Mercurial > dwm-meillo
annotate event.c @ 74:5370ef170cc9
sanitized names
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 22:54:09 +0200 |
parents | c2ddb9dbbd10 |
children | f08271b7cb20 |
rev | line source |
---|---|
5 | 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> | |
63
f14858218641
searching for a better way to discard enter notifies
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
7 #include <stdio.h> |
5 | 8 #include <stdlib.h> |
9 #include <string.h> | |
73 | 10 #include <unistd.h> |
5 | 11 #include <X11/keysym.h> |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
12 #include <X11/Xatom.h> |
5 | 13 |
43 | 14 #include "dwm.h" |
5 | 15 |
73 | 16 #define ButtonMask (ButtonPressMask | ButtonReleaseMask) |
17 #define MouseMask (ButtonMask | PointerMotionMask) | |
18 | |
5 | 19 /* local functions */ |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
20 static void buttonpress(XEvent *e); |
5 | 21 static void configurerequest(XEvent *e); |
22 static void destroynotify(XEvent *e); | |
23 static void enternotify(XEvent *e); | |
24 static void leavenotify(XEvent *e); | |
25 static void expose(XEvent *e); | |
26 static void maprequest(XEvent *e); | |
27 static void propertynotify(XEvent *e); | |
28 static void unmapnotify(XEvent *e); | |
29 | |
30 void (*handler[LASTEvent]) (XEvent *) = { | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
31 [ButtonPress] = buttonpress, |
5 | 32 [ConfigureRequest] = configurerequest, |
33 [DestroyNotify] = destroynotify, | |
34 [EnterNotify] = enternotify, | |
35 [LeaveNotify] = leavenotify, | |
36 [Expose] = expose, | |
37 [KeyPress] = keypress, | |
38 [MapRequest] = maprequest, | |
39 [PropertyNotify] = propertynotify, | |
40 [UnmapNotify] = unmapnotify | |
41 }; | |
42 | |
43 static void | |
73 | 44 mresize(Client *c) |
45 { | |
46 XEvent ev; | |
47 int ocx, ocy; | |
48 | |
49 ocx = c->x; | |
50 ocy = c->y; | |
51 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | |
52 None, cursor[CurResize], CurrentTime) != GrabSuccess) | |
53 return; | |
54 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); | |
55 for(;;) { | |
56 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | |
57 switch(ev.type) { | |
58 default: break; | |
59 case Expose: | |
60 handler[Expose](&ev); | |
61 break; | |
62 case MotionNotify: | |
63 XFlush(dpy); | |
64 c->w = abs(ocx - ev.xmotion.x); | |
65 c->h = abs(ocy - ev.xmotion.y); | |
66 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; | |
67 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; | |
68 resize(c, True); | |
69 break; | |
70 case ButtonRelease: | |
71 XUngrabPointer(dpy, CurrentTime); | |
72 return; | |
73 } | |
74 } | |
75 } | |
76 | |
77 static void | |
78 mmove(Client *c) | |
79 { | |
80 XEvent ev; | |
81 int x1, y1, ocx, ocy, di; | |
82 unsigned int dui; | |
83 Window dummy; | |
84 | |
85 ocx = c->x; | |
86 ocy = c->y; | |
87 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, | |
88 None, cursor[CurMove], CurrentTime) != GrabSuccess) | |
89 return; | |
90 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | |
91 for(;;) { | |
92 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); | |
93 switch (ev.type) { | |
94 default: break; | |
95 case Expose: | |
96 handler[Expose](&ev); | |
97 break; | |
98 case MotionNotify: | |
99 XFlush(dpy); | |
100 c->x = ocx + (ev.xmotion.x - x1); | |
101 c->y = ocy + (ev.xmotion.y - y1); | |
102 resize(c, False); | |
103 break; | |
104 case ButtonRelease: | |
105 XUngrabPointer(dpy, CurrentTime); | |
106 return; | |
107 } | |
108 } | |
109 } | |
110 | |
111 static void | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
112 buttonpress(XEvent *e) |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
113 { |
73 | 114 int x; |
115 Arg a; | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
116 XButtonPressedEvent *ev = &e->xbutton; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
117 Client *c; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
118 |
73 | 119 if(barwin == ev->window) { |
120 x = (arrange == floating) ? textw("~") : 0; | |
121 for(a.i = 0; a.i < TLast; a.i++) { | |
122 x += textw(tags[a.i]); | |
123 if(ev->x < x) { | |
124 view(&a); | |
125 break; | |
126 } | |
127 } | |
128 } | |
58
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
55
diff
changeset
|
129 else if((c = getclient(ev->window))) { |
73 | 130 if(arrange == tiling && !c->floating) |
131 return; | |
74 | 132 higher(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
133 switch(ev->button) { |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
134 default: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
135 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
136 case Button1: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
137 mmove(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
138 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
139 case Button2: |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
25
diff
changeset
|
140 lower(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
141 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
142 case Button3: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
143 mresize(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
144 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
145 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
146 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
147 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
148 |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
149 static void |
5 | 150 configurerequest(XEvent *e) |
151 { | |
152 XConfigureRequestEvent *ev = &e->xconfigurerequest; | |
153 XWindowChanges wc; | |
154 Client *c; | |
155 | |
156 ev->value_mask &= ~CWSibling; | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
157 if((c = getclient(ev->window))) { |
29 | 158 gravitate(c, True); |
5 | 159 if(ev->value_mask & CWX) |
20 | 160 c->x = ev->x; |
5 | 161 if(ev->value_mask & CWY) |
20 | 162 c->y = ev->y; |
5 | 163 if(ev->value_mask & CWWidth) |
20 | 164 c->w = ev->width; |
5 | 165 if(ev->value_mask & CWHeight) |
20 | 166 c->h = ev->height; |
29 | 167 if(ev->value_mask & CWBorderWidth) |
55 | 168 c->border = 1; |
29 | 169 gravitate(c, False); |
53 | 170 resize(c, True); |
5 | 171 } |
172 | |
173 wc.x = ev->x; | |
174 wc.y = ev->y; | |
175 wc.width = ev->width; | |
176 wc.height = ev->height; | |
25 | 177 wc.border_width = 1; |
5 | 178 wc.sibling = None; |
179 wc.stack_mode = Above; | |
180 ev->value_mask &= ~CWStackMode; | |
181 ev->value_mask |= CWBorderWidth; | |
182 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); | |
183 XFlush(dpy); | |
184 } | |
185 | |
186 static void | |
187 destroynotify(XEvent *e) | |
188 { | |
189 Client *c; | |
190 XDestroyWindowEvent *ev = &e->xdestroywindow; | |
191 | |
11 | 192 if((c = getclient(ev->window))) |
193 unmanage(c); | |
5 | 194 } |
195 | |
196 static void | |
197 enternotify(XEvent *e) | |
198 { | |
199 XCrossingEvent *ev = &e->xcrossing; | |
200 Client *c; | |
201 | |
202 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) | |
203 return; | |
204 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
205 if((c = getclient(ev->window))) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
206 focus(c); |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
25
diff
changeset
|
207 else if(ev->window == root) |
31 | 208 issel = True; |
5 | 209 } |
210 | |
211 static void | |
212 leavenotify(XEvent *e) | |
213 { | |
214 XCrossingEvent *ev = &e->xcrossing; | |
215 | |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
25
diff
changeset
|
216 if((ev->window == root) && !ev->same_screen) |
31 | 217 issel = True; |
5 | 218 } |
219 | |
220 static void | |
221 expose(XEvent *e) | |
222 { | |
223 XExposeEvent *ev = &e->xexpose; | |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
224 Client *c; |
5 | 225 |
226 if(ev->count == 0) { | |
70 | 227 if(barwin == ev->window) |
74 | 228 drawstatus(); |
70 | 229 else if((c = gettitle(ev->window))) |
74 | 230 drawtitle(c); |
5 | 231 } |
232 } | |
233 | |
234 static void | |
235 maprequest(XEvent *e) | |
236 { | |
237 XMapRequestEvent *ev = &e->xmaprequest; | |
238 static XWindowAttributes wa; | |
239 | |
240 if(!XGetWindowAttributes(dpy, ev->window, &wa)) | |
241 return; | |
242 | |
243 if(wa.override_redirect) { | |
244 XSelectInput(dpy, ev->window, | |
245 (StructureNotifyMask | PropertyChangeMask)); | |
246 return; | |
247 } | |
248 | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
249 if(!getclient(ev->window)) |
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
250 manage(ev->window, &wa); |
5 | 251 } |
252 | |
253 static void | |
254 propertynotify(XEvent *e) | |
255 { | |
256 XPropertyEvent *ev = &e->xproperty; | |
53 | 257 Window trans; |
5 | 258 Client *c; |
259 | |
260 if(ev->state == PropertyDelete) | |
261 return; /* ignore */ | |
262 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
263 if((c = getclient(ev->window))) { |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
264 if(ev->atom == wm_atom[WMProtocols]) { |
74 | 265 c->proto = proto(c->win); |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
266 return; |
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
267 } |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
268 switch (ev->atom) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
269 default: break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
270 case XA_WM_TRANSIENT_FOR: |
53 | 271 XGetTransientForHint(dpy, c->win, &trans); |
272 if(!c->floating && (c->floating = (trans != 0))) | |
273 arrange(NULL); | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
274 break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
275 case XA_WM_NORMAL_HINTS: |
74 | 276 setsize(c); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
277 break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
278 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
279 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { |
74 | 280 settitle(c); |
281 drawtitle(c); | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
282 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
283 } |
5 | 284 } |
285 | |
286 static void | |
287 unmapnotify(XEvent *e) | |
288 { | |
289 Client *c; | |
290 XUnmapEvent *ev = &e->xunmap; | |
291 | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
292 if((c = getclient(ev->window))) |
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
293 unmanage(c); |
5 | 294 } |