about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 16:14:22 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 16:14:22 +0200
commit33996500763b04119a6867dfa4040a4236c21a41 (patch)
tree7abc832f02c0478dd9b8e339c3ee7874d1bb7787
parent272e15c4b7bdeeb258caadb7c62e70c49c12b16d (diff)
downloaddwm-33996500763b04119a6867dfa4040a4236c21a41.tar.gz
added protocol killing stuff
-rw-r--r--client.c33
-rw-r--r--cmd.c14
-rw-r--r--event.c50
-rw-r--r--menu.c2
-rw-r--r--wm.c66
-rw-r--r--wm.h24
6 files changed, 153 insertions, 36 deletions
diff --git a/client.c b/client.c
index 8aca2e2..caa523c 100644
--- a/client.c
+++ b/client.c
@@ -10,8 +10,8 @@
 #include "util.h"
 #include "wm.h"
 
-static void
-update_client_name(Client *c)
+void
+update_name(Client *c)
 {
 	XTextProperty name;
 	int n;
@@ -38,6 +38,20 @@ update_client_name(Client *c)
 }
 
 void
+focus(Client *c)
+{
+	Client **l;
+	for(l=&stack; *l && *l != c; l=&(*l)->snext);
+	eassert(*l == c);
+	*l = c->snext;
+	c->snext = stack;
+	stack = c;
+	XRaiseWindow(dpy, c->win);
+	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+	XFlush(dpy);
+}
+
+void
 manage(Window w, XWindowAttributes *wa)
 {
 	Client *c, **l;
@@ -59,7 +73,7 @@ manage(Window w, XWindowAttributes *wa)
 		(c->size.flags & PMinSize && c->size.flags & PMaxSize
 		 && c->size.min_width == c->size.max_width
 		 && c->size.min_height == c->size.max_height);
-	update_client_name(c);
+	update_name(c);
 	twa.override_redirect = 1;
 	twa.background_pixmap = ParentRelative;
 	twa.event_mask = ExposureMask;
@@ -73,9 +87,10 @@ manage(Window w, XWindowAttributes *wa)
 	for(l=&clients; *l; l=&(*l)->next);
 	c->next = *l; /* *l == nil */
 	*l = c;
-	XMapRaised(dpy, c->win);
-	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
-	XFlush(dpy);
+	c->snext = stack;
+	stack = c;
+	XMapWindow(dpy, c->win);
+	focus(c);
 }
 
 static int
@@ -98,12 +113,15 @@ unmanage(Client *c)
 	for(l=&clients; *l && *l != c; l=&(*l)->next);
 	eassert(*l == c);
 	*l = c->next;
+	for(l=&stack; *l && *l != c; l=&(*l)->snext);
+	eassert(*l == c);
+	*l = c->snext;
 	free(c);
 
 	XFlush(dpy);
 	XSetErrorHandler(error_handler);
 	XUngrabServer(dpy);
-	/*flush_masked_events(EnterWindowMask); ? */
+	flush_events(EnterWindowMask);
 }
 
 
@@ -116,3 +134,4 @@ getclient(Window w)
 			return c;
 	return NULL;
 }
+
diff --git a/cmd.c b/cmd.c
index 8244540..9ac4e72 100644
--- a/cmd.c
+++ b/cmd.c
@@ -18,3 +18,17 @@ quit(char *arg)
 	fputs("quit\n", stderr);
 	running = False;
 }
+
+void
+kill(char *arg)
+{
+	Client *c = stack;
+
+	if(!c)
+		return;
+	if(c->proto & WM_PROTOCOL_DELWIN)
+		send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
+	else
+		XKillClient(dpy, c->win);
+}
+
diff --git a/event.c b/event.c
index d168787..ccab9d1 100644
--- a/event.c
+++ b/event.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <X11/keysym.h>
+#include <X11/Xatom.h>
 
 #include "wm.h"
 
@@ -35,7 +36,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
 };
 
 unsigned int
-flush_masked_events(long even_mask)
+flush_events(long even_mask)
 {
 	XEvent ev;
 	unsigned int n = 0;
@@ -91,25 +92,18 @@ destroynotify(XEvent *e)
 static void
 enternotify(XEvent *e)
 {
-#if 0
 	XCrossingEvent *ev = &e->xcrossing;
 	Client *c;
 
 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
 		return;
 
-	if((c = client_of_win(ev->window))) {
-		Frame *f = c->sel;
-		Area *a = f->area;
-		if(a->mode == Colmax)
-			c = a->sel->client;
-		focus(c, False);
-	}
+	if((c = getclient(ev->window)))
+		focus(c);
 	else if(ev->window == root) {
 		sel_screen = True;
-		draw_frames();
+		/*draw_frames();*/
 	}
-#endif
 }
 
 static void
@@ -137,9 +131,7 @@ expose(XEvent *e)
 static void
 keymapnotify(XEvent *e)
 {
-#if 0
 	update_keys();
-#endif
 }
 
 static void
@@ -164,16 +156,40 @@ maprequest(XEvent *e)
 static void
 propertynotify(XEvent *e)
 {
-#if 0
 	XPropertyEvent *ev = &e->xproperty;
+	long msize;
 	Client *c;
 
 	if(ev->state == PropertyDelete)
 		return; /* ignore */
 
-	if((c = client_of_win(ev->window)))
-		prop_client(c, ev);
-#endif
+	if(ev->atom == wm_atom[WMProtocols]) {
+		c->proto = win_proto(c->win);
+		return;
+	}
+	if((c = getclient(ev->window))) {
+		switch (ev->atom) {
+			default: break;
+			case XA_WM_TRANSIENT_FOR:
+				XGetTransientForHint(dpy, c->win, &c->trans);
+				break;
+			case XA_WM_NORMAL_HINTS:
+				if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
+						|| !c->size.flags)
+					c->size.flags = PSize;
+				if(c->size.flags & PMinSize && c->size.flags & PMaxSize
+						&& c->size.min_width == c->size.max_width
+						&& c->size.min_height == c->size.max_height)
+					c->fixedsize = True;
+				else
+					c->fixedsize = False;
+				break;
+		}
+		if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
+			update_name(c);
+			/*draw_frame(c->sel);*/
+		}
+	}
 }
 
 static void
diff --git a/menu.c b/menu.c
index 650fc57..e09d3b7 100644
--- a/menu.c
+++ b/menu.c
@@ -304,7 +304,7 @@ kpress(XKeyEvent * e)
 		}
 		break;
 	default:
-		if((num == 1) && !iscntrl((int) buf[0])) {
+		if(num && !iscntrl((int) buf[0])) {
 			buf[num] = 0;
 			if(len > 0)
 				strncat(text, buf, sizeof(text));
diff --git a/wm.c b/wm.c
index ef4721d..b156cba 100644
--- a/wm.c
+++ b/wm.c
@@ -16,18 +16,18 @@
 /* X structs */
 Display *dpy;
 Window root, barwin;
-Atom net_atom[NetLast];
+Atom wm_atom[WMLast], net_atom[NetLast];
 Cursor cursor[CurLast];
 XRectangle rect, barrect;
 Bool running = True;
+Bool sel_screen;
 
 char *bartext, tag[256];
-int screen, sel_screen;
+int screen;
 
 Brush brush = {0};
 Client *clients = NULL;
-
-enum { WM_PROTOCOL_DELWIN = 1 };
+Client *stack = NULL;
 
 static Bool other_wm_running;
 static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
@@ -62,6 +62,62 @@ scan_wins()
 		XFree(wins);
 }
 
+static int
+win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
+{
+	Atom real;
+	int format;
+	unsigned long res, extra;
+	int status;
+
+	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
+			&res, &extra, prop);
+
+	if(status != Success || *prop == 0) {
+		return 0;
+	}
+	if(res == 0) {
+		free((void *) *prop);
+	}
+	return res;
+}
+
+int
+win_proto(Window w)
+{
+	Atom *protocols;
+	long res;
+	int protos = 0;
+	int i;
+
+	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
+			((unsigned char **) &protocols));
+	if(res <= 0) {
+		return protos;
+	}
+	for(i = 0; i < res; i++) {
+		if(protocols[i] == wm_atom[WMDelete])
+			protos |= WM_PROTOCOL_DELWIN;
+	}
+	free((char *) protocols);
+	return protos;
+}
+
+void
+send_message(Window w, Atom a, long value)
+{
+	XEvent e;
+
+	e.type = ClientMessage;
+	e.xclient.window = w;
+	e.xclient.message_type = a;
+	e.xclient.format = 32;
+	e.xclient.data.l[0] = value;
+	e.xclient.data.l[1] = CurrentTime;
+	XSendEvent(dpy, w, False, NoEventMask, &e);
+	XFlush(dpy);
+}
+
 /*
  * There's no way to check accesses to destroyed windows, thus
  * those cases are ignored (especially on UnmapNotify's).
@@ -160,6 +216,8 @@ main(int argc, char *argv[])
 	x_error_handler = XSetErrorHandler(error_handler);
 
 	/* init atoms */
+	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
+	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
 	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
 	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
 
diff --git a/wm.h b/wm.h
index 68c30da..b9ba8f7 100644
--- a/wm.h
+++ b/wm.h
@@ -9,7 +9,10 @@
 
 #include <X11/Xutil.h>
 
+#define WM_PROTOCOL_DELWIN 1
+
 /* atoms */
+enum { WMProtocols, WMDelete, WMLast };
 enum { NetSupported, NetWMName, NetLast };
 
 /* cursor */
@@ -25,6 +28,7 @@ struct Client {
 	char name[256];
 	char tag[256];
 	unsigned int border;
+	int proto;
 	Bool fixedsize;
 	Window win;
 	Window trans;
@@ -44,18 +48,17 @@ struct Key {
 
 extern Display *dpy;
 extern Window root, barwin;
-extern Atom net_atom[NetLast];
+extern Atom wm_atom[WMLast], net_atom[NetLast];
 extern Cursor cursor[CurLast];
 extern XRectangle rect, barrect;
-extern Bool running;
-extern Bool grid;
+extern Bool running, sel_screen, grid;
 extern void (*handler[LASTEvent]) (XEvent *);
 
-extern int screen, sel_screen;
+extern int screen;
 extern char *bartext, tag[256];
 
 extern Brush brush;
-extern Client *clients;
+extern Client *clients, *stack;
 
 /* bar.c */
 extern void draw_bar();
@@ -66,8 +69,13 @@ extern void quit(char *arg);
 
 /* client.c */
 extern void manage(Window w, XWindowAttributes *wa);
-void unmanage(Client *c);
-extern Client * getclient(Window w);
+extern void unmanage(Client *c);
+extern Client *getclient(Window w);
+extern void focus(Client *c);
+extern void update_name(Client *c);
+
+/* event.c */
+extern unsigned int flush_events(long even_mask);
 
 /* key.c */
 extern void update_keys();
@@ -75,3 +83,5 @@ extern void keypress(XEvent *e);
 
 /* wm.c */
 extern int error_handler(Display *dpy, XErrorEvent *error);
+extern void send_message(Window w, Atom a, long value);
+extern int win_proto(Window w);
emory corruption' href='/akkartik/mu/commit/076continuation.cc?h=hlt&id=a3195d440d2f0e99400db78e5a4386691c94a9a0'>a3195d44 ^
03d673bb ^



53930831 ^
03d673bb ^

3b776ac3 ^

03d673bb ^
a3195d44 ^
















53de40aa ^
a3195d44 ^












53de40aa ^
a3195d44 ^































4c513685 ^

































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327