Mercurial > dwm-meillo
annotate event.c @ 27:f96fb3fd8203
added grid mode on Mod1Mask g
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Wed, 12 Jul 2006 16:00:51 +0200 |
parents | e8f627998d6f |
children | 8ad86d0a6a53 |
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> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <X11/keysym.h> | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
10 #include <X11/Xatom.h> |
5 | 11 |
12 #include "wm.h" | |
13 | |
14 /* local functions */ | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
15 static void buttonpress(XEvent *e); |
5 | 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); | |
25 | |
26 void (*handler[LASTEvent]) (XEvent *) = { | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
27 [ButtonPress] = buttonpress, |
5 | 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 }; | |
39 | |
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
|
40 void |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
41 discard_events(long even_mask) |
5 | 42 { |
43 XEvent ev; | |
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
|
44 while(XCheckMaskEvent(dpy, even_mask, &ev)); |
5 | 45 } |
46 | |
47 static void | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
48 buttonpress(XEvent *e) |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
49 { |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
50 XButtonPressedEvent *ev = &e->xbutton; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
51 Client *c; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
52 |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
53 if((c = getclient(ev->window))) { |
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
|
54 raise(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
55 switch(ev->button) { |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
56 default: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
57 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
58 case Button1: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
59 mmove(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
60 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
61 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
|
62 lower(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
63 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
64 case Button3: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
65 mresize(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
66 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
67 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
68 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
69 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
70 |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
71 static void |
5 | 72 configurerequest(XEvent *e) |
73 { | |
74 XConfigureRequestEvent *ev = &e->xconfigurerequest; | |
75 XWindowChanges wc; | |
76 Client *c; | |
77 | |
78 ev->value_mask &= ~CWSibling; | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
79 if((c = getclient(ev->window))) { |
5 | 80 if(ev->value_mask & CWX) |
20 | 81 c->x = ev->x; |
5 | 82 if(ev->value_mask & CWY) |
20 | 83 c->y = ev->y; |
5 | 84 if(ev->value_mask & CWWidth) |
20 | 85 c->w = ev->width; |
5 | 86 if(ev->value_mask & CWHeight) |
20 | 87 c->h = ev->height; |
5 | 88 } |
89 | |
90 wc.x = ev->x; | |
91 wc.y = ev->y; | |
92 wc.width = ev->width; | |
93 wc.height = ev->height; | |
25 | 94 wc.border_width = 1; |
5 | 95 wc.sibling = None; |
96 wc.stack_mode = Above; | |
97 ev->value_mask &= ~CWStackMode; | |
98 ev->value_mask |= CWBorderWidth; | |
99 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); | |
100 XFlush(dpy); | |
101 } | |
102 | |
103 static void | |
104 destroynotify(XEvent *e) | |
105 { | |
106 Client *c; | |
107 XDestroyWindowEvent *ev = &e->xdestroywindow; | |
108 | |
11 | 109 if((c = getclient(ev->window))) |
110 unmanage(c); | |
5 | 111 } |
112 | |
113 static void | |
114 enternotify(XEvent *e) | |
115 { | |
116 XCrossingEvent *ev = &e->xcrossing; | |
117 Client *c; | |
118 | |
119 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) | |
120 return; | |
121 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
122 if((c = getclient(ev->window))) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
123 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
|
124 else if(ev->window == root) |
5 | 125 sel_screen = True; |
126 } | |
127 | |
128 static void | |
129 leavenotify(XEvent *e) | |
130 { | |
131 XCrossingEvent *ev = &e->xcrossing; | |
132 | |
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
|
133 if((ev->window == root) && !ev->same_screen) |
5 | 134 sel_screen = True; |
135 } | |
136 | |
137 static void | |
138 expose(XEvent *e) | |
139 { | |
140 XExposeEvent *ev = &e->xexpose; | |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
141 Client *c; |
5 | 142 |
143 if(ev->count == 0) { | |
23 | 144 if((c = gettitle(ev->window))) |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
145 draw_client(c); |
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
146 else if(ev->window == barwin) |
5 | 147 draw_bar(); |
148 } | |
149 } | |
150 | |
151 static void | |
152 keymapnotify(XEvent *e) | |
153 { | |
154 update_keys(); | |
155 } | |
156 | |
157 static void | |
158 maprequest(XEvent *e) | |
159 { | |
160 XMapRequestEvent *ev = &e->xmaprequest; | |
161 static XWindowAttributes wa; | |
162 | |
163 if(!XGetWindowAttributes(dpy, ev->window, &wa)) | |
164 return; | |
165 | |
166 if(wa.override_redirect) { | |
167 XSelectInput(dpy, ev->window, | |
168 (StructureNotifyMask | PropertyChangeMask)); | |
169 return; | |
170 } | |
171 | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
172 if(!getclient(ev->window)) |
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
173 manage(ev->window, &wa); |
5 | 174 } |
175 | |
176 static void | |
177 propertynotify(XEvent *e) | |
178 { | |
179 XPropertyEvent *ev = &e->xproperty; | |
180 Client *c; | |
181 | |
182 if(ev->state == PropertyDelete) | |
183 return; /* ignore */ | |
184 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
185 if(ev->atom == wm_atom[WMProtocols]) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
186 c->proto = win_proto(c->win); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
187 return; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
188 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
189 if((c = getclient(ev->window))) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
190 switch (ev->atom) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
191 default: break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
192 case XA_WM_TRANSIENT_FOR: |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
193 XGetTransientForHint(dpy, c->win, &c->trans); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
194 break; |
20 | 195 update_size(c); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
196 case XA_WM_NORMAL_HINTS: |
20 | 197 update_size(c); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
198 break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
199 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
200 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
201 update_name(c); |
22
bd3a44353916
fixed several other stuff, coming closer to something useful
Anselm R. Garbe <garbeam@wmii.de>
parents:
21
diff
changeset
|
202 if(c == stack) |
bd3a44353916
fixed several other stuff, coming closer to something useful
Anselm R. Garbe <garbeam@wmii.de>
parents:
21
diff
changeset
|
203 draw_bar(); |
bd3a44353916
fixed several other stuff, coming closer to something useful
Anselm R. Garbe <garbeam@wmii.de>
parents:
21
diff
changeset
|
204 else |
bd3a44353916
fixed several other stuff, coming closer to something useful
Anselm R. Garbe <garbeam@wmii.de>
parents:
21
diff
changeset
|
205 draw_client(c); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
206 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
207 } |
5 | 208 } |
209 | |
210 static void | |
211 unmapnotify(XEvent *e) | |
212 { | |
213 Client *c; | |
214 XUnmapEvent *ev = &e->xunmap; | |
215 | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
216 if((c = getclient(ev->window))) |
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
217 unmanage(c); |
5 | 218 } |