new stuff
authorAnselm R. Garbe <garbeam@wmii.de>
Thu, 13 Jul 2006 19:55:07 +0200
changeset 51 035617ee18d1
parent 50 148f25ed0ad7
child 52 d18f6dd0cf23
new stuff
client.c
config.mk
dev.c
dwm.h
main.c
--- a/client.c	Thu Jul 13 18:21:38 2006 +0200
+++ b/client.c	Thu Jul 13 19:55:07 2006 +0200
@@ -3,21 +3,19 @@
  * See LICENSE file for license details.
  */
 
-#include <math.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
 #include "dwm.h"
 
-static void (*arrange)(Arg *) = floating;
+static void (*arrange)(Arg *) = tiling;
 
-static void
-center(Client *c)
-{
-	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
-}
+static Rule rule[] = {
+	{ "Firefox-bin", "Gecko", { [Twww] = "www" } },
+};
 
 static Client *
 next(Client *c)
@@ -29,18 +27,18 @@
 void
 zoom(Arg *arg)
 {
-	Client **l;
+	Client **l, *old;
 
-	if(!sel)
+	if(!(old = sel))
 		return;
 
 	for(l = &clients; *l && *l != sel; l = &(*l)->next);
 	*l = sel->next;
 
-	sel->next = clients; /* pop */
-	clients = sel;
+	old->next = clients; /* pop */
+	clients = old;
+	sel = old;
 	arrange(NULL);
-	center(sel);
 	focus(sel);
 }
 
@@ -119,39 +117,38 @@
 tiling(Arg *arg)
 {
 	Client *c;
-	int n, cols, rows, gw, gh, i, j;
-    float rt, fd;
+	int n, i, w, h;
 
+	w = sw - mw;
 	arrange = tiling;
-	for(n = 0, c = clients; c; c = next(c->next), n++);
-	if(n) {
-		rt = sqrt(n);
-		if(modff(rt, &fd) < 0.5)
-			rows = floor(rt);
-		else
-			rows = ceil(rt);
-		if(rows * rows < n)
-			cols = rows + 1;
-		else
-			cols = rows;
+	for(n = 0, c = clients; c; c = c->next)
+		if(c->tags[tsel])
+			n++;
+
+	h = (n > 2) ? sh / (n - 2) : sh;
 
-		gw = (sw - 2)  / cols;
-		gh = (sh - 2) / rows;
-	}
-	else
-		cols = rows = gw = gh = 0;
-
-	for(i = j = 0, c = clients; c; c = c->next) {
+	for(i = 0, c = clients; c; c = c->next) {
 		if(c->tags[tsel]) {
-			c->x = i * gw;
-			c->y = j * gh;
-			c->w = gw;
-			c->h = gh;
+			if(n == 1) {
+				c->x = sx;
+				c->y = sy;
+				c->w = sw;
+				c->h = sh;
+			}
+			else if(i == 1) {
+				c->x = sx;
+				c->y = sy;
+				c->w = mw;
+				c->h = sh;
+			}
+			else {
+				c->x = sx + mw;
+				c->y = sy + (i - 2) * h;
+				c->w = w;
+				c->h = h;
+			}
 			resize(c);
-			if(++i == cols) {
-				j++;
-				i = 0;
-			}
+			i++;
 		}
 		else
 			ban_client(c);
@@ -175,7 +172,6 @@
 
 	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
 		craise(c);
-		center(c);
 		focus(c);
 	}
 }
@@ -192,7 +188,6 @@
 		c = next(clients);
 	if(c) {
 		craise(c);
-		center(c);
 		c->revert = sel;
 		focus(c);
 	}
@@ -323,6 +318,43 @@
 	discard_events(EnterWindowMask);
 }
 
+static void
+init_tags(Client *c)
+{
+	XClassHint ch;
+	static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
+	unsigned int i, j;
+	Bool matched = False;
+
+	if(!len) {
+		c->tags[tsel] = tags[tsel];
+		return;
+	}
+
+	if(XGetClassHint(dpy, c->win, &ch)) {
+		if(ch.res_class && ch.res_name) {
+			fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
+			for(i = 0; i < len; i++)
+				if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
+					&& !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
+				{
+			fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
+					for(j = 0; j < TLast; j++)
+						c->tags[j] = rule[i].tags[j];
+					matched = True;
+					break;
+				}
+		}
+		if(ch.res_class)
+			XFree(ch.res_class);
+		if(ch.res_name)
+			XFree(ch.res_name);
+	}
+
+	if(!matched)
+		c->tags[tsel] = tags[tsel];
+}
+
 void
 manage(Window w, XWindowAttributes *wa)
 {
@@ -346,13 +378,13 @@
 	twa.background_pixmap = ParentRelative;
 	twa.event_mask = ExposureMask;
 
-	c->tags[tsel] = tags[tsel];
 	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
 			0, DefaultDepth(dpy, screen), CopyFromParent,
 			DefaultVisual(dpy, screen),
 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
 
 	update_name(c);
+	init_tags(c);
 
 	for(l = &clients; *l; l = &(*l)->next);
 	c->next = *l; /* *l == nil */
@@ -368,8 +400,10 @@
 	XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
 			GrabModeAsync, GrabModeSync, None, None);
 	arrange(NULL);
-	center(c);
-	focus(c);
+	if(c->tags[tsel])
+		focus(c);
+	else
+		ban_client(c);
 }
 
 void
--- a/config.mk	Thu Jul 13 18:21:38 2006 +0200
+++ b/config.mk	Thu Jul 13 19:55:07 2006 +0200
@@ -11,7 +11,7 @@
 VERSION = 0.0
 
 # includes and libs
-LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11
+LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
 
 # Linux/BSD
 CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
--- a/dev.c	Thu Jul 13 18:21:38 2006 +0200
+++ b/dev.c	Thu Jul 13 19:55:07 2006 +0200
@@ -20,8 +20,7 @@
 const char *xlock[] = { "xlock", NULL };
 
 static Key key[] = {
-	{ Mod1Mask, XK_Return, zoom, { 0 } },
-	{ Mod1Mask, XK_t, spawn, { .argv = term } },
+	{ Mod1Mask, XK_Return, spawn, { .argv = term } },
 	{ Mod1Mask, XK_w, spawn, { .argv = browse } },
 	{ Mod1Mask, XK_l, spawn, { .argv = xlock } },
 	{ Mod1Mask, XK_k, prevc, { 0 } },
@@ -33,6 +32,7 @@
 	{ Mod1Mask, XK_3, view, { .i = Twww } }, 
 	{ Mod1Mask, XK_4, view, { .i = Twork } }, 
 	{ Mod1Mask, XK_space, tiling, { 0 } }, 
+	{ Mod1Mask | ShiftMask, XK_Return, zoom, { 0 } },
 	{ Mod1Mask | ShiftMask, XK_space, floating, { 0 } }, 
 	{ Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } }, 
 	{ Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } }, 
@@ -48,10 +48,10 @@
 void
 update_keys(void)
 {
-	unsigned int i, len;
+	static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
+	unsigned int i;
 	KeyCode code;
 
-	len = sizeof(key) / sizeof(key[0]);
 	for(i = 0; i < len; i++) {
 		code = XKeysymToKeycode(dpy, key[i].keysym);
 		XUngrabKey(dpy, code, key[i].mod, root);
@@ -63,11 +63,11 @@
 keypress(XEvent *e)
 {
 	XKeyEvent *ev = &e->xkey;
-	unsigned int i, len;
+	static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
+	unsigned int i;
 	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)
--- a/dwm.h	Thu Jul 13 18:21:38 2006 +0200
+++ b/dwm.h	Thu Jul 13 19:55:07 2006 +0200
@@ -7,22 +7,24 @@
 
 /********** CUSTOMIZE **********/
 
-#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
-#define BGCOLOR		"DarkSlateGrey"
-#define FGCOLOR		"LightSteelBlue"
-#define BORDERCOLOR	"SlateGray"
-#define WM_PROTOCOL_DELWIN 1
+#define FONT				"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
+#define BGCOLOR				"#666699"
+#define FGCOLOR				"#ffffff"
+#define BORDERCOLOR			"#9999CC"
+#define MASTERW				52 /* percent */
+#define WM_PROTOCOL_DELWIN	1
 
 /* tags */
 enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
 
 /********** CUSTOMIZE **********/
 
+typedef union Arg Arg;
 typedef struct DC DC;
 typedef struct Client Client;
 typedef struct Fnt Fnt;
 typedef struct Key Key;
-typedef union Arg Arg;
+typedef struct Rule Rule;
 
 union Arg {
 	const char **argv;
@@ -71,6 +73,12 @@
 	Client *revert;
 };
 
+struct Rule {
+	const char *class;
+	const char *instance;
+	char *tags[TLast];
+};
+
 struct Key {
 	unsigned long mod;
 	KeySym keysym;
@@ -85,8 +93,8 @@
 extern Bool running, issel;
 extern void (*handler[LASTEvent]) (XEvent *);
 
-extern int tsel, screen, sx, sy, sw, sh, th;
-extern char stext[1024], *tags[TLast];
+extern int tsel, screen, sx, sy, sw, sh, mw, th;
+extern char *tags[TLast];
 
 extern DC dc;
 extern Client *clients, *sel;
--- a/main.c	Thu Jul 13 18:21:38 2006 +0200
+++ b/main.c	Thu Jul 13 19:55:07 2006 +0200
@@ -33,9 +33,8 @@
 Bool running = True;
 Bool issel;
 
-char stext[1024];
 int tsel = Tdev; /* default tag */
-int screen, sx, sy, sw, sh, th;
+int screen, sx, sy, sw, sh, mw, th;
 
 DC dc = {0};
 Client *clients = NULL;
@@ -223,6 +222,7 @@
 	sx = sy = 0;
 	sw = DisplayWidth(dpy, screen);
 	sh = DisplayHeight(dpy, screen);
+	mw = (sw * MASTERW) / 100;
 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
 
 	XSetErrorHandler(0);