event.c (view raw)
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>
10
11#include "wm.h"
12
13/* local functions */
14static void configurerequest(XEvent *e);
15static void destroynotify(XEvent *e);
16static void enternotify(XEvent *e);
17static void leavenotify(XEvent *e);
18static void expose(XEvent *e);
19static void keymapnotify(XEvent *e);
20static void maprequest(XEvent *e);
21static void propertynotify(XEvent *e);
22static void unmapnotify(XEvent *e);
23
24void (*handler[LASTEvent]) (XEvent *) = {
25 [ConfigureRequest] = configurerequest,
26 [DestroyNotify] = destroynotify,
27 [EnterNotify] = enternotify,
28 [LeaveNotify] = leavenotify,
29 [Expose] = expose,
30 [KeyPress] = keypress,
31 [KeymapNotify] = keymapnotify,
32 [MapRequest] = maprequest,
33 [PropertyNotify] = propertynotify,
34 [UnmapNotify] = unmapnotify
35};
36
37unsigned int
38flush_masked_events(long even_mask)
39{
40 XEvent ev;
41 unsigned int n = 0;
42 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
43 return n;
44}
45
46static void
47configurerequest(XEvent *e)
48{
49 XConfigureRequestEvent *ev = &e->xconfigurerequest;
50 XWindowChanges wc;
51 Client *c;
52
53 c = getclient(ev->window);
54 ev->value_mask &= ~CWSibling;
55 if(c) {
56 if(ev->value_mask & CWX)
57 c->r[RFloat].x = ev->x;
58 if(ev->value_mask & CWY)
59 c->r[RFloat].y = ev->y;
60 if(ev->value_mask & CWWidth)
61 c->r[RFloat].width = ev->width;
62 if(ev->value_mask & CWHeight)
63 c->r[RFloat].height = ev->height;
64 if(ev->value_mask & CWBorderWidth)
65 c->border = ev->border_width;
66 }
67
68 wc.x = ev->x;
69 wc.y = ev->y;
70 wc.width = ev->width;
71 wc.height = ev->height;
72 wc.border_width = 0;
73 wc.sibling = None;
74 wc.stack_mode = Above;
75 ev->value_mask &= ~CWStackMode;
76 ev->value_mask |= CWBorderWidth;
77 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
78 XFlush(dpy);
79}
80
81static void
82destroynotify(XEvent *e)
83{
84 Client *c;
85 XDestroyWindowEvent *ev = &e->xdestroywindow;
86
87 if((c = getclient(ev->window)))
88 unmanage(c);
89}
90
91static void
92enternotify(XEvent *e)
93{
94#if 0
95 XCrossingEvent *ev = &e->xcrossing;
96 Client *c;
97
98 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
99 return;
100
101 if((c = client_of_win(ev->window))) {
102 Frame *f = c->sel;
103 Area *a = f->area;
104 if(a->mode == Colmax)
105 c = a->sel->client;
106 focus(c, False);
107 }
108 else if(ev->window == root) {
109 sel_screen = True;
110 draw_frames();
111 }
112#endif
113}
114
115static void
116leavenotify(XEvent *e)
117{
118 XCrossingEvent *ev = &e->xcrossing;
119
120 if((ev->window == root) && !ev->same_screen) {
121 sel_screen = True;
122 /*draw_frames();*/
123 }
124}
125
126static void
127expose(XEvent *e)
128{
129 XExposeEvent *ev = &e->xexpose;
130
131 if(ev->count == 0) {
132 if(ev->window == barwin)
133 draw_bar();
134 }
135}
136
137static void
138keymapnotify(XEvent *e)
139{
140#if 0
141 update_keys();
142#endif
143}
144
145static void
146maprequest(XEvent *e)
147{
148 XMapRequestEvent *ev = &e->xmaprequest;
149 static XWindowAttributes wa;
150
151 if(!XGetWindowAttributes(dpy, ev->window, &wa))
152 return;
153
154 if(wa.override_redirect) {
155 XSelectInput(dpy, ev->window,
156 (StructureNotifyMask | PropertyChangeMask));
157 return;
158 }
159
160 if(!getclient(ev->window))
161 manage(ev->window, &wa);
162}
163
164static void
165propertynotify(XEvent *e)
166{
167#if 0
168 XPropertyEvent *ev = &e->xproperty;
169 Client *c;
170
171 if(ev->state == PropertyDelete)
172 return; /* ignore */
173
174 if((c = client_of_win(ev->window)))
175 prop_client(c, ev);
176#endif
177}
178
179static void
180unmapnotify(XEvent *e)
181{
182 Client *c;
183 XUnmapEvent *ev = &e->xunmap;
184
185 if((c = getclient(ev->window)))
186 unmanage(c);
187}