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);
"nv"># Many functions here may not be usable yet because of missing features # (global variable support, etc.) sig check-ints-equal a: int, b: int, msg: (addr array byte) sig kernel-string-equal? s: (addr kernel-string), benchmark: (addr array byte) -> result/eax: boolean sig new-segment len: int, ad: (addr allocation-descriptor) sig string-equal? s: (addr array byte), benchmark: (addr array byte) -> result/eax: boolean sig string-starts-with? s: (addr array byte), benchmark: (addr array byte) -> result/eax: boolean sig check-strings-equal s: (addr array byte), expected: (addr array byte), msg: (addr array byte) sig clear-stream f: (addr stream _) sig rewind-stream f: (addr stream _) sig initialize-trace-stream n: int sig trace line: (addr array byte) sig check-trace-contains line: (addr string), msg: (addr string) sig check-trace-scans-to line: (addr string), msg: (addr string) sig trace-scan line: (addr array byte) -> result/eax: boolean sig next-line-matches? t: (addr stream byte), line: (addr array byte) -> result/eax: boolean sig skip-next-line t: (addr stream byte) sig clear-trace-stream sig write f: (addr stream byte), s: (addr array byte) # writing to file descriptor not supported; use buffered-file sig stream-data-equal? f: (addr stream byte), s: (addr array byte) -> result/eax: boolean sig check-stream-equal f: (addr stream byte), s: (addr array byte), msg: (addr array byte) sig next-stream-line-equal? f: (addr stream byte), s: (addr array byte) -> result/eax: boolean sig check-next-stream-line-equal f: (addr stream byte), s: (addr array byte), msg: (addr array byte) sig tailor-exit-descriptor ed: (addr exit-descriptor), nbytes: int sig stop ed: (addr exit-descriptor), value: int #sig read f: fd or (addr stream byte), s: (addr stream byte) -> num-bytes-read/eax: int sig read-byte-buffered f: (addr buffered-file) -> byte-or-Eof/eax: byte sig read-byte s: (addr stream byte) -> result/eax: byte #sig write-stream f: fd or (addr stream byte), s: (addr stream byte) #sig error ed: (addr exit-descriptor), out: fd or (addr stream byte), msg: (addr array byte) sig write-byte-buffered f: (addr buffered-file), n: int sig flush f: (addr buffered-file) sig append-byte f: (addr stream byte), n: int sig write-buffered f: (addr buffered-file), msg: (addr array byte) #sig to-hex-char in/eax: int -> out/eax: int sig append-byte-hex f: (addr stream byte), n: int sig write-byte-hex-buffered f: (addr buffered-file), n: int sig write-int32-hex f: (addr stream byte), n: int sig write-int32-hex-bits f: (addr stream byte), n: int, bits: int sig write-int32-hex-buffered f: (addr buffered-file), n: int sig write-int32-hex-bits-buffered f: (addr buffered-file), n: int, bits: int sig is-hex-int? in: (addr slice) -> result/eax: boolean sig parse-hex-int in: (addr array byte) -> result/eax: int sig parse-hex-int-from-slice in: (addr slice) -> result/eax: int #sig parse-hex-int-helper start: (addr byte), end: (addr byte) -> result/eax: int sig is-hex-digit? c: byte -> result/eax: boolean #sig from-hex-char in/eax: byte -> out/eax: nibble sig parse-decimal-int in: (addr array byte) -> result/eax: int sig parse-decimal-int-from-slice in: (addr slice) -> result/eax: int sig parse-decimal-int-from-stream in: (addr stream byte) -> result/eax: int #sig parse-decimal-int-helper start: (addr byte), end: (addr byte) -> result/eax: int sig decimal-size n: int -> result/eax: int sig error-byte ed: (addr exit-descriptor), out: (addr buffered-file), msg: (addr array byte), n: byte #sig allocate ad: (addr allocation-descriptor), n: int, out: (addr handle _) #sig allocate-raw ad: (addr allocation-descriptor), n: int, out: (addr handle _) sig lookup h: (handle _T) -> result/eax: (addr _T) sig handle-equal? a: (handle _T), b: (handle _T) -> result/eax: boolean sig copy-handle src: (handle _T), dest: (addr handle _T) #sig allocate-region ad: (addr allocation-descriptor), n: int, out: (addr handle allocation-descriptor) #sig allocate-array ad: (addr allocation-descriptor), n: int, out: (addr handle _) sig copy-array ad: (addr allocation-descriptor), src: (addr array _T), out: (addr handle array _T) #sig zero-out start: (addr byte), size: int #sig new-stream ad: (addr allocation-descriptor), length: int, elemsize: int, out: (addr handle stream _) sig read-line-buffered f: (addr buffered-file), s: (addr stream byte) sig read-line f: (addr stream byte), s: (addr stream byte) sig slice-empty? s: (addr slice) -> result/eax: boolean sig slice-equal? s: (addr slice), p: (addr array byte) -> result/eax: boolean sig slice-starts-with? s: (addr slice), head: (addr array byte) -> result/eax: boolean sig write-slice out: (addr stream byte), s: (addr slice) sig write-slice-buffered out: (addr buffered-file), s: (addr slice) sig slice-to-string ad: (addr allocation-descriptor), in: (addr slice), out: (addr handle array byte) sig next-token in: (addr stream byte), delimiter: byte, out: (addr slice) sig next-token-from-slice start: (addr byte), end: (addr byte), delimiter: byte, out: (addr slice) sig skip-chars-matching in: (addr stream byte), delimiter: byte sig skip-chars-matching-whitespace in: (addr stream byte) sig skip-chars-not-matching in: (addr stream byte), delimiter: byte sig skip-chars-not-matching-whitespace in: (addr stream byte) #sig skip-chars-matching-in-slice curr: (addr byte), end: (addr byte), delimiter: byte -> curr/eax: (addr byte) #sig skip-chars-matching-whitespace-in-slice curr: (addr byte), end: (addr byte) -> curr/eax: (addr byte) #sig skip-chars-not-matching-in-slice curr: (addr byte), end: (addr byte), delimiter: byte -> curr/eax: (addr byte) #sig skip-chars-not-matching-whitespace-in-slice curr: (addr byte), end: (addr byte) -> curr/eax: (addr byte) sig skip-string line: (addr stream byte) #sig skip-string-in-slice curr: (addr byte), end: (addr byte) -> curr/eax: (addr byte) sig skip-until-close-paren line: (addr stream byte) #sig skip-until-close-paren-in-slice curr: (addr byte), end: (addr byte) -> curr/eax: (addr byte) sig write-stream-data f: (addr buffered-file), s: (addr stream byte) sig write-int32-decimal out: (addr stream byte), n: int sig is-decimal-digit? c: grapheme -> result/eax: boolean sig to-decimal-digit in: grapheme -> out/eax: int sig next-word line: (addr stream byte), out: (addr slice) sig has-metadata? word: (addr slice), s: (addr string) -> result/eax: boolean sig is-valid-name? in: (addr slice) -> result/eax: boolean sig is-label? word: (addr slice) -> result/eax: boolean sig emit-hex out: (addr buffered-file), n: int, width: int sig emit out: (addr buffered-file), word: (addr slice), width: int #sig get table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int, abort-message-prefix: (addr array byte) -> result/eax: (addr T) #sig get-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int, abort-message-prefix: (addr array byte) -> result/eax: (addr T) #sig get-or-insert table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int, ad: (addr allocation-descriptor) -> result/eax: (addr T) #sig get-or-insert-handle table: (addr stream {(handle array byte), T}), key: (handle array byte), row-size: int -> result/eax: (addr T) #sig get-or-insert-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int, ad: (addr allocation-descriptor) -> result/eax: (addr T) #sig get-or-stop table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int #sig get-slice-or-stop table: (addr stream {(handle array byte), _}), key: (addr slice), row-size: int #sig maybe-get table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int -> result/eax: (addr T) #sig maybe-get-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int -> result/eax: (addr T) sig slurp f: (addr buffered-file), s: (addr stream byte) sig compute-width word: (addr array byte) -> result/eax: int sig compute-width-of-slice s: (addr slice) -> result/eax: int sig emit-hex-array out: (addr buffered-file), arr: (addr array byte) sig next-word-or-string line: (addr stream byte), out: (addr slice) sig write-int out: (addr stream byte), n: int #sig clear-stack s: (addr stack) #sig push s: (addr stack), n: int #sig pop s: (addr stack) -> n/eax: int #sig top s: (addr stack) -> n/eax: int sig array-equal? a: (addr array int), b: (addr array int) -> result/eax: boolean sig parse-array-of-ints s: (addr array byte), out: (addr handle array int) sig check-array-equal a: (addr array int), expected: (addr string), msg: (addr string) #sig push-n-zero-bytes n: int sig kernel-string-to-string ad: (addr allocation-descriptor), in: (addr kernel-string), out: (addr handle array byte) sig kernel-string-length in: (addr kernel-string) -> result/eax: int sig enable-screen-grid-mode sig enable-screen-type-mode sig real-screen-size -> nrows/eax: int, ncols/ecx: int sig clear-real-screen sig move-cursor-on-real-screen row: int, column: int sig print-string-to-real-screen s: (addr array byte) sig print-slice-to-real-screen s: (addr slice) sig print-stream-to-real-screen s: (addr stream byte) sig print-grapheme-to-real-screen c: grapheme sig print-int32-hex-to-real-screen n: int sig print-int32-hex-bits-to-real-screen n: int, bits: int sig print-int32-decimal-to-real-screen n: int sig write-int32-decimal-buffered f: (addr buffered-file), n: int sig reset-formatting-on-real-screen sig start-color-on-real-screen fg: int, bg: int sig start-bold-on-real-screen sig start-underline-on-real-screen sig start-reverse-video-on-real-screen sig start-blinking-on-real-screen sig hide-cursor-on-real-screen sig show-cursor-on-real-screen sig enable-keyboard-immediate-mode sig enable-keyboard-type-mode sig read-key-from-real-keyboard -> result/eax: grapheme sig read-line-from-real-keyboard out: (addr stream byte) sig open filename: (addr array byte), write?: boolean, out: (addr handle buffered-file) sig populate-buffered-file-containing contents: (addr array byte), out: (addr handle buffered-file) sig new-buffered-file out: (addr handle buffered-file) #sig size in: (addr array _) -> result/eax: int sig stream-empty? s: (addr stream _) -> result/eax: boolean sig stream-full? s: (addr stream _) -> result/eax: boolean sig stream-to-array in: (addr stream _), out: (addr handle array _) sig unquote-stream-to-array in: (addr stream _), out: (addr handle array _) sig stream-first s: (addr stream byte) -> result/eax: byte sig stream-final s: (addr stream byte) -> result/eax: byte #sig copy-bytes src: (addr byte), dest: (addr byte), n: int