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@13
|
10 #include <X11/Xatom.h>
|
garbeam@5
|
11
|
garbeam@5
|
12 #include "wm.h"
|
garbeam@5
|
13
|
garbeam@5
|
14 /* local functions */
|
garbeam@18
|
15 static void buttonpress(XEvent *e);
|
garbeam@5
|
16 static void configurerequest(XEvent *e);
|
garbeam@5
|
17 static void destroynotify(XEvent *e);
|
garbeam@5
|
18 static void enternotify(XEvent *e);
|
garbeam@5
|
19 static void leavenotify(XEvent *e);
|
garbeam@5
|
20 static void expose(XEvent *e);
|
garbeam@5
|
21 static void keymapnotify(XEvent *e);
|
garbeam@5
|
22 static void maprequest(XEvent *e);
|
garbeam@5
|
23 static void propertynotify(XEvent *e);
|
garbeam@5
|
24 static void unmapnotify(XEvent *e);
|
garbeam@5
|
25
|
garbeam@5
|
26 void (*handler[LASTEvent]) (XEvent *) = {
|
garbeam@18
|
27 [ButtonPress] = buttonpress,
|
garbeam@5
|
28 [ConfigureRequest] = configurerequest,
|
garbeam@5
|
29 [DestroyNotify] = destroynotify,
|
garbeam@5
|
30 [EnterNotify] = enternotify,
|
garbeam@5
|
31 [LeaveNotify] = leavenotify,
|
garbeam@5
|
32 [Expose] = expose,
|
garbeam@5
|
33 [KeyPress] = keypress,
|
garbeam@5
|
34 [KeymapNotify] = keymapnotify,
|
garbeam@5
|
35 [MapRequest] = maprequest,
|
garbeam@5
|
36 [PropertyNotify] = propertynotify,
|
garbeam@5
|
37 [UnmapNotify] = unmapnotify
|
garbeam@5
|
38 };
|
garbeam@5
|
39
|
garbeam@5
|
40 unsigned int
|
garbeam@18
|
41 discard_events(long even_mask)
|
garbeam@5
|
42 {
|
garbeam@5
|
43 XEvent ev;
|
garbeam@5
|
44 unsigned int n = 0;
|
garbeam@5
|
45 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
|
garbeam@5
|
46 return n;
|
garbeam@5
|
47 }
|
garbeam@5
|
48
|
garbeam@5
|
49 static void
|
garbeam@18
|
50 buttonpress(XEvent *e)
|
garbeam@18
|
51 {
|
garbeam@18
|
52 XButtonPressedEvent *ev = &e->xbutton;
|
garbeam@18
|
53 Client *c;
|
garbeam@18
|
54
|
garbeam@18
|
55 if((c = getclient(ev->window))) {
|
garbeam@18
|
56 switch(ev->button) {
|
garbeam@18
|
57 default:
|
garbeam@18
|
58 break;
|
garbeam@18
|
59 case Button1:
|
garbeam@18
|
60 mmove(c);
|
garbeam@18
|
61 break;
|
garbeam@18
|
62 case Button2:
|
garbeam@18
|
63 XLowerWindow(dpy, c->win);
|
garbeam@18
|
64 break;
|
garbeam@18
|
65 case Button3:
|
garbeam@18
|
66 mresize(c);
|
garbeam@18
|
67 break;
|
garbeam@18
|
68 }
|
garbeam@18
|
69 }
|
garbeam@18
|
70 }
|
garbeam@18
|
71
|
garbeam@18
|
72 static void
|
garbeam@5
|
73 configurerequest(XEvent *e)
|
garbeam@5
|
74 {
|
garbeam@5
|
75 XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
garbeam@5
|
76 XWindowChanges wc;
|
garbeam@5
|
77 Client *c;
|
garbeam@5
|
78
|
garbeam@5
|
79 ev->value_mask &= ~CWSibling;
|
garbeam@18
|
80 if((c = getclient(ev->window))) {
|
garbeam@5
|
81 if(ev->value_mask & CWX)
|
garbeam@9
|
82 c->r[RFloat].x = ev->x;
|
garbeam@5
|
83 if(ev->value_mask & CWY)
|
garbeam@9
|
84 c->r[RFloat].y = ev->y;
|
garbeam@5
|
85 if(ev->value_mask & CWWidth)
|
garbeam@9
|
86 c->r[RFloat].width = ev->width;
|
garbeam@5
|
87 if(ev->value_mask & CWHeight)
|
garbeam@9
|
88 c->r[RFloat].height = ev->height;
|
garbeam@5
|
89 if(ev->value_mask & CWBorderWidth)
|
garbeam@5
|
90 c->border = ev->border_width;
|
garbeam@5
|
91 }
|
garbeam@5
|
92
|
garbeam@5
|
93 wc.x = ev->x;
|
garbeam@5
|
94 wc.y = ev->y;
|
garbeam@5
|
95 wc.width = ev->width;
|
garbeam@5
|
96 wc.height = ev->height;
|
garbeam@5
|
97 wc.border_width = 0;
|
garbeam@5
|
98 wc.sibling = None;
|
garbeam@5
|
99 wc.stack_mode = Above;
|
garbeam@5
|
100 ev->value_mask &= ~CWStackMode;
|
garbeam@5
|
101 ev->value_mask |= CWBorderWidth;
|
garbeam@5
|
102 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
|
garbeam@5
|
103 XFlush(dpy);
|
garbeam@5
|
104 }
|
garbeam@5
|
105
|
garbeam@5
|
106 static void
|
garbeam@5
|
107 destroynotify(XEvent *e)
|
garbeam@5
|
108 {
|
garbeam@5
|
109 Client *c;
|
garbeam@5
|
110 XDestroyWindowEvent *ev = &e->xdestroywindow;
|
garbeam@5
|
111
|
garbeam@11
|
112 if((c = getclient(ev->window)))
|
garbeam@11
|
113 unmanage(c);
|
garbeam@5
|
114 }
|
garbeam@5
|
115
|
garbeam@5
|
116 static void
|
garbeam@5
|
117 enternotify(XEvent *e)
|
garbeam@5
|
118 {
|
garbeam@5
|
119 XCrossingEvent *ev = &e->xcrossing;
|
garbeam@5
|
120 Client *c;
|
garbeam@5
|
121
|
garbeam@5
|
122 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
|
garbeam@5
|
123 return;
|
garbeam@5
|
124
|
garbeam@13
|
125 if((c = getclient(ev->window)))
|
garbeam@13
|
126 focus(c);
|
garbeam@5
|
127 else if(ev->window == root) {
|
garbeam@5
|
128 sel_screen = True;
|
garbeam@13
|
129 /*draw_frames();*/
|
garbeam@5
|
130 }
|
garbeam@5
|
131 }
|
garbeam@5
|
132
|
garbeam@5
|
133 static void
|
garbeam@5
|
134 leavenotify(XEvent *e)
|
garbeam@5
|
135 {
|
garbeam@5
|
136 XCrossingEvent *ev = &e->xcrossing;
|
garbeam@5
|
137
|
garbeam@5
|
138 if((ev->window == root) && !ev->same_screen) {
|
garbeam@5
|
139 sel_screen = True;
|
garbeam@5
|
140 /*draw_frames();*/
|
garbeam@5
|
141 }
|
garbeam@5
|
142 }
|
garbeam@5
|
143
|
garbeam@5
|
144 static void
|
garbeam@5
|
145 expose(XEvent *e)
|
garbeam@5
|
146 {
|
garbeam@5
|
147 XExposeEvent *ev = &e->xexpose;
|
garbeam@5
|
148
|
garbeam@5
|
149 if(ev->count == 0) {
|
garbeam@5
|
150 if(ev->window == barwin)
|
garbeam@5
|
151 draw_bar();
|
garbeam@5
|
152 }
|
garbeam@5
|
153 }
|
garbeam@5
|
154
|
garbeam@5
|
155 static void
|
garbeam@5
|
156 keymapnotify(XEvent *e)
|
garbeam@5
|
157 {
|
garbeam@5
|
158 update_keys();
|
garbeam@5
|
159 }
|
garbeam@5
|
160
|
garbeam@5
|
161 static void
|
garbeam@5
|
162 maprequest(XEvent *e)
|
garbeam@5
|
163 {
|
garbeam@5
|
164 XMapRequestEvent *ev = &e->xmaprequest;
|
garbeam@5
|
165 static XWindowAttributes wa;
|
garbeam@5
|
166
|
garbeam@5
|
167 if(!XGetWindowAttributes(dpy, ev->window, &wa))
|
garbeam@5
|
168 return;
|
garbeam@5
|
169
|
garbeam@5
|
170 if(wa.override_redirect) {
|
garbeam@5
|
171 XSelectInput(dpy, ev->window,
|
garbeam@5
|
172 (StructureNotifyMask | PropertyChangeMask));
|
garbeam@5
|
173 return;
|
garbeam@5
|
174 }
|
garbeam@5
|
175
|
garbeam@10
|
176 if(!getclient(ev->window))
|
garbeam@10
|
177 manage(ev->window, &wa);
|
garbeam@5
|
178 }
|
garbeam@5
|
179
|
garbeam@5
|
180 static void
|
garbeam@5
|
181 propertynotify(XEvent *e)
|
garbeam@5
|
182 {
|
garbeam@5
|
183 XPropertyEvent *ev = &e->xproperty;
|
garbeam@13
|
184 long msize;
|
garbeam@5
|
185 Client *c;
|
garbeam@5
|
186
|
garbeam@5
|
187 if(ev->state == PropertyDelete)
|
garbeam@5
|
188 return; /* ignore */
|
garbeam@5
|
189
|
garbeam@13
|
190 if(ev->atom == wm_atom[WMProtocols]) {
|
garbeam@13
|
191 c->proto = win_proto(c->win);
|
garbeam@13
|
192 return;
|
garbeam@13
|
193 }
|
garbeam@13
|
194 if((c = getclient(ev->window))) {
|
garbeam@13
|
195 switch (ev->atom) {
|
garbeam@13
|
196 default: break;
|
garbeam@13
|
197 case XA_WM_TRANSIENT_FOR:
|
garbeam@13
|
198 XGetTransientForHint(dpy, c->win, &c->trans);
|
garbeam@13
|
199 break;
|
garbeam@13
|
200 case XA_WM_NORMAL_HINTS:
|
garbeam@13
|
201 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
|
garbeam@13
|
202 || !c->size.flags)
|
garbeam@13
|
203 c->size.flags = PSize;
|
garbeam@13
|
204 if(c->size.flags & PMinSize && c->size.flags & PMaxSize
|
garbeam@13
|
205 && c->size.min_width == c->size.max_width
|
garbeam@13
|
206 && c->size.min_height == c->size.max_height)
|
garbeam@13
|
207 c->fixedsize = True;
|
garbeam@13
|
208 else
|
garbeam@13
|
209 c->fixedsize = False;
|
garbeam@13
|
210 break;
|
garbeam@13
|
211 }
|
garbeam@13
|
212 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
|
garbeam@13
|
213 update_name(c);
|
garbeam@13
|
214 }
|
garbeam@13
|
215 }
|
garbeam@5
|
216 }
|
garbeam@5
|
217
|
garbeam@5
|
218 static void
|
garbeam@5
|
219 unmapnotify(XEvent *e)
|
garbeam@5
|
220 {
|
garbeam@5
|
221 Client *c;
|
garbeam@5
|
222 XUnmapEvent *ev = &e->xunmap;
|
garbeam@5
|
223
|
garbeam@10
|
224 if((c = getclient(ev->window)))
|
garbeam@10
|
225 unmanage(c);
|
garbeam@5
|
226 }
|