aewl

view event.c @ 45:7943c72e34eb

added pointer warps on kb-driven/manage-driven focus
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 12:00:20 +0200
parents 082c75b937b5
children 529901e6a227
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <X11/keysym.h>
10 #include <X11/Xatom.h>
12 #include "dwm.h"
14 /* local functions */
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,
32 [Expose] = expose,
33 [KeyPress] = keypress,
34 [KeymapNotify] = keymapnotify,
35 [MapRequest] = maprequest,
36 [PropertyNotify] = propertynotify,
37 [UnmapNotify] = unmapnotify
38 };
40 void
41 discard_events(long even_mask)
42 {
43 XEvent ev;
44 while(XCheckMaskEvent(dpy, even_mask, &ev));
45 }
47 static void
48 buttonpress(XEvent *e)
49 {
50 XButtonPressedEvent *ev = &e->xbutton;
51 Client *c;
53 if((c = getclient(ev->window))) {
54 craise(c);
55 switch(ev->button) {
56 default:
57 break;
58 case Button1:
59 mmove(c);
60 break;
61 case Button2:
62 lower(c);
63 break;
64 case Button3:
65 mresize(c);
66 break;
67 }
68 }
69 }
71 static void
72 configurerequest(XEvent *e)
73 {
74 XConfigureRequestEvent *ev = &e->xconfigurerequest;
75 XWindowChanges wc;
76 Client *c;
78 ev->value_mask &= ~CWSibling;
79 if((c = getclient(ev->window))) {
80 gravitate(c, True);
81 if(ev->value_mask & CWX)
82 c->x = ev->x;
83 if(ev->value_mask & CWY)
84 c->y = ev->y;
85 if(ev->value_mask & CWWidth)
86 c->w = ev->width;
87 if(ev->value_mask & CWHeight)
88 c->h = ev->height;
89 if(ev->value_mask & CWBorderWidth)
90 c->border = ev->border_width;
91 gravitate(c, False);
92 }
94 wc.x = ev->x;
95 wc.y = ev->y;
96 wc.width = ev->width;
97 wc.height = ev->height;
98 wc.border_width = 1;
99 wc.sibling = None;
100 wc.stack_mode = Above;
101 ev->value_mask &= ~CWStackMode;
102 ev->value_mask |= CWBorderWidth;
103 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
104 XFlush(dpy);
105 }
107 static void
108 destroynotify(XEvent *e)
109 {
110 Client *c;
111 XDestroyWindowEvent *ev = &e->xdestroywindow;
113 if((c = getclient(ev->window)))
114 unmanage(c);
115 }
117 static void
118 enternotify(XEvent *e)
119 {
120 XCrossingEvent *ev = &e->xcrossing;
121 Client *c;
123 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
124 return;
126 if((c = getclient(ev->window)))
127 focus(c);
128 else if(ev->window == root)
129 issel = True;
130 }
132 static void
133 leavenotify(XEvent *e)
134 {
135 XCrossingEvent *ev = &e->xcrossing;
137 if((ev->window == root) && !ev->same_screen)
138 issel = True;
139 }
141 static void
142 expose(XEvent *e)
143 {
144 XExposeEvent *ev = &e->xexpose;
145 Client *c;
147 if(ev->count == 0) {
148 if((c = gettitle(ev->window)))
149 draw_client(c);
150 }
151 }
153 static void
154 keymapnotify(XEvent *e)
155 {
156 update_keys();
157 }
159 static void
160 maprequest(XEvent *e)
161 {
162 XMapRequestEvent *ev = &e->xmaprequest;
163 static XWindowAttributes wa;
165 if(!XGetWindowAttributes(dpy, ev->window, &wa))
166 return;
168 if(wa.override_redirect) {
169 XSelectInput(dpy, ev->window,
170 (StructureNotifyMask | PropertyChangeMask));
171 return;
172 }
174 if(!getclient(ev->window))
175 manage(ev->window, &wa);
176 }
178 static void
179 propertynotify(XEvent *e)
180 {
181 XPropertyEvent *ev = &e->xproperty;
182 Client *c;
184 if(ev->state == PropertyDelete)
185 return; /* ignore */
187 if((c = getclient(ev->window))) {
188 if(ev->atom == wm_atom[WMProtocols]) {
189 c->proto = win_proto(c->win);
190 return;
191 }
192 switch (ev->atom) {
193 default: break;
194 case XA_WM_TRANSIENT_FOR:
195 XGetTransientForHint(dpy, c->win, &c->trans);
196 break;
197 update_size(c);
198 case XA_WM_NORMAL_HINTS:
199 update_size(c);
200 break;
201 }
202 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
203 update_name(c);
204 draw_client(c);
205 }
206 }
207 }
209 static void
210 unmapnotify(XEvent *e)
211 {
212 Client *c;
213 XUnmapEvent *ev = &e->xunmap;
215 if((c = getclient(ev->window)))
216 unmanage(c);
217 }