[hackers] [dwm] introduced tile.c, some refactoring of functions

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Mon Feb 19 13:02:49 2007

changeset: 769:dc60583894e0
tag: tip
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Mon Feb 19 13:00:29 2007 +0100
summary: introduced tile.c, some refactoring of functions

diff -r b1dbe65d3e84 -r dc60583894e0 Makefile
--- a/Makefile Mon Feb 19 11:34:12 2007 +0100
+++ b/Makefile Mon Feb 19 13:00:29 2007 +0100
@@ -3,7 +3,7 @@
 
 include config.mk
 
-SRC = client.c draw.c event.c main.c tag.c util.c view.c
+SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c
 OBJ = ${SRC:.c=.o}
 
 all: options dwm
diff -r b1dbe65d3e84 -r dc60583894e0 config.arg.h
--- a/config.arg.h Mon Feb 19 11:34:12 2007 +0100
+++ b/config.arg.h Mon Feb 19 13:00:29 2007 +0100
@@ -5,11 +5,11 @@
 #define TAGS \
 const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
 
-#define BORDERPX 1
 #define DEFMODE dotile /* dofloat */
 #define FLOATSYMBOL "><>"
 #define TILESYMBOL "[]="
 
+#define BORDERPX 1
 #define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
 #define NORMBORDERCOLOR "#333"
 #define NORMBGCOLOR "#222"
diff -r b1dbe65d3e84 -r dc60583894e0 config.default.h
--- a/config.default.h Mon Feb 19 11:34:12 2007 +0100
+++ b/config.default.h Mon Feb 19 13:00:29 2007 +0100
@@ -5,11 +5,11 @@
 #define TAGS \
 const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
 
-#define BORDERPX 1
 #define DEFMODE dotile /* dofloat */
 #define FLOATSYMBOL "><>"
 #define TILESYMBOL "[]="
 
+#define BORDERPX 1
 #define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
 #define NORMBORDERCOLOR "#dddddd"
 #define NORMBGCOLOR "#eeeeee"
diff -r b1dbe65d3e84 -r dc60583894e0 dwm.h
--- a/dwm.h Mon Feb 19 11:34:12 2007 +0100
+++ b/dwm.h Mon Feb 19 13:00:29 2007 +0100
@@ -127,10 +127,16 @@ extern int xerror(Display *dsply, XError
 extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
 
 /* tag.c */
-extern void initrregs(void); /* initialize regexps of rules defined in config.h */
+extern void compileregexps(void); /* initialize regexps of rules defined in config.h */
 extern void settags(Client *c, Client *trans); /* sets tags of c */
 extern void tag(Arg *arg); /* tags c with arg's index */
 extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
+
+/* tile.c */
+extern void dotile(void); /* arranges all windows tiled */
+extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
+extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
+extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
 
 /* util.c */
 extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
@@ -140,15 +146,12 @@ 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 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 */
 extern Bool isvisible(Client *c); /* returns True if client is visible */
-extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
+extern Client *nextmanaged(Client *c); /* returns managed successor of c */
 extern void restack(void); /* restores z layers of all clients */
 extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */
 extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */
 extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
 extern void view(Arg *arg); /* views the tag with arg's index */
-extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
diff -r b1dbe65d3e84 -r dc60583894e0 main.c
--- a/main.c Mon Feb 19 11:34:12 2007 +0100
+++ b/main.c Mon Feb 19 13:00:29 2007 +0100
@@ -117,7 +117,7 @@ setup(void) {
         wa.cursor = cursor[CurNormal];
         XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
         grabkeys();
- initrregs();
+ compileregexps();
         for(ntags = 0; tags[ntags]; ntags++);
         seltag = emallocz(sizeof(Bool) * ntags);
         seltag[0] = True;
diff -r b1dbe65d3e84 -r dc60583894e0 tag.c
--- a/tag.c Mon Feb 19 11:34:12 2007 +0100
+++ b/tag.c Mon Feb 19 13:00:29 2007 +0100
@@ -32,7 +32,7 @@ static unsigned int len = 0;
 /* extern */
 
 void
-initrregs(void) {
+compileregexps(void) {
         unsigned int i;
         regex_t *reg;
 
diff -r b1dbe65d3e84 -r dc60583894e0 tile.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tile.c Mon Feb 19 13:00:29 2007 +0100
@@ -0,0 +1,132 @@
+/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+#include "dwm.h"
+
+/* static */
+
+static void
+togglemax(Client *c) {
+ XEvent ev;
+
+ if(c->isfixed)
+ return;
+
+ if((c->ismax = !c->ismax)) {
+ c->rx = c->x;
+ c->ry = c->y;
+ c->rw = c->w;
+ c->rh = c->h;
+ resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
+ }
+ else
+ resize(c, c->rx, c->ry, c->rw, c->rh, True);
+ while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
+/* extern */
+
+void
+dotile(void) {
+ unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
+ Client *c;
+
+ for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+ n++;
+ /* window geoms */
+ mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
+ mw = (n > nmaster) ? (waw * master) / 1000 : waw;
+ th = (n > nmaster) ? wah / (n - nmaster) : 0;
+ tw = waw - mw;
+
+ for(i = 0, c = clients; c; c = c->next)
+ if(isvisible(c)) {
+ if(c->isbanned)
+ XMoveWindow(dpy, c->win, c->x, c->y);
+ c->isbanned = False;
+ if(c->isfloat)
+ continue;
+ c->ismax = False;
+ nx = wax;
+ ny = way;
+ if(i < nmaster) {
+ ny += i * mh;
+ nw = mw - 2 * BORDERPX;
+ nh = mh - 2 * BORDERPX;
+ }
+ else { /* tile window */
+ nx += mw;
+ nw = tw - 2 * BORDERPX;
+ if(th > 2 * BORDERPX) {
+ ny += (i - nmaster) * th;
+ nh = th - 2 * BORDERPX;
+ }
+ else /* fallback if th <= 2 * BORDERPX */
+ nh = wah - 2 * BORDERPX;
+ }
+ resize(c, nx, ny, nw, nh, False);
+ i++;
+ }
+ else {
+ c->isbanned = True;
+ 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
+incnmaster(Arg *arg) {
+ if((arrange == dofloat) || (nmaster + arg->i < 1)
+ || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
+ return;
+ nmaster += arg->i;
+ if(sel)
+ arrange();
+ else
+ drawstatus();
+}
+
+void
+resizemaster(Arg *arg) {
+ if(arrange != dotile)
+ return;
+ if(arg->i == 0)
+ master = MASTER;
+ else {
+ if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
+ || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
+ return;
+ master += arg->i;
+ }
+ arrange();
+}
+
+void
+zoom(Arg *arg) {
+ unsigned int n;
+ Client *c;
+
+ if(!sel)
+ return;
+ if(sel->isfloat || (arrange == dofloat)) {
+ togglemax(sel);
+ return;
+ }
+ for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+ n++;
+
+ if((c = sel) == nextmanaged(clients))
+ if(!(c = nextmanaged(c->next)))
+ return;
+ detach(c);
+ if(clients)
+ clients->prev = c;
+ c->next = clients;
+ clients = c;
+ focus(c);
+ arrange();
+}
diff -r b1dbe65d3e84 -r dc60583894e0 view.c
--- a/view.c Mon Feb 19 11:34:12 2007 +0100
+++ b/view.c Mon Feb 19 13:00:29 2007 +0100
@@ -2,34 +2,6 @@
  * See LICENSE file for license details.
  */
 #include "dwm.h"
-#include <stdio.h>
-
-/* static */
-
-static Client *
-nexttiled(Client *c) {
- for(; c && (c->isfloat || !isvisible(c)); c = c->next);
- return c;
-}
-
-static void
-togglemax(Client *c) {
- XEvent ev;
-
- if(c->isfixed)
- return;
-
- if((c->ismax = !c->ismax)) {
- c->rx = c->x;
- c->ry = c->y;
- c->rw = c->w;
- c->rh = c->h;
- resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
- }
- else
- resize(c, c->rx, c->ry, c->rw, c->rh, True);
- while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
-}
 
 /* extern */
 
@@ -70,58 +42,6 @@ dofloat(void) {
 }
 
 void
-dotile(void) {
- unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
- Client *c;
-
- for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
- n++;
- /* window geoms */
- mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
- mw = (n > nmaster) ? (waw * master) / 1000 : waw;
- th = (n > nmaster) ? wah / (n - nmaster) : 0;
- tw = waw - mw;
-
- for(i = 0, c = clients; c; c = c->next)
- if(isvisible(c)) {
- if(c->isbanned)
- XMoveWindow(dpy, c->win, c->x, c->y);
- c->isbanned = False;
- if(c->isfloat)
- continue;
- c->ismax = False;
- nx = wax;
- ny = way;
- if(i < nmaster) {
- ny += i * mh;
- nw = mw - 2 * BORDERPX;
- nh = mh - 2 * BORDERPX;
- }
- else { /* tile window */
- nx += mw;
- nw = tw - 2 * BORDERPX;
- if(th > 2 * BORDERPX) {
- ny += (i - nmaster) * th;
- nh = th - 2 * BORDERPX;
- }
- else /* fallback if th <= 2 * BORDERPX */
- nh = wah - 2 * BORDERPX;
- }
- resize(c, nx, ny, nw, nh, False);
- i++;
- }
- else {
- c->isbanned = True;
- 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
 focusnext(Arg *arg) {
         Client *c;
    
@@ -153,18 +73,6 @@ focusprev(Arg *arg) {
         }
 }
 
-void
-incnmaster(Arg *arg) {
- if((arrange == dofloat) || (nmaster + arg->i < 1)
- || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
- return;
- nmaster += arg->i;
- if(sel)
- arrange();
- else
- drawstatus();
-}
-
 Bool
 isvisible(Client *c) {
         unsigned int i;
@@ -175,19 +83,10 @@ isvisible(Client *c) {
         return False;
 }
 
-void
-resizemaster(Arg *arg) {
- if(arrange != dotile)
- return;
- if(arg->i == 0)
- master = MASTER;
- else {
- if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
- || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
- return;
- master += arg->i;
- }
- arrange();
+Client *
+nextmanaged(Client *c) {
+ for(; c && (c->isfloat || !isvisible(c)); c = c->next);
+ return c;
 }
 
 void
@@ -203,7 +102,7 @@ restack(void) {
         if(arrange != dofloat) {
                 if(!sel->isfloat)
                         XLowerWindow(dpy, sel->win);
- for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
+ for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
                         if(c == sel)
                                 continue;
                         XLowerWindow(dpy, c->win);
@@ -252,28 +151,3 @@ view(Arg *arg) {
         arrange();
 }
 
-void
-zoom(Arg *arg) {
- unsigned int n;
- Client *c;
-
- if(!sel)
- return;
- if(sel->isfloat || (arrange == dofloat)) {
- togglemax(sel);
- return;
- }
- for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
- n++;
-
- if((c = sel) == nexttiled(clients))
- if(!(c = nexttiled(c->next)))
- return;
- detach(c);
- if(clients)
- clients->prev = c;
- c->next = clients;
- clients = c;
- focus(c);
- arrange();
-}
Received on Mon Feb 19 2007 - 13:02:49 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:27 UTC