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)
82 c->r[RFloat].x = ev->x;
83 if(ev->value_mask & CWY)
84 c->r[RFloat].y = ev->y;
85 if(ev->value_mask & CWWidth)
86 c->r[RFloat].width = ev->width;
87 if(ev->value_mask & CWHeight)
88 c->r[RFloat].height = ev->height;
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;
148 if(ev->window == barwin)
154 keymapnotify(XEvent *e)
160 maprequest(XEvent *e)
162 XMapRequestEvent *ev = &e->xmaprequest;
163 static XWindowAttributes wa;
165 if(!XGetWindowAttributes(dpy, ev->window, &wa))
168 if(wa.override_redirect) {
169 XSelectInput(dpy, ev->window,
170 (StructureNotifyMask | PropertyChangeMask));
174 if(!getclient(ev->window))
175 manage(ev->window, &wa);
179 propertynotify(XEvent *e)
181 XPropertyEvent *ev = &e->xproperty;
185 if(ev->state == PropertyDelete)
188 if(ev->atom == wm_atom[WMProtocols]) {
189 c->proto = win_proto(c->win);
192 if((c = getclient(ev->window))) {
195 case XA_WM_TRANSIENT_FOR:
196 XGetTransientForHint(dpy, c->win, &c->trans);
198 case XA_WM_NORMAL_HINTS:
199 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
201 c->size.flags = PSize;
202 if(c->size.flags & PMinSize && c->size.flags & PMaxSize
203 && c->size.min_width == c->size.max_width
204 && c->size.min_height == c->size.max_height)
207 c->fixedsize = False;
210 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
217 unmapnotify(XEvent *e)
220 XUnmapEvent *ev = &e->xunmap;
222 if((c = getclient(ev->window)))