Hi!

I played a little bit with the source code of dwm. Finally I removed
the whole dofloat/dotile bloat and replaced it by a version which only
uses c->isfloat. It saves about 400 lines without removing any
functionality.

Enno Boland

--
http://www.gnuffy.org - Real Community Distro
http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
diff -up dwm-3.3/client.c dwm-3.3-nodofloat/client.c
--- dwm-3.3/client.c	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/client.c	2007-02-03 17:58:59.000000000 +0100
@@ -7,7 +7,7 @@
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
-/* static functions */
+/* static */
 
 static void
 detachstack(Client *c) {
@@ -65,7 +65,9 @@ xerrordummy(Display *dsply, XErrorEvent 
 	return 0;
 }
 
-/* extern functions */
+/* extern */
+
+Bool dofloat;
 
 void
 configure(Client *c) {
@@ -166,6 +168,7 @@ manage(Window w, XWindowAttributes *wa) 
 	grabbuttons(c, False);
 	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
 	updatetitle(c);
+	c->isfloat = dofloat;
 	settags(c, getclient(trans));
 	if(!c->isfloat)
 		c->isfloat = trans || c->isfixed;
Only in dwm-3.3-nodofloat: client.o
Only in dwm-3.3-nodofloat: config.h
diff -up dwm-3.3/draw.c dwm-3.3-nodofloat/draw.c
--- dwm-3.3/draw.c	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/draw.c	2007-02-03 17:58:38.000000000 +0100
@@ -97,6 +97,8 @@ drawtext(const char *text, unsigned long
 
 /* extern */
 
+Bool doloat;
+
 void
 drawstatus(void) {
 	int i, x;
@@ -111,7 +113,7 @@ drawstatus(void) {
 		dc.x += dc.w;
 	}
 	dc.w = bmw;
-	drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, False);
+	drawtext(dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, False);
 	x = dc.x + dc.w;
 	dc.w = textw(stext);
 	dc.x = sw - dc.w;
Only in dwm-3.3-nodofloat: draw.o
Only in dwm-3.3-nodofloat: dwm
diff -up dwm-3.3/dwm.h dwm-3.3-nodofloat/dwm.h
--- dwm-3.3/dwm.h	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/dwm.h	2007-02-03 17:59:32.000000000 +0100
@@ -75,7 +75,7 @@ struct Client {
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
 	long flags; 
 	unsigned int border;
-	Bool isfloat, isfixed, ismax;
+	Bool deffloat, isfloat, isfixed, ismax;
 	Bool *tags;
 	Client *next;
 	Client *prev;
@@ -91,7 +91,7 @@ extern int wax, way, wah, waw;			/* wind
 extern unsigned int master, nmaster;		/* master percent, number of master clients */
 extern unsigned int ntags, numlockmask;		/* number of tags, dynamic lock mask */
 extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
-extern void (*arrange)(void);			/* arrange function, indicates mode  */
+extern Bool dofloat;				/* indicates mode  */
 extern Atom wmatom[WMLast], netatom[NetLast];
 extern Bool running, selscreen, *seltag;	/* seltag is array of Bool */
 extern Client *clients, *sel, *stack;		/* global client list and stack */
@@ -142,8 +142,7 @@ extern void spawn(Arg *arg);			/* forks 
 
 /* view.c */
 extern void detach(Client *c);			/* detaches c from global client list */
-extern void dofloat(void);			/* arranges all windows floating */
-extern void dotile(void);			/* arranges all windows tiled */
+extern void arrange(void);			/* arranges all windows tiled */
 extern void focusnext(Arg *arg);		/* focuses next visible client, arg is ignored  */
 extern void focusprev(Arg *arg);		/* focuses previous visible client, arg is ignored */
 extern void incnmaster(Arg *arg);		/* increments nmaster with arg's index value */
diff -up dwm-3.3/event.c dwm-3.3-nodofloat/event.c
--- dwm-3.3/event.c	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/event.c	2007-02-03 17:43:43.000000000 +0100
@@ -147,13 +147,13 @@ buttonpress(XEvent *e) {
 		focus(c);
 		if(CLEANMASK(ev->state) != MODKEY)
 			return;
-		if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) {
+		if(ev->button == Button1 && c->isfloat) {
 			restack();
 			movemouse(c);
 		}
 		else if(ev->button == Button2)
 			zoom(NULL);
-		else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) &&
+		else if(ev->button == Button3 && c->isfloat &&
 				!c->isfixed) {
 			restack();
 			resizemouse(c);
Only in dwm-3.3-nodofloat: event.o
Only in dwm-3.3-nodofloat: main.o
diff -up dwm-3.3/tag.c dwm-3.3-nodofloat/tag.c
--- dwm-3.3/tag.c	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/tag.c	2007-02-03 17:53:39.000000000 +0100
@@ -88,7 +88,7 @@ settags(Client *c, Client *trans) {
 				ch.res_name ? ch.res_name : "", c->name);
 		for(i = 0; i < len; i++)
 			if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
-				c->isfloat = rule[i].isfloat;
+				c->deffloat = c->isfloat = rule[i].isfloat;
 				for(j = 0; rreg[i].tregex && j < ntags; j++) {
 					if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
 						matched = True;
Only in dwm-3.3-nodofloat: tag.o
Only in dwm-3.3-nodofloat: util.o
diff -up dwm-3.3/view.c dwm-3.3-nodofloat/view.c
--- dwm-3.3/view.c	2007-02-01 08:22:55.000000000 +0100
+++ dwm-3.3-nodofloat/view.c	2007-02-03 18:01:11.000000000 +0100
@@ -37,7 +37,7 @@ togglemax(Client *c) {
 
 /* extern */
 
-void (*arrange)(void) = DEFMODE;
+Bool dofloat = DEFFLOAT;
 
 void
 detach(Client *c) {
@@ -51,25 +51,7 @@ detach(Client *c) {
 }
 
 void
-dofloat(void) {
-	Client *c;
-
-	for(c = clients; c; c = c->next) {
-		if(isvisible(c)) {
-			resize(c, True);
-		}
-		else
-			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-	}
-	if(!sel || !isvisible(sel)) {
-		for(c = stack; c && !isvisible(c); c = c->snext);
-		focus(c);
-	}
-	restack();
-}
-
-void
-dotile(void) {
+arrange(void) {
 	unsigned int i, n, mw, mh, tw, th;
 	Client *c;
 
@@ -149,7 +131,7 @@ focusprev(Arg *arg) {
 
 void
 incnmaster(Arg *arg) {
-	if((arrange == dofloat) || (nmaster + arg->i < 1)
+	if((nmaster + arg->i < 1)
 		|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
 		return;
 	nmaster += arg->i;
@@ -190,16 +172,14 @@ restack(void) {
 	drawstatus();
 	if(!sel)
 		return;
-	if(sel->isfloat || arrange == dofloat)
+	if(sel->isfloat)
 		XRaiseWindow(dpy, sel->win);
-	if(arrange != dofloat) {
-		if(!sel->isfloat)
-			XLowerWindow(dpy, sel->win);
-		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
-			if(c == sel)
-				continue;
-			XLowerWindow(dpy, c->win);
-		}
+	if(!sel->isfloat)
+		XLowerWindow(dpy, sel->win);
+	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
+		if(c == sel)
+			continue;
+		XLowerWindow(dpy, c->win);
 	}
 	XSync(dpy, False);
 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
@@ -207,15 +187,20 @@ restack(void) {
 
 void
 togglefloat(Arg *arg) {
-	if (!sel || arrange == dofloat)
+	if (!sel)
 		return;
-	sel->isfloat = !sel->isfloat;
+	sel->deffloat = sel->isfloat = !sel->isfloat;
 	arrange();
 }
 
 void
 togglemode(Arg *arg) {
-	arrange = (arrange == dofloat) ? dotile : dofloat;
+	Client *c;
+	dofloat = !dofloat;
+
+	for(c = clients; c != NULL; c = c->next)
+		c->isfloat = dofloat ? 1 : c->deffloat;
+
 	if(sel)
 		arrange();
 	else
@@ -251,7 +236,7 @@ zoom(Arg *arg) {
 
 	if(!sel)
 		return;
-	if(sel->isfloat || (arrange == dofloat)) {
+	if(sel->isfloat) {
 		togglemax(sel);
 		return;
 	}
Only in dwm-3.3-nodofloat: view.o

Reply via email to