aewl

view event.c @ 5:e5018cae273f

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