2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
9 #include <X11/keysym.h>
10 #include <X11/Xatom.h>
15 static void buttonpress(XEvent *e);
16 static void configurerequest(XEvent *e);
17 static void destroynotify(XEvent *e);
18 static void enternotify(XEvent *e);
19 static void leavenotify(XEvent *e);
20 static void expose(XEvent *e);
21 static void keymapnotify(XEvent *e);
22 static void maprequest(XEvent *e);
23 static void propertynotify(XEvent *e);
24 static void unmapnotify(XEvent *e);
26 void (*handler[LASTEvent]) (XEvent *) = {
27 [ButtonPress] = buttonpress,
28 [ConfigureRequest] = configurerequest,
29 [DestroyNotify] = destroynotify,
30 [EnterNotify] = enternotify,
31 [LeaveNotify] = leavenotify,
33 [KeyPress] = keypress,
34 [KeymapNotify] = keymapnotify,
35 [MapRequest] = maprequest,
36 [PropertyNotify] = propertynotify,
37 [UnmapNotify] = unmapnotify
41 discard_events(long even_mask)
45 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
50 buttonpress(XEvent *e)
52 XButtonPressedEvent *ev = &e->xbutton;
55 if((c = getclient(ev->window))) {
63 XLowerWindow(dpy, c->win);
73 configurerequest(XEvent *e)
75 XConfigureRequestEvent *ev = &e->xconfigurerequest;
79 ev->value_mask &= ~CWSibling;
80 if((c = getclient(ev->window))) {
81 if(ev->value_mask & CWX)
83 if(ev->value_mask & CWY)
85 if(ev->value_mask & CWWidth)
87 if(ev->value_mask & CWHeight)
94 wc.height = ev->height;
97 wc.stack_mode = Above;
98 ev->value_mask &= ~CWStackMode;
99 ev->value_mask |= CWBorderWidth;
100 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
105 destroynotify(XEvent *e)
108 XDestroyWindowEvent *ev = &e->xdestroywindow;
110 if((c = getclient(ev->window)))
115 enternotify(XEvent *e)
117 XCrossingEvent *ev = &e->xcrossing;
120 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
123 if((c = getclient(ev->window)))
125 else if(ev->window == root) {
132 leavenotify(XEvent *e)
134 XCrossingEvent *ev = &e->xcrossing;
136 if((ev->window == root) && !ev->same_screen) {
145 XExposeEvent *ev = &e->xexpose;
149 if((c = getclient(ev->window)))
151 else if(ev->window == barwin)
157 keymapnotify(XEvent *e)
163 maprequest(XEvent *e)
165 XMapRequestEvent *ev = &e->xmaprequest;
166 static XWindowAttributes wa;
168 if(!XGetWindowAttributes(dpy, ev->window, &wa))
171 if(wa.override_redirect) {
172 XSelectInput(dpy, ev->window,
173 (StructureNotifyMask | PropertyChangeMask));
177 if(!getclient(ev->window))
178 manage(ev->window, &wa);
182 propertynotify(XEvent *e)
184 XPropertyEvent *ev = &e->xproperty;
187 if(ev->state == PropertyDelete)
190 if(ev->atom == wm_atom[WMProtocols]) {
191 c->proto = win_proto(c->win);
194 if((c = getclient(ev->window))) {
197 case XA_WM_TRANSIENT_FOR:
198 XGetTransientForHint(dpy, c->win, &c->trans);
201 case XA_WM_NORMAL_HINTS:
205 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
216 unmapnotify(XEvent *e)
219 XUnmapEvent *ev = &e->xunmap;
221 if((c = getclient(ev->window)))