changeset 755:cdd895c163bd

tag and seltag is now only bool removed unnecessary functions cleanups
author meillo@marmaro.de
date Fri, 30 May 2008 00:07:26 +0200 (2008-05-29)
parents 4c12dccc288d
children bff1012527b3
files dwm.c
diffstat 1 files changed, 34 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/dwm.c	Thu May 29 23:12:30 2008 +0200
+++ b/dwm.c	Fri May 30 00:07:26 2008 +0200
@@ -90,7 +90,7 @@
 	long flags;
 	unsigned int border;
 	Bool isfixed, isfloat, ismax;
-	Bool *tags;
+	Bool tag;
 	Client *next;
 	Client *prev;
 	Client *snext;
@@ -99,13 +99,12 @@
 
 typedef struct {
 	const char *clpattern;
-	const char *tpattern;
+	int tag;
 	Bool isfloat;
 } Rule;
 
 typedef struct {
 	regex_t *clregex;
-	regex_t *tregex;
 } RReg;
 
 
@@ -132,7 +131,7 @@
 void (*handler[LASTEvent])(XEvent *);	/* event handler */
 void (*arrange)(void);			/* arrange function, indicates mode  */
 Atom wmatom[WMLast], netatom[NetLast];
-Bool running, selscreen, *seltag;	/* seltag is array of Bool */
+Bool running, selscreen, seltag;	/* seltag is array of Bool */
 Client *clients, *sel, *stack;		/* global client list and stack */
 Cursor cursor[CurLast];
 DC dc;					/* global draw context */
@@ -186,11 +185,8 @@
 /* tag.c */
 void initrregs(void);			/* initialize regexps of rules defined in config.h */
 Client *getnext(Client *c);		/* returns next visible client */
-Client *getprev(Client *c);		/* returns previous visible client */
 void settags(Client *c, Client *trans);	/* sets tags of c */
-void tag(Arg *arg);			/* tags c with arg's index */
 void toggletag(Arg *arg);		/* toggles c tags with arg's index */
-void viewnext(Arg *arg);    /* view next tag(s) */
 
 /* util.c */
 void *emallocz(unsigned int size);	/* allocates zero-initialized memory, exits on error */
@@ -208,7 +204,7 @@
 void restack(void);			/* restores z layers of all clients */
 void togglefloat(Arg *arg);		/* toggles focusesd client between floating/non-floating state */
 void togglemode(Arg *arg);		/* toggles global arrange function (dotile/dofloat) */
-void view(Arg *arg);			/* views the tag with arg's index */
+void toggleview();			/* views the tag with arg's index */
 void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
 
 
@@ -404,11 +400,9 @@
 
 Bool
 isvisible(Client *c) {
-	unsigned int i;
-
-	for(i = 0; i < ntags; i++)
-		if(c->tags[i] && seltag[i])
-			return True;
+	if((c->tag && seltag) || (!c->tag && !seltag)) {
+		return True;
+	}
 	return False;
 }
 
@@ -464,13 +458,8 @@
 }
 
 void
-view(Arg *arg) {
-	unsigned int i;
-
-	for(i = 0; i < ntags; i++)
-		seltag[i] = (arg->i == -1) ? True : False;
-	if(arg->i >= 0 && arg->i < ntags)
-		seltag[arg->i] = True;
+toggleview() {
+	seltag = !seltag;
 	arrange();
 }
 
@@ -583,12 +572,6 @@
 	return c;
 }
 
-Client *
-getprev(Client *c) {
-	for(; c && !isvisible(c); c = c->prev);
-	return c;
-}
-
 void
 initrregs(void) {
 	unsigned int i;
@@ -606,13 +589,6 @@
 			else
 				rreg[i].clregex = reg;
 		}
-		if(rule[i].tpattern) {
-			reg = emallocz(sizeof(regex_t));
-			if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
-				free(reg);
-			else
-				rreg[i].tregex = reg;
-		}
 	}
 }
 
@@ -625,10 +601,8 @@
 	XClassHint ch = { 0 };
 
 	if(matched) {
-		for(i = 0; i < ntags; i++)
-			c->tags[i] = trans->tags[i];
-	}
-	else {
+		c->tag = trans->tag;
+	} else {
 		XGetClassHint(dpy, c->win, &ch);
 		snprintf(prop, sizeof prop, "%s:%s:%s",
 				ch.res_class ? ch.res_class : "",
@@ -636,12 +610,14 @@
 		for(i = 0; i < len; i++)
 			if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
 				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;
-						c->tags[j] = True;
-					}
+				if (rule[i].tag < 0) {
+					c->tag = seltag;
+				} else if (rule[i].tag == 0) {
+					c->tag = True;
+				} else {
+					c->tag = False;
 				}
+				matched = True;
         break;  /* perform only the first rule matching */
 			}
 		if(ch.res_class)
@@ -649,49 +625,19 @@
 		if(ch.res_name)
 			XFree(ch.res_name);
 	}
-	if(!matched)
-		for(i = 0; i < ntags; i++)
-			c->tags[i] = seltag[i];
-}
-
-void
-tag(Arg *arg) {
-	unsigned int i;
-
-	if(!sel)
-		return;
-	for(i = 0; i < ntags; i++)
-		sel->tags[i] = (arg->i == -1) ? True : False;
-	if(arg->i >= 0 && arg->i < ntags)
-		sel->tags[arg->i] = True;
-	arrange();
+	if(!matched) {
+		c->tag = seltag;
+	}
 }
 
 void
 toggletag(Arg *arg) {
-	unsigned int i;
-
 	if(!sel)
 		return;
-	sel->tags[arg->i] = !sel->tags[arg->i];
-	for(i = 0; i < ntags && !sel->tags[i]; i++);
-	if(i == ntags)
-		sel->tags[arg->i] = True;
-	arrange();
+	sel->tag = !sel->tag;
+	toggleview();
 }
 
-/* begin code by jukka */
-void
-viewnext(Arg *arg) {
-  unsigned int i;
-  Bool last = seltag[ntags-1];
-
-  for (i=ntags-1; i>0; --i)
-    seltag[i] = seltag[i-1];
-  seltag[0] = last;
-  arrange();
-}
-/* end code by jukka */
 
 
 
@@ -809,7 +755,7 @@
 			x += textw(tags[a.i]);
 			if(ev->x < x) {
 				if(ev->button == Button1) {
-					view(&a);
+					toggleview();
 				}
 				return;
 			}
@@ -1141,7 +1087,7 @@
 	dc.x = dc.y = 0;
 	for(i = 0; i < ntags; i++) {
 		dc.w = textw(tags[i]);
-		drawtext(tags[i], (seltag[i] ? dc.sel : dc.norm));
+		drawtext(tags[i], ( (i == 0 && seltag || i == 1 && !seltag) ? dc.sel : dc.norm));
 		dc.x += dc.w + 1;
 	}
 	dc.w = bmw;
@@ -1374,7 +1320,7 @@
 	Window trans;
 
 	c = emallocz(sizeof(Client));
-	c->tags = emallocz(ntags * sizeof(Bool));
+	c->tag = True;
 	c->win = w;
 	c->x = wa->x;
 	c->y = wa->y;
@@ -1567,7 +1513,6 @@
 	}
 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
 	setclientstate(c, WithdrawnState);
-	free(c->tags);
 	free(c);
 	XSync(dpy, False);
 	XSetErrorHandler(xerror);
@@ -1616,7 +1561,6 @@
 	XFreeCursor(dpy, cursor[CurMove]);
 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
 	XSync(dpy, False);
-	free(seltag);
 }
 
 static void
@@ -1677,9 +1621,8 @@
 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
 	grabkeys();
 	initrregs();
-	for(ntags = 0; tags[ntags]; ntags++);
-	seltag = emallocz(sizeof(Bool) * ntags);
-	seltag[0] = True;
+	ntags = 2;
+	seltag = True;
 	/* style */
 	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
 	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
@@ -1778,13 +1721,14 @@
 	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
 		fputs("dwm-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n", stdout);
 		exit(EXIT_SUCCESS);
+	} else if(argc != 1) {
+		eprint("usage: dwm [-v]\n");
 	}
-	else if(argc != 1)
-		eprint("usage: dwm [-v]\n");
 	setlocale(LC_CTYPE, "");
 	dpy = XOpenDisplay(0);
-	if(!dpy)
+	if(!dpy) {
 		eprint("dwm: cannot open display\n");
+	}
 	xfd = ConnectionNumber(dpy);
 	screen = DefaultScreen(dpy);
 	root = RootWindow(dpy, screen);
@@ -1793,8 +1737,9 @@
 	/* this causes an error if some other window manager is running */
 	XSelectInput(dpy, root, SubstructureRedirectMask);
 	XSync(dpy, False);
-	if(otherwm)
+	if(otherwm) {
 		eprint("dwm: another window manager is already running\n");
+	}
 
 	XSync(dpy, False);
 	XSetErrorHandler(NULL);