Mercurial > dwm-meillo
annotate event.c @ 65:4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 17:30:37 +0200 |
parents | f14858218641 |
children | e5fff8249705 |
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> | |
10 #include <X11/keysym.h> | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
11 #include <X11/Xatom.h> |
5 | 12 |
43 | 13 #include "dwm.h" |
5 | 14 |
15 /* local functions */ | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
16 static void buttonpress(XEvent *e); |
5 | 17 static void configurerequest(XEvent *e); |
18 static void destroynotify(XEvent *e); | |
19 static void enternotify(XEvent *e); | |
20 static void leavenotify(XEvent *e); | |
21 static void expose(XEvent *e); | |
22 static void keymapnotify(XEvent *e); | |
23 static void maprequest(XEvent *e); | |
24 static void propertynotify(XEvent *e); | |
25 static void unmapnotify(XEvent *e); | |
26 | |
27 void (*handler[LASTEvent]) (XEvent *) = { | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
28 [ButtonPress] = buttonpress, |
5 | 29 [ConfigureRequest] = configurerequest, |
30 [DestroyNotify] = destroynotify, | |
31 [EnterNotify] = enternotify, | |
32 [LeaveNotify] = leavenotify, | |
33 [Expose] = expose, | |
34 [KeyPress] = keypress, | |
35 [KeymapNotify] = keymapnotify, | |
36 [MapRequest] = maprequest, | |
37 [PropertyNotify] = propertynotify, | |
38 [UnmapNotify] = unmapnotify | |
39 }; | |
40 | |
41 static void | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
42 buttonpress(XEvent *e) |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
43 { |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
44 XButtonPressedEvent *ev = &e->xbutton; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
45 Client *c; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
46 |
58
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
55
diff
changeset
|
47 if(barwin == ev->window) |
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
55
diff
changeset
|
48 barclick(ev); |
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
55
diff
changeset
|
49 else if((c = getclient(ev->window))) { |
32 | 50 craise(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
51 switch(ev->button) { |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
52 default: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
53 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
54 case Button1: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
55 mmove(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
56 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
57 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
|
58 lower(c); |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
59 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
60 case Button3: |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
61 mresize(c); |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
62 break; |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
63 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
64 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
65 } |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
66 |
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
67 static void |
5 | 68 configurerequest(XEvent *e) |
69 { | |
70 XConfigureRequestEvent *ev = &e->xconfigurerequest; | |
71 XWindowChanges wc; | |
72 Client *c; | |
73 | |
74 ev->value_mask &= ~CWSibling; | |
18
1efa34c6e1b6
added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
75 if((c = getclient(ev->window))) { |
29 | 76 gravitate(c, True); |
5 | 77 if(ev->value_mask & CWX) |
20 | 78 c->x = ev->x; |
5 | 79 if(ev->value_mask & CWY) |
20 | 80 c->y = ev->y; |
5 | 81 if(ev->value_mask & CWWidth) |
20 | 82 c->w = ev->width; |
5 | 83 if(ev->value_mask & CWHeight) |
20 | 84 c->h = ev->height; |
29 | 85 if(ev->value_mask & CWBorderWidth) |
55 | 86 c->border = 1; |
29 | 87 gravitate(c, False); |
53 | 88 resize(c, True); |
5 | 89 } |
90 | |
91 wc.x = ev->x; | |
92 wc.y = ev->y; | |
93 wc.width = ev->width; | |
94 wc.height = ev->height; | |
25 | 95 wc.border_width = 1; |
5 | 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); |
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
|
125 else if(ev->window == root) |
31 | 126 issel = True; |
5 | 127 } |
128 | |
129 static void | |
130 leavenotify(XEvent *e) | |
131 { | |
132 XCrossingEvent *ev = &e->xcrossing; | |
133 | |
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
|
134 if((ev->window == root) && !ev->same_screen) |
31 | 135 issel = True; |
5 | 136 } |
137 | |
138 static void | |
139 expose(XEvent *e) | |
140 { | |
141 XExposeEvent *ev = &e->xexpose; | |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
142 Client *c; |
5 | 143 |
144 if(ev->count == 0) { | |
23 | 145 if((c = gettitle(ev->window))) |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
146 draw_client(c); |
5 | 147 } |
148 } | |
149 | |
150 static void | |
151 keymapnotify(XEvent *e) | |
152 { | |
153 update_keys(); | |
154 } | |
155 | |
156 static void | |
157 maprequest(XEvent *e) | |
158 { | |
159 XMapRequestEvent *ev = &e->xmaprequest; | |
160 static XWindowAttributes wa; | |
161 | |
162 if(!XGetWindowAttributes(dpy, ev->window, &wa)) | |
163 return; | |
164 | |
165 if(wa.override_redirect) { | |
166 XSelectInput(dpy, ev->window, | |
167 (StructureNotifyMask | PropertyChangeMask)); | |
168 return; | |
169 } | |
170 | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
171 if(!getclient(ev->window)) |
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
172 manage(ev->window, &wa); |
5 | 173 } |
174 | |
175 static void | |
176 propertynotify(XEvent *e) | |
177 { | |
178 XPropertyEvent *ev = &e->xproperty; | |
53 | 179 Window trans; |
5 | 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((c = getclient(ev->window))) { |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
186 if(ev->atom == wm_atom[WMProtocols]) { |
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
187 c->proto = win_proto(c->win); |
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
188 return; |
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
29
diff
changeset
|
189 } |
13
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: |
53 | 193 XGetTransientForHint(dpy, c->win, &trans); |
194 if(!c->floating && (c->floating = (trans != 0))) | |
195 arrange(NULL); | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
196 break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
197 case XA_WM_NORMAL_HINTS: |
20 | 198 update_size(c); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
199 break; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
200 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
11
diff
changeset
|
201 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
|
202 update_name(c); |
32 | 203 draw_client(c); |
13
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 } |