commit 5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63
parent 39ed54a468f339535f82cce2c0a79b92e74a7c09
Author: Anselm R. Garbe <arg@suckless.org>
Date: Mon, 19 Feb 2007 13:00:29 +0100
introduced tile.c, some refactoring of functions
Diffstat:
8 files changed, 150 insertions(+), 141 deletions(-)
diff --git a/Makefile b/Makefile
@@ -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 --git a/config.arg.h b/config.arg.h
@@ -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 --git a/config.default.h b/config.default.h
@@ -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 --git a/dwm.h b/dwm.h
@@ -127,11 +127,17 @@ extern void sendevent(Window w, Atom a, long value); /* send synthetic event to
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 */
extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
@@ -140,15 +146,12 @@ extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
/* 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 --git a/main.c b/main.c
@@ -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 --git a/tag.c b/tag.c
@@ -32,7 +32,7 @@ static unsigned int len = 0;
/* extern */
void
-initrregs(void) {
+compileregexps(void) {
unsigned int i;
regex_t *reg;
diff --git a/tile.c b/tile.c
@@ -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 --git a/view.c b/view.c
@@ -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();
-}