event.c (view raw)
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <fcntl.h>
7#include <stdlib.h>
8#include <string.h>
9#include <X11/keysym.h>
10
11#include "wm.h"
12
13/* local functions */
14static void configurerequest(XEvent *e);
15static void destroynotify(XEvent *e);
16static void enternotify(XEvent *e);
17static void leavenotify(XEvent *e);
18static void expose(XEvent *e);
19static void keymapnotify(XEvent *e);
20static void maprequest(XEvent *e);
21static void propertynotify(XEvent *e);
22static void unmapnotify(XEvent *e);
23
24void (*handler[LASTEvent]) (XEvent *) = {
25 [ConfigureRequest] = configurerequest,
26 [DestroyNotify] = destroynotify,
27 [EnterNotify] = enternotify,
28 [LeaveNotify] = leavenotify,
29 [Expose] = expose,
30 [KeyPress] = keypress,
31 [KeymapNotify] = keymapnotify,
32 [MapRequest] = maprequest,
33 [PropertyNotify] = propertynotify,
34 [UnmapNotify] = unmapnotify
35};
36
37unsigned int
38flush_masked_events(long even_mask)
39{
40 XEvent ev;
41 unsigned int n = 0;
42 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
43 return n;
44}
45
46static void
47configurerequest(XEvent *e)
48{
49 XConfigureRequestEvent *ev = &e->xconfigurerequest;
50 XWindowChanges wc;
51 Client *c;
52
53 c = getclient(ev->window);
54 ev->value_mask &= ~CWSibling;
55 if(c) {
56 if(ev->value_mask & CWX)
57 c->r[RFloat].x = ev->x;
58 if(ev->value_mask & CWY)
59 c->r[RFloat].y = ev->y;
60 if(ev->value_mask & CWWidth)
61 c->r[RFloat].width = ev->width;
62 if(ev->value_mask & CWHeight)
63 c->r[RFloat].height = ev->height;
64 if(ev->value_mask & CWBorderWidth)
65 c->border = ev->border_width;
66 }
67
68 wc.x = ev->x;
69 wc.y = ev->y;
70 wc.width = ev->width;
71 wc.height = ev->height;
72 wc.border_width = 0;
73 wc.sibling = None;
74 wc.stack_mode = Above;
75 ev->value_mask &= ~CWStackMode;
76 ev->value_mask |= CWBorderWidth;
77 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
78 XFlush(dpy);
79}
80
81static void
82destroynotify(XEvent *e)
83{
84#if 0
85 Client *c;
86 XDestroyWindowEvent *ev = &e->xdestroywindow;
87
88 if((c = client_of_win(ev->window)))
89 destroy_client(c);
90#endif
91}
92
93static void
94enternotify(XEvent *e)
95{
96#if 0
97 XCrossingEvent *ev = &e->xcrossing;
98 Client *c;
99
100 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
101 return;
102
103 if((c = client_of_win(ev->window))) {
104 Frame *f = c->sel;
105 Area *a = f->area;
106 if(a->mode == Colmax)
107 c = a->sel->client;
108 focus(c, False);
109 }
110 else if(ev->window == root) {
111 sel_screen = True;
112 draw_frames();
113 }
114#endif
115}
116
117static void
118leavenotify(XEvent *e)
119{
120 XCrossingEvent *ev = &e->xcrossing;
121
122 if((ev->window == root) && !ev->same_screen) {
123 sel_screen = True;
124 /*draw_frames();*/
125 }
126}
127
128static void
129expose(XEvent *e)
130{
131 XExposeEvent *ev = &e->xexpose;
132
133 if(ev->count == 0) {
134 if(ev->window == barwin)
135 draw_bar();
136 }
137}
138
139static void
140keymapnotify(XEvent *e)
141{
142#if 0
143 update_keys();
144#endif
145}
146
147static void
148maprequest(XEvent *e)
149{
150 XMapRequestEvent *ev = &e->xmaprequest;
151 static XWindowAttributes wa;
152
153 if(!XGetWindowAttributes(dpy, ev->window, &wa))
154 return;
155
156 if(wa.override_redirect) {
157 XSelectInput(dpy, ev->window,
158 (StructureNotifyMask | PropertyChangeMask));
159 return;
160 }
161
162 if(!getclient(ev->window))
163 manage(ev->window, &wa);
164}
165
166static void
167propertynotify(XEvent *e)
168{
169#if 0
170 XPropertyEvent *ev = &e->xproperty;
171 Client *c;
172
173 if(ev->state == PropertyDelete)
174 return; /* ignore */
175
176 if((c = client_of_win(ev->window)))
177 prop_client(c, ev);
178#endif
179}
180
181static void
182unmapnotify(XEvent *e)
183{
184 Client *c;
185 XUnmapEvent *ev = &e->xunmap;
186
187 if((c = getclient(ev->window)))
188 unmanage(c);
189}