about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 12:52:57 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 12:52:57 +0200
commit16c67f32d62849792c8e6d4fdec22a1896f9c279 (patch)
treecb18262f3e207d8229bf0f8833f602a7b7903b03
parent366d81e313e6dd4e9e6c61ed8dfca4b4b40ccde6 (diff)
downloaddwm-16c67f32d62849792c8e6d4fdec22a1896f9c279.tar.gz
fixed several stuff (gridwm gets better and better)
-rw-r--r--README1
-rw-r--r--client.c12
-rw-r--r--config.h4
-rw-r--r--event.c87
-rw-r--r--font.c4
-rw-r--r--key.c17
-rw-r--r--menu.c2
-rw-r--r--util.c13
-rw-r--r--wm.c50
-rw-r--r--wm.h10
10 files changed, 59 insertions, 141 deletions
diff --git a/README b/README
index c766f1b..814549e 100644
--- a/README
+++ b/README
@@ -2,6 +2,7 @@ gridwm
 ------
 
 gridwm is an automatic X11 window manager which arranges all windows in a grid.
+One goal is not to exceed 3kSLOC.
 
 
 Requirements
diff --git a/client.c b/client.c
index 1e693f7..62f4d98 100644
--- a/client.c
+++ b/client.c
@@ -51,7 +51,6 @@ create_client(Window w, XWindowAttributes *wa)
 	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 @@ create_client(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);
-	XAddToSaveSet(dpy, c->win);
 	update_client_name(c);
 	twa.override_redirect = 1;
 	twa.background_pixmap = ParentRelative;
@@ -87,3 +85,13 @@ manage(Client *c)
 	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;
+}
diff --git a/config.h b/config.h
index d37034d..2f73716 100644
--- a/config.h
+++ b/config.h
@@ -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},
+
diff --git a/event.c b/event.c
index b31c94f..909012d 100644
--- a/event.c
+++ b/event.c
@@ -16,7 +16,6 @@ static void destroynotify(XEvent *e);
 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 @@ flush_masked_events(long even_mask)
 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 @@ expose(XEvent *e)
 }
 
 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 @@ maprequest(XEvent *e)
 	}
 
 	/*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
diff --git a/font.c b/font.c
index 99301b5..a6b8225 100644
--- a/font.c
+++ b/font.c
@@ -38,7 +38,7 @@ loadfont(Blitz *blitz, BlitzFont *font)
 	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 @@ loadfont(Blitz *blitz, BlitzFont *font)
 			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;
diff --git a/key.c b/key.c
index a8742da..b5d46c6 100644
--- a/key.c
+++ b/key.c
@@ -24,3 +24,20 @@ update_keys()
 		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;
+		}
+}
diff --git a/menu.c b/menu.c
index 6d8843e..ff0ffc1 100644
--- a/menu.c
+++ b/menu.c
@@ -358,8 +358,6 @@ main(int argc, char *argv[])
 
 	char buf[256];
 
-	fputs(STATUSCMD, stdout);
-	fputs("\n", stdout);
 	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
 	fputs(buf, stderr);
 
diff --git a/util.c b/util.c
index de4df98..c0f2489 100644
--- a/util.c
+++ b/util.c
@@ -93,11 +93,12 @@ spawn(Display *dpy, const char *cmd)
 		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 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
 	}
 
 	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 {
diff --git a/wm.c b/wm.c
index 038e6b9..8c5814f 100644
--- a/wm.c
+++ b/wm.c
@@ -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 @@ 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 == 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 @@ main(int argc, char *argv[])
 	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 @@ main(int argc, char *argv[])
 	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);
 
diff --git a/wm.h b/wm.h
index 454f7bf..9ea74fe 100644
--- a/wm.h
+++ b/wm.h
@@ -10,7 +10,6 @@
 #include <X11/Xutil.h>
 
 /* atoms */
-enum { WMState, WMProtocols, WMDelete, WMLast };
 enum { NetSupported, NetWMName, NetLast };
 
 /* cursor */
@@ -25,7 +24,6 @@ typedef struct Key Key;
 struct Client {
 	char name[256];
 	char tag[256];
-	int proto;
 	unsigned int border;
 	Bool fixedsize;
 	Window win;
@@ -46,7 +44,7 @@ struct Key {
 
 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 int screen, sel_screen;
 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);