aewl

view event.c @ 70:e5fff8249705

draw bar on exposure ;)
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 18:46:12 +0200
parents f14858218641
children c2ddb9dbbd10
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 <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <X11/keysym.h>
11 #include <X11/Xatom.h>
13 #include "dwm.h"
15 /* local functions */
16 static void buttonpress(XEvent *e);
17 static void configurerequest(XEvent *e);
18 static void destroynotify(XEvent *e);
19 static void enternotify(XEvent *e);
20 static void leavenotify(XEvent *e);
21 static void expose(XEvent *e);
22 static void keymapnotify(XEvent *e);
23 static void maprequest(XEvent *e);
24 static void propertynotify(XEvent *e);
25 static void unmapnotify(XEvent *e);
27 void (*handler[LASTEvent]) (XEvent *) = {
28 [ButtonPress] = buttonpress,
29 [ConfigureRequest] = configurerequest,
30 [DestroyNotify] = destroynotify,
31 [EnterNotify] = enternotify,
32 [LeaveNotify] = leavenotify,
33 [Expose] = expose,
34 [KeyPress] = keypress,
35 [KeymapNotify] = keymapnotify,
36 [MapRequest] = maprequest,
37 [PropertyNotify] = propertynotify,
38 [UnmapNotify] = unmapnotify
39 };
41 static void
42 buttonpress(XEvent *e)
43 {
44 XButtonPressedEvent *ev = &e->xbutton;
45 Client *c;
47 if(barwin == ev->window)
48 barclick(ev);
49 else if((c = getclient(ev->window))) {
50 craise(c);
51 switch(ev->button) {
52 default:
53 break;
54 case Button1:
55 mmove(c);
56 break;
57 case Button2:
58 lower(c);
59 break;
60 case Button3:
61 mresize(c);
62 break;
63 }
64 }
65 }
67 static void
68 configurerequest(XEvent *e)
69 {
70 XConfigureRequestEvent *ev = &e->xconfigurerequest;
71 XWindowChanges wc;
72 Client *c;
74 ev->value_mask &= ~CWSibling;
75 if((c = getclient(ev->window))) {
76 gravitate(c, True);
77 if(ev->value_mask & CWX)
78 c->x = ev->x;
79 if(ev->value_mask & CWY)
80 c->y = ev->y;
81 if(ev->value_mask & CWWidth)
82 c->w = ev->width;
83 if(ev->value_mask & CWHeight)
84 c->h = ev->height;
85 if(ev->value_mask & CWBorderWidth)
86 c->border = 1;
87 gravitate(c, False);
88 resize(c, True);
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 = 1;
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 issel = True;
127 }
129 static void
130 leavenotify(XEvent *e)
131 {
132 XCrossingEvent *ev = &e->xcrossing;
134 if((ev->window == root) && !ev->same_screen)
135 issel = True;
136 }
138 static void
139 expose(XEvent *e)
140 {
141 XExposeEvent *ev = &e->xexpose;
142 Client *c;
144 if(ev->count == 0) {
145 if(barwin == ev->window)
146 draw_bar();
147 else if((c = gettitle(ev->window)))
148 draw_client(c);
149 }
150 }
152 static void
153 keymapnotify(XEvent *e)
154 {
155 update_keys();
156 }
158 static void
159 maprequest(XEvent *e)
160 {
161 XMapRequestEvent *ev = &e->xmaprequest;
162 static XWindowAttributes wa;
164 if(!XGetWindowAttributes(dpy, ev->window, &wa))
165 return;
167 if(wa.override_redirect) {
168 XSelectInput(dpy, ev->window,
169 (StructureNotifyMask | PropertyChangeMask));
170 return;
171 }
173 if(!getclient(ev->window))
174 manage(ev->window, &wa);
175 }
177 static void
178 propertynotify(XEvent *e)
179 {
180 XPropertyEvent *ev = &e->xproperty;
181 Window trans;
182 Client *c;
184 if(ev->state == PropertyDelete)
185 return; /* ignore */
187 if((c = getclient(ev->window))) {
188 if(ev->atom == wm_atom[WMProtocols]) {
189 c->proto = win_proto(c->win);
190 return;
191 }
192 switch (ev->atom) {
193 default: break;
194 case XA_WM_TRANSIENT_FOR:
195 XGetTransientForHint(dpy, c->win, &trans);
196 if(!c->floating && (c->floating = (trans != 0)))
197 arrange(NULL);
198 break;
199 case XA_WM_NORMAL_HINTS:
200 update_size(c);
201 break;
202 }
203 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
204 update_name(c);
205 draw_client(c);
206 }
207 }
208 }
210 static void
211 unmapnotify(XEvent *e)
212 {
213 Client *c;
214 XUnmapEvent *ev = &e->xunmap;
216 if((c = getclient(ev->window)))
217 unmanage(c);
218 }