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