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)
44 while(XCheckMaskEvent(dpy, even_mask, &ev));
48 buttonpress(XEvent *e)
50 XButtonPressedEvent *ev = &e->xbutton;
53 if((c = getclient(ev->window))) {
72 configurerequest(XEvent *e)
74 XConfigureRequestEvent *ev = &e->xconfigurerequest;
78 ev->value_mask &= ~CWSibling;
79 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)
89 if(ev->value_mask & CWBorderWidth)
90 c->border = ev->border_width;
98 wc.height = ev->height;
101 wc.stack_mode = Above;
102 ev->value_mask &= ~CWStackMode;
103 ev->value_mask |= CWBorderWidth;
104 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
109 destroynotify(XEvent *e)
112 XDestroyWindowEvent *ev = &e->xdestroywindow;
114 if((c = getclient(ev->window)))
119 enternotify(XEvent *e)
121 XCrossingEvent *ev = &e->xcrossing;
124 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
127 if((c = getclient(ev->window)))
129 else if(ev->window == root)
134 leavenotify(XEvent *e)
136 XCrossingEvent *ev = &e->xcrossing;
138 if((ev->window == root) && !ev->same_screen)
145 XExposeEvent *ev = &e->xexpose;
149 if((c = gettitle(ev->window)))
155 keymapnotify(XEvent *e)
161 maprequest(XEvent *e)
163 XMapRequestEvent *ev = &e->xmaprequest;
164 static XWindowAttributes wa;
166 if(!XGetWindowAttributes(dpy, ev->window, &wa))
169 if(wa.override_redirect) {
170 XSelectInput(dpy, ev->window,
171 (StructureNotifyMask | PropertyChangeMask));
175 if(!getclient(ev->window))
176 manage(ev->window, &wa);
180 propertynotify(XEvent *e)
182 XPropertyEvent *ev = &e->xproperty;
186 if(ev->state == PropertyDelete)
189 if((c = getclient(ev->window))) {
190 if(ev->atom == wm_atom[WMProtocols]) {
191 c->proto = win_proto(c->win);
196 case XA_WM_TRANSIENT_FOR:
197 XGetTransientForHint(dpy, c->win, &trans);
198 if(!c->floating && (c->floating = (trans != 0)))
201 case XA_WM_NORMAL_HINTS:
205 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
213 unmapnotify(XEvent *e)
216 XUnmapEvent *ev = &e->xunmap;
218 if((c = getclient(ev->window)))