dwm-meillo

view event.c @ 21:3ef108a5ca0a

implemented draw_client stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 23:18:30 +0200
parents 4560e0882c1d
children bd3a44353916
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>
10 #include <X11/Xatom.h>
12 #include "wm.h"
14 /* local functions */
15 static void buttonpress(XEvent *e);
16 static void configurerequest(XEvent *e);
17 static void destroynotify(XEvent *e);
18 static void enternotify(XEvent *e);
19 static void leavenotify(XEvent *e);
20 static void expose(XEvent *e);
21 static void keymapnotify(XEvent *e);
22 static void maprequest(XEvent *e);
23 static void propertynotify(XEvent *e);
24 static void unmapnotify(XEvent *e);
26 void (*handler[LASTEvent]) (XEvent *) = {
27 [ButtonPress] = buttonpress,
28 [ConfigureRequest] = configurerequest,
29 [DestroyNotify] = destroynotify,
30 [EnterNotify] = enternotify,
31 [LeaveNotify] = leavenotify,
32 [Expose] = expose,
33 [KeyPress] = keypress,
34 [KeymapNotify] = keymapnotify,
35 [MapRequest] = maprequest,
36 [PropertyNotify] = propertynotify,
37 [UnmapNotify] = unmapnotify
38 };
40 unsigned int
41 discard_events(long even_mask)
42 {
43 XEvent ev;
44 unsigned int n = 0;
45 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
46 return n;
47 }
49 static void
50 buttonpress(XEvent *e)
51 {
52 XButtonPressedEvent *ev = &e->xbutton;
53 Client *c;
55 if((c = getclient(ev->window))) {
56 switch(ev->button) {
57 default:
58 break;
59 case Button1:
60 mmove(c);
61 break;
62 case Button2:
63 XLowerWindow(dpy, c->win);
64 break;
65 case Button3:
66 mresize(c);
67 break;
68 }
69 }
70 }
72 static void
73 configurerequest(XEvent *e)
74 {
75 XConfigureRequestEvent *ev = &e->xconfigurerequest;
76 XWindowChanges wc;
77 Client *c;
79 ev->value_mask &= ~CWSibling;
80 if((c = getclient(ev->window))) {
81 if(ev->value_mask & CWX)
82 c->x = ev->x;
83 if(ev->value_mask & CWY)
84 c->y = ev->y;
85 if(ev->value_mask & CWWidth)
86 c->w = ev->width;
87 if(ev->value_mask & CWHeight)
88 c->h = ev->height;
89 }
91 wc.x = ev->x;
92 wc.y = ev->y;
93 wc.width = ev->width;
94 wc.height = ev->height;
95 wc.border_width = 0;
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 }
104 static void
105 destroynotify(XEvent *e)
106 {
107 Client *c;
108 XDestroyWindowEvent *ev = &e->xdestroywindow;
110 if((c = getclient(ev->window)))
111 unmanage(c);
112 }
114 static void
115 enternotify(XEvent *e)
116 {
117 XCrossingEvent *ev = &e->xcrossing;
118 Client *c;
120 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
121 return;
123 if((c = getclient(ev->window)))
124 focus(c);
125 else if(ev->window == root) {
126 sel_screen = True;
127 /*draw_frames();*/
128 }
129 }
131 static void
132 leavenotify(XEvent *e)
133 {
134 XCrossingEvent *ev = &e->xcrossing;
136 if((ev->window == root) && !ev->same_screen) {
137 sel_screen = True;
138 /*draw_frames();*/
139 }
140 }
142 static void
143 expose(XEvent *e)
144 {
145 XExposeEvent *ev = &e->xexpose;
146 Client *c;
148 if(ev->count == 0) {
149 if((c = getclient(ev->window)))
150 draw_client(c);
151 else if(ev->window == barwin)
152 draw_bar();
153 }
154 }
156 static void
157 keymapnotify(XEvent *e)
158 {
159 update_keys();
160 }
162 static void
163 maprequest(XEvent *e)
164 {
165 XMapRequestEvent *ev = &e->xmaprequest;
166 static XWindowAttributes wa;
168 if(!XGetWindowAttributes(dpy, ev->window, &wa))
169 return;
171 if(wa.override_redirect) {
172 XSelectInput(dpy, ev->window,
173 (StructureNotifyMask | PropertyChangeMask));
174 return;
175 }
177 if(!getclient(ev->window))
178 manage(ev->window, &wa);
179 }
181 static void
182 propertynotify(XEvent *e)
183 {
184 XPropertyEvent *ev = &e->xproperty;
185 Client *c;
187 if(ev->state == PropertyDelete)
188 return; /* ignore */
190 if(ev->atom == wm_atom[WMProtocols]) {
191 c->proto = win_proto(c->win);
192 return;
193 }
194 if((c = getclient(ev->window))) {
195 switch (ev->atom) {
196 default: break;
197 case XA_WM_TRANSIENT_FOR:
198 XGetTransientForHint(dpy, c->win, &c->trans);
199 break;
200 update_size(c);
201 case XA_WM_NORMAL_HINTS:
202 update_size(c);
203 break;
204 }
205 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
206 update_name(c);
207 }
208 }
209 }
211 static void
212 unmapnotify(XEvent *e)
213 {
214 Client *c;
215 XUnmapEvent *ev = &e->xunmap;
217 if((c = getclient(ev->window)))
218 unmanage(c);
219 }