rev |
line source |
garbeam@5
|
1 /*
|
garbeam@5
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@5
|
3 * See LICENSE file for license details.
|
garbeam@5
|
4 */
|
garbeam@5
|
5
|
garbeam@5
|
6 #include <fcntl.h>
|
garbeam@5
|
7 #include <stdlib.h>
|
garbeam@5
|
8 #include <string.h>
|
garbeam@5
|
9 #include <X11/keysym.h>
|
garbeam@5
|
10
|
garbeam@5
|
11 #include "wm.h"
|
garbeam@5
|
12
|
garbeam@5
|
13 /* local functions */
|
garbeam@5
|
14 static void configurerequest(XEvent *e);
|
garbeam@5
|
15 static void destroynotify(XEvent *e);
|
garbeam@5
|
16 static void enternotify(XEvent *e);
|
garbeam@5
|
17 static void leavenotify(XEvent *e);
|
garbeam@5
|
18 static void expose(XEvent *e);
|
garbeam@5
|
19 static void keypress(XEvent *e);
|
garbeam@5
|
20 static void keymapnotify(XEvent *e);
|
garbeam@5
|
21 static void maprequest(XEvent *e);
|
garbeam@5
|
22 static void propertynotify(XEvent *e);
|
garbeam@5
|
23 static void unmapnotify(XEvent *e);
|
garbeam@5
|
24
|
garbeam@5
|
25 void (*handler[LASTEvent]) (XEvent *) = {
|
garbeam@5
|
26 [ConfigureRequest] = configurerequest,
|
garbeam@5
|
27 [DestroyNotify] = destroynotify,
|
garbeam@5
|
28 [EnterNotify] = enternotify,
|
garbeam@5
|
29 [LeaveNotify] = leavenotify,
|
garbeam@5
|
30 [Expose] = expose,
|
garbeam@5
|
31 [KeyPress] = keypress,
|
garbeam@5
|
32 [KeymapNotify] = keymapnotify,
|
garbeam@5
|
33 [MapRequest] = maprequest,
|
garbeam@5
|
34 [PropertyNotify] = propertynotify,
|
garbeam@5
|
35 [UnmapNotify] = unmapnotify
|
garbeam@5
|
36 };
|
garbeam@5
|
37
|
garbeam@5
|
38 unsigned int
|
garbeam@5
|
39 flush_masked_events(long even_mask)
|
garbeam@5
|
40 {
|
garbeam@5
|
41 XEvent ev;
|
garbeam@5
|
42 unsigned int n = 0;
|
garbeam@5
|
43 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
|
garbeam@5
|
44 return n;
|
garbeam@5
|
45 }
|
garbeam@5
|
46
|
garbeam@5
|
47 static void
|
garbeam@5
|
48 configurerequest(XEvent *e)
|
garbeam@5
|
49 {
|
garbeam@5
|
50 #if 0
|
garbeam@5
|
51 XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
garbeam@5
|
52 XWindowChanges wc;
|
garbeam@5
|
53 XRectangle *frect;
|
garbeam@5
|
54 Client *c;
|
garbeam@5
|
55
|
garbeam@5
|
56 c = client_of_win(ev->window);
|
garbeam@5
|
57 ev->value_mask &= ~CWSibling;
|
garbeam@5
|
58 if(c) {
|
garbeam@5
|
59 gravitate_client(c, True);
|
garbeam@5
|
60
|
garbeam@5
|
61 if(ev->value_mask & CWX)
|
garbeam@5
|
62 c->rect.x = ev->x;
|
garbeam@5
|
63 if(ev->value_mask & CWY)
|
garbeam@5
|
64 c->rect.y = ev->y;
|
garbeam@5
|
65 if(ev->value_mask & CWWidth)
|
garbeam@5
|
66 c->rect.width = ev->width;
|
garbeam@5
|
67 if(ev->value_mask & CWHeight)
|
garbeam@5
|
68 c->rect.height = ev->height;
|
garbeam@5
|
69 if(ev->value_mask & CWBorderWidth)
|
garbeam@5
|
70 c->border = ev->border_width;
|
garbeam@5
|
71
|
garbeam@5
|
72 gravitate_client(c, False);
|
garbeam@5
|
73
|
garbeam@5
|
74 if(c->frame) {
|
garbeam@5
|
75 if(c->sel->area->floating)
|
garbeam@5
|
76 frect=&c->sel->rect;
|
garbeam@5
|
77 else
|
garbeam@5
|
78 frect=&c->sel->revert;
|
garbeam@5
|
79
|
garbeam@5
|
80 if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
|
garbeam@5
|
81 frect->y = wc.y = -height_of_bar();
|
garbeam@5
|
82 frect->x = wc.x = -def.border;
|
garbeam@5
|
83 }
|
garbeam@5
|
84 else {
|
garbeam@5
|
85 frect->y = wc.y = c->rect.y - height_of_bar();
|
garbeam@5
|
86 frect->x = wc.x = c->rect.x - def.border;
|
garbeam@5
|
87 }
|
garbeam@5
|
88 frect->width = wc.width = c->rect.width + 2 * def.border;
|
garbeam@5
|
89 frect->height = wc.height = c->rect.height + def.border
|
garbeam@5
|
90 + height_of_bar();
|
garbeam@5
|
91 wc.border_width = 1;
|
garbeam@5
|
92 wc.sibling = None;
|
garbeam@5
|
93 wc.stack_mode = ev->detail;
|
garbeam@5
|
94 if(c->sel->area->view != screen->sel)
|
garbeam@5
|
95 wc.x += 2 * screen->rect.width;
|
garbeam@5
|
96 if(c->sel->area->floating) {
|
garbeam@5
|
97 XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
|
garbeam@5
|
98 configure_client(c);
|
garbeam@5
|
99 }
|
garbeam@5
|
100 }
|
garbeam@5
|
101 }
|
garbeam@5
|
102
|
garbeam@5
|
103 wc.x = ev->x;
|
garbeam@5
|
104 wc.y = ev->y;
|
garbeam@5
|
105 wc.width = ev->width;
|
garbeam@5
|
106 wc.height = ev->height;
|
garbeam@5
|
107
|
garbeam@5
|
108 if(c && c->frame) {
|
garbeam@5
|
109 wc.x = def.border;
|
garbeam@5
|
110 wc.y = height_of_bar();
|
garbeam@5
|
111 wc.width = c->sel->rect.width - 2 * def.border;
|
garbeam@5
|
112 wc.height = c->sel->rect.height - def.border - height_of_bar();
|
garbeam@5
|
113 }
|
garbeam@5
|
114
|
garbeam@5
|
115 wc.border_width = 0;
|
garbeam@5
|
116 wc.sibling = None;
|
garbeam@5
|
117 wc.stack_mode = Above;
|
garbeam@5
|
118 ev->value_mask &= ~CWStackMode;
|
garbeam@5
|
119 ev->value_mask |= CWBorderWidth;
|
garbeam@5
|
120 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
|
garbeam@5
|
121
|
garbeam@5
|
122 XFlush(dpy);
|
garbeam@5
|
123 #endif
|
garbeam@5
|
124 }
|
garbeam@5
|
125
|
garbeam@5
|
126 static void
|
garbeam@5
|
127 destroynotify(XEvent *e)
|
garbeam@5
|
128 {
|
garbeam@5
|
129 #if 0
|
garbeam@5
|
130 Client *c;
|
garbeam@5
|
131 XDestroyWindowEvent *ev = &e->xdestroywindow;
|
garbeam@5
|
132
|
garbeam@5
|
133 if((c = client_of_win(ev->window)))
|
garbeam@5
|
134 destroy_client(c);
|
garbeam@5
|
135 #endif
|
garbeam@5
|
136 }
|
garbeam@5
|
137
|
garbeam@5
|
138 static void
|
garbeam@5
|
139 enternotify(XEvent *e)
|
garbeam@5
|
140 {
|
garbeam@5
|
141 #if 0
|
garbeam@5
|
142 XCrossingEvent *ev = &e->xcrossing;
|
garbeam@5
|
143 Client *c;
|
garbeam@5
|
144
|
garbeam@5
|
145 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
|
garbeam@5
|
146 return;
|
garbeam@5
|
147
|
garbeam@5
|
148 if((c = client_of_win(ev->window))) {
|
garbeam@5
|
149 Frame *f = c->sel;
|
garbeam@5
|
150 Area *a = f->area;
|
garbeam@5
|
151 if(a->mode == Colmax)
|
garbeam@5
|
152 c = a->sel->client;
|
garbeam@5
|
153 focus(c, False);
|
garbeam@5
|
154 }
|
garbeam@5
|
155 else if(ev->window == root) {
|
garbeam@5
|
156 sel_screen = True;
|
garbeam@5
|
157 draw_frames();
|
garbeam@5
|
158 }
|
garbeam@5
|
159 #endif
|
garbeam@5
|
160 }
|
garbeam@5
|
161
|
garbeam@5
|
162 static void
|
garbeam@5
|
163 leavenotify(XEvent *e)
|
garbeam@5
|
164 {
|
garbeam@5
|
165 XCrossingEvent *ev = &e->xcrossing;
|
garbeam@5
|
166
|
garbeam@5
|
167 if((ev->window == root) && !ev->same_screen) {
|
garbeam@5
|
168 sel_screen = True;
|
garbeam@5
|
169 /*draw_frames();*/
|
garbeam@5
|
170 }
|
garbeam@5
|
171 }
|
garbeam@5
|
172
|
garbeam@5
|
173 static void
|
garbeam@5
|
174 expose(XEvent *e)
|
garbeam@5
|
175 {
|
garbeam@5
|
176 XExposeEvent *ev = &e->xexpose;
|
garbeam@5
|
177
|
garbeam@5
|
178 if(ev->count == 0) {
|
garbeam@5
|
179 if(ev->window == barwin)
|
garbeam@5
|
180 draw_bar();
|
garbeam@5
|
181 }
|
garbeam@5
|
182 }
|
garbeam@5
|
183
|
garbeam@5
|
184 static void
|
garbeam@5
|
185 keypress(XEvent *e)
|
garbeam@5
|
186 {
|
garbeam@5
|
187 #if 0
|
garbeam@5
|
188 XKeyEvent *ev = &e->xkey;
|
garbeam@5
|
189 KeySym k = 0;
|
garbeam@5
|
190 char buf[32];
|
garbeam@5
|
191 int n;
|
garbeam@5
|
192 static Frame *f;
|
garbeam@5
|
193
|
garbeam@5
|
194
|
garbeam@5
|
195 ev->state &= valid_mask;
|
garbeam@5
|
196 if((f = frame_of_win(ev->window))) {
|
garbeam@5
|
197 buf[0] = 0;
|
garbeam@5
|
198 n = XLookupString(ev, buf, sizeof(buf), &k, 0);
|
garbeam@5
|
199 if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
|
garbeam@5
|
200 || IsPFKey(k) || IsPrivateKeypadKey(k))
|
garbeam@5
|
201 return;
|
garbeam@5
|
202 buf[n] = 0;
|
garbeam@5
|
203 blitz_kpress_input(&f->tagbar, ev->state, k, buf);
|
garbeam@5
|
204 }
|
garbeam@5
|
205 else
|
garbeam@5
|
206 key(root, ev->state, (KeyCode) ev->keycode);
|
garbeam@5
|
207 #endif
|
garbeam@5
|
208 }
|
garbeam@5
|
209
|
garbeam@5
|
210 static void
|
garbeam@5
|
211 keymapnotify(XEvent *e)
|
garbeam@5
|
212 {
|
garbeam@5
|
213 #if 0
|
garbeam@5
|
214 update_keys();
|
garbeam@5
|
215 #endif
|
garbeam@5
|
216 }
|
garbeam@5
|
217
|
garbeam@5
|
218 static void
|
garbeam@5
|
219 maprequest(XEvent *e)
|
garbeam@5
|
220 {
|
garbeam@5
|
221 XMapRequestEvent *ev = &e->xmaprequest;
|
garbeam@5
|
222 static XWindowAttributes wa;
|
garbeam@5
|
223
|
garbeam@5
|
224 if(!XGetWindowAttributes(dpy, ev->window, &wa))
|
garbeam@5
|
225 return;
|
garbeam@5
|
226
|
garbeam@5
|
227 if(wa.override_redirect) {
|
garbeam@5
|
228 XSelectInput(dpy, ev->window,
|
garbeam@5
|
229 (StructureNotifyMask | PropertyChangeMask));
|
garbeam@5
|
230 return;
|
garbeam@5
|
231 }
|
garbeam@5
|
232
|
garbeam@6
|
233 /*if(!client_of_win(ev->window))*/
|
garbeam@6
|
234 manage(create_client(ev->window, &wa));
|
garbeam@5
|
235 }
|
garbeam@5
|
236
|
garbeam@5
|
237 static void
|
garbeam@5
|
238 propertynotify(XEvent *e)
|
garbeam@5
|
239 {
|
garbeam@5
|
240 #if 0
|
garbeam@5
|
241 XPropertyEvent *ev = &e->xproperty;
|
garbeam@5
|
242 Client *c;
|
garbeam@5
|
243
|
garbeam@5
|
244 if(ev->state == PropertyDelete)
|
garbeam@5
|
245 return; /* ignore */
|
garbeam@5
|
246
|
garbeam@5
|
247 if((c = client_of_win(ev->window)))
|
garbeam@5
|
248 prop_client(c, ev);
|
garbeam@5
|
249 #endif
|
garbeam@5
|
250 }
|
garbeam@5
|
251
|
garbeam@5
|
252 static void
|
garbeam@5
|
253 unmapnotify(XEvent *e)
|
garbeam@5
|
254 {
|
garbeam@5
|
255 #if 0
|
garbeam@5
|
256 Client *c;
|
garbeam@5
|
257 XUnmapEvent *ev = &e->xunmap;
|
garbeam@5
|
258
|
garbeam@5
|
259 if((c = client_of_win(ev->window)))
|
garbeam@5
|
260 destroy_client(c);
|
garbeam@5
|
261 #endif
|
garbeam@5
|
262 }
|