fixed several stuff (gridwm gets better and better)
authorAnselm R. Garbe <garbeam@wmii.de>
Tue, 11 Jul 2006 12:52:57 +0200
changeset 9 d567f430a81d
parent 8 7066ff2fe8bc
child 10 703255003abb
fixed several stuff (gridwm gets better and better)
README
client.c
config.h
event.c
font.c
key.c
menu.c
util.c
wm.c
wm.h
--- a/README	Tue Jul 11 11:50:18 2006 +0200
+++ b/README	Tue Jul 11 12:52:57 2006 +0200
@@ -2,6 +2,7 @@
 ------
 
 gridwm is an automatic X11 window manager which arranges all windows in a grid.
+One goal is not to exceed 3kSLOC.
 
 
 Requirements
--- a/client.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/client.c	Tue Jul 11 12:52:57 2006 +0200
@@ -51,7 +51,6 @@
 	c->r[RFloat].height = wa->height;
 	c->border = wa->border_width;
 	XSetWindowBorderWidth(dpy, c->win, 0);
-	c->proto = win_proto(c->win);
 	XGetTransientForHint(dpy, c->win, &c->trans);
 	if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
 		c->size.flags = PSize;
@@ -59,7 +58,6 @@
 		(c->size.flags & PMinSize && c->size.flags & PMaxSize
 		 && c->size.min_width == c->size.max_width
 		 && c->size.min_height == c->size.max_height);
-	XAddToSaveSet(dpy, c->win);
 	update_client_name(c);
 	twa.override_redirect = 1;
 	twa.background_pixmap = ParentRelative;
@@ -87,3 +85,13 @@
 	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
 	XFlush(dpy);
 }
+
+Client *
+getclient(Window w)
+{
+	Client *c;
+	for(c = clients; c; c = c->next)
+		if(c->win == w)
+			return c;
+	return NULL;
+}
--- a/config.h	Tue Jul 11 11:50:18 2006 +0200
+++ b/config.h	Tue Jul 11 12:52:57 2006 +0200
@@ -10,4 +10,6 @@
 #define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
 					" `acpi | awk '{print $4}' | sed 's/,//'`"
 #define KEYS		\
-	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" },
+	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
+	{ Mod1Mask | ShiftMask, XK_q, quit, NULL},
+
--- a/event.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/event.c	Tue Jul 11 12:52:57 2006 +0200
@@ -16,7 +16,6 @@
 static void enternotify(XEvent *e);
 static void leavenotify(XEvent *e);
 static void expose(XEvent *e);
-static void keypress(XEvent *e);
 static void keymapnotify(XEvent *e);
 static void maprequest(XEvent *e);
 static void propertynotify(XEvent *e);
@@ -47,80 +46,36 @@
 static void
 configurerequest(XEvent *e)
 {
-#if 0
 	XConfigureRequestEvent *ev = &e->xconfigurerequest;
 	XWindowChanges wc;
-	XRectangle *frect;
 	Client *c;
 
-	c = client_of_win(ev->window);
+	c = getclient(ev->window);
 	ev->value_mask &= ~CWSibling;
 	if(c) {
-		gravitate_client(c, True);
-
 		if(ev->value_mask & CWX)
-			c->rect.x = ev->x;
+			c->r[RFloat].x = ev->x;
 		if(ev->value_mask & CWY)
-			c->rect.y = ev->y;
+			c->r[RFloat].y = ev->y;
 		if(ev->value_mask & CWWidth)
-			c->rect.width = ev->width;
+			c->r[RFloat].width = ev->width;
 		if(ev->value_mask & CWHeight)
-			c->rect.height = ev->height;
+			c->r[RFloat].height = ev->height;
 		if(ev->value_mask & CWBorderWidth)
 			c->border = ev->border_width;
-
-		gravitate_client(c, False);
-
-		if(c->frame) {
-			if(c->sel->area->floating)
-				frect=&c->sel->rect;
-			else
-				frect=&c->sel->revert;
-
-			if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
-				frect->y = wc.y = -height_of_bar();
-				frect->x = wc.x = -def.border;
-			}
-			else {
-				frect->y = wc.y = c->rect.y - height_of_bar();
-				frect->x = wc.x = c->rect.x - def.border;
-			}
-			frect->width = wc.width = c->rect.width + 2 * def.border;
-			frect->height = wc.height = c->rect.height + def.border
-				+ height_of_bar();
-			wc.border_width = 1;
-			wc.sibling = None;
-			wc.stack_mode = ev->detail;
-			if(c->sel->area->view != screen->sel)
-				wc.x += 2 * screen->rect.width;
-			if(c->sel->area->floating) {
-				XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
-				configure_client(c);
-			}
-		}
 	}
 
 	wc.x = ev->x;
 	wc.y = ev->y;
 	wc.width = ev->width;
 	wc.height = ev->height;
-
-	if(c && c->frame) {
-		wc.x = def.border;
-		wc.y = height_of_bar();
-		wc.width = c->sel->rect.width - 2 * def.border;
-		wc.height = c->sel->rect.height - def.border - height_of_bar();
-	}
-
 	wc.border_width = 0;
 	wc.sibling = None;
 	wc.stack_mode = Above;
 	ev->value_mask &= ~CWStackMode;
 	ev->value_mask |= CWBorderWidth;
 	XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
-
 	XFlush(dpy);
-#endif
 }
 
 static void
@@ -182,32 +137,6 @@
 }
 
 static void
-keypress(XEvent *e)
-{
-#if 0
-	XKeyEvent *ev = &e->xkey;
-	KeySym k = 0;
-	char buf[32];
-	int n;
-	static Frame *f;
-
-
-	ev->state &= valid_mask;
-	if((f = frame_of_win(ev->window))) {
-		buf[0] = 0;
-		n = XLookupString(ev, buf, sizeof(buf), &k, 0);
-		if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
-				|| IsPFKey(k) || IsPrivateKeypadKey(k))
-			return;
-		buf[n] = 0;
-		blitz_kpress_input(&f->tagbar, ev->state, k, buf);
-	}
-	else
-		key(root, ev->state, (KeyCode) ev->keycode);
-#endif
-}
-
-static void
 keymapnotify(XEvent *e)
 {
 #if 0
@@ -231,7 +160,11 @@
 	}
 
 	/*if(!client_of_win(ev->window))*/
-		manage(create_client(ev->window, &wa));
+		/*manage(create_client(ev->window, &wa));*/
+	XMapRaised(dpy, ev->window);
+	XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
+	XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
+	XFlush(dpy);
 }
 
 static void
--- a/font.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/font.c	Tue Jul 11 12:52:57 2006 +0200
@@ -38,7 +38,7 @@
 	font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
 	if(missing) {
 		while(n--)
-			fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
+			fprintf(stderr, "missing fontset: %s\n", missing[n]);
 		XFreeStringList(missing);
 		if(font->set) {
 			XFreeFontSet(blitz->dpy, font->set);
@@ -72,7 +72,7 @@
 			font->xfont = XLoadQueryFont(blitz->dpy, fontname);
 		}
 		if (!font->xfont) {
-			fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
+			fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
 			exit(1);
 		}
 		font->ascent = font->xfont->ascent;
--- a/key.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/key.c	Tue Jul 11 12:52:57 2006 +0200
@@ -24,3 +24,20 @@
 		XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
 	}
 }
+
+void
+keypress(XEvent *e)
+{
+	XKeyEvent *ev = &e->xkey;
+	unsigned int i, len;
+	KeySym keysym;
+
+	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
+	len = sizeof(key) / sizeof(key[0]);
+	for(i = 0; i < len; i++)
+		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
+			if(key[i].func)
+				key[i].func(key[i].arg);
+			return;
+		}
+}
--- a/menu.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/menu.c	Tue Jul 11 12:52:57 2006 +0200
@@ -358,8 +358,6 @@
 
 	char buf[256];
 
-	fputs(STATUSCMD, stdout);
-	fputs("\n", stdout);
 	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
 	fputs(buf, stderr);
 
--- a/util.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/util.c	Tue Jul 11 12:52:57 2006 +0200
@@ -93,11 +93,12 @@
 		return;
 	if(fork() == 0) {
 		if(fork() == 0) {
-			setsid();
 			if(dpy)
 				close(ConnectionNumber(dpy));
-			execlp(shell, "shell", "-c", cmd, NULL);
-			fprintf(stderr, "gridwm: execvp %s", cmd);
+			setsid();
+			fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
+			execlp(shell, shell, "-c", cmd, NULL);
+			fprintf(stderr, "gridwm: execlp %s", cmd);
 			perror(" failed");
 		}
 		exit (0);
@@ -123,14 +124,14 @@
 	}
 
 	if(fork() == 0) {
-		setsid();
 		if(dpy)
 			close(ConnectionNumber(dpy));
+		setsid();
 		dup2(pfd[1], STDOUT_FILENO);
 		close(pfd[0]);
 		close(pfd[1]);
-		execlp(shell, "shell", "-c", cmd, NULL);
-		fprintf(stderr, "gridwm: execvp %s", cmd);
+		execlp(shell, shell, "-c", cmd, NULL);
+		fprintf(stderr, "gridwm: execlp %s", cmd);
 		perror(" failed");
 	}
 	else {
--- a/wm.c	Tue Jul 11 11:50:18 2006 +0200
+++ b/wm.c	Tue Jul 11 12:52:57 2006 +0200
@@ -16,11 +16,11 @@
 /* X structs */
 Display *dpy;
 Window root, barwin;
-Atom wm_atom[WMLast], net_atom[NetLast];
+Atom net_atom[NetLast];
 Cursor cursor[CurLast];
 XRectangle rect, barrect;
 Bool running = True;
-Client *client = NULL;
+Client *clients = NULL;
 
 char *bartext, tag[256];
 int screen, sel_screen;
@@ -63,46 +63,6 @@
 		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 == NULL) {
-		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;
-}
-
 /*
  * There's no way to check accesses to destroyed windows, thus
  * those cases are ignored (especially on UnmapNotify's).
@@ -201,9 +161,6 @@
 	x_error_handler = XSetErrorHandler(error_handler);
 
 	/* init atoms */
-	wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
-	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);
 
@@ -242,7 +199,8 @@
 	XMapRaised(dpy, barwin);
 	draw_bar();
 
-	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
+	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
+					| LeaveWindowMask;
 	wa.cursor = cursor[CurNormal];
 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
 
--- a/wm.h	Tue Jul 11 11:50:18 2006 +0200
+++ b/wm.h	Tue Jul 11 12:52:57 2006 +0200
@@ -10,7 +10,6 @@
 #include <X11/Xutil.h>
 
 /* atoms */
-enum { WMState, WMProtocols, WMDelete, WMLast };
 enum { NetSupported, NetWMName, NetLast };
 
 /* cursor */
@@ -25,7 +24,6 @@
 struct Client {
 	char name[256];
 	char tag[256];
-	int proto;
 	unsigned int border;
 	Bool fixedsize;
 	Window win;
@@ -46,7 +44,7 @@
 
 extern Display *dpy;
 extern Window root, barwin;
-extern Atom wm_atom[WMLast], net_atom[NetLast];
+extern Atom net_atom[NetLast];
 extern Cursor cursor[CurLast];
 extern XRectangle rect, barrect;
 extern Bool running;
@@ -57,20 +55,22 @@
 extern char *bartext, tag[256];
 
 extern Brush brush;
-extern Client *client;
+extern Client *clients;
 
 /* bar.c */
 extern void draw_bar();
 
 /* cmd.c */
 extern void run(char *arg);
+extern void quit(char *arg);
 
 /* client.c */
 extern Client *create_client(Window w, XWindowAttributes *wa);
 extern void manage(Client *c);
+extern Client * getclient(Window w);
 
 /* key.c */
 extern void update_keys();
+extern void keypress(XEvent *e);
 
 /* wm.c */
-extern int win_proto(Window w);