aewl

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
parents 4c12dccc288d
children bff1012527b3
files dwm.c
diffstat 1 files changed, 34 insertions(+), 89 deletions(-) [+]
line diff
     1.1 --- a/dwm.c	Thu May 29 23:12:30 2008 +0200
     1.2 +++ b/dwm.c	Fri May 30 00:07:26 2008 +0200
     1.3 @@ -90,7 +90,7 @@
     1.4  	long flags;
     1.5  	unsigned int border;
     1.6  	Bool isfixed, isfloat, ismax;
     1.7 -	Bool *tags;
     1.8 +	Bool tag;
     1.9  	Client *next;
    1.10  	Client *prev;
    1.11  	Client *snext;
    1.12 @@ -99,13 +99,12 @@
    1.13  
    1.14  typedef struct {
    1.15  	const char *clpattern;
    1.16 -	const char *tpattern;
    1.17 +	int tag;
    1.18  	Bool isfloat;
    1.19  } Rule;
    1.20  
    1.21  typedef struct {
    1.22  	regex_t *clregex;
    1.23 -	regex_t *tregex;
    1.24  } RReg;
    1.25  
    1.26  
    1.27 @@ -132,7 +131,7 @@
    1.28  void (*handler[LASTEvent])(XEvent *);	/* event handler */
    1.29  void (*arrange)(void);			/* arrange function, indicates mode  */
    1.30  Atom wmatom[WMLast], netatom[NetLast];
    1.31 -Bool running, selscreen, *seltag;	/* seltag is array of Bool */
    1.32 +Bool running, selscreen, seltag;	/* seltag is array of Bool */
    1.33  Client *clients, *sel, *stack;		/* global client list and stack */
    1.34  Cursor cursor[CurLast];
    1.35  DC dc;					/* global draw context */
    1.36 @@ -186,11 +185,8 @@
    1.37  /* tag.c */
    1.38  void initrregs(void);			/* initialize regexps of rules defined in config.h */
    1.39  Client *getnext(Client *c);		/* returns next visible client */
    1.40 -Client *getprev(Client *c);		/* returns previous visible client */
    1.41  void settags(Client *c, Client *trans);	/* sets tags of c */
    1.42 -void tag(Arg *arg);			/* tags c with arg's index */
    1.43  void toggletag(Arg *arg);		/* toggles c tags with arg's index */
    1.44 -void viewnext(Arg *arg);    /* view next tag(s) */
    1.45  
    1.46  /* util.c */
    1.47  void *emallocz(unsigned int size);	/* allocates zero-initialized memory, exits on error */
    1.48 @@ -208,7 +204,7 @@
    1.49  void restack(void);			/* restores z layers of all clients */
    1.50  void togglefloat(Arg *arg);		/* toggles focusesd client between floating/non-floating state */
    1.51  void togglemode(Arg *arg);		/* toggles global arrange function (dotile/dofloat) */
    1.52 -void view(Arg *arg);			/* views the tag with arg's index */
    1.53 +void toggleview();			/* views the tag with arg's index */
    1.54  void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
    1.55  
    1.56  
    1.57 @@ -404,11 +400,9 @@
    1.58  
    1.59  Bool
    1.60  isvisible(Client *c) {
    1.61 -	unsigned int i;
    1.62 -
    1.63 -	for(i = 0; i < ntags; i++)
    1.64 -		if(c->tags[i] && seltag[i])
    1.65 -			return True;
    1.66 +	if((c->tag && seltag) || (!c->tag && !seltag)) {
    1.67 +		return True;
    1.68 +	}
    1.69  	return False;
    1.70  }
    1.71  
    1.72 @@ -464,13 +458,8 @@
    1.73  }
    1.74  
    1.75  void
    1.76 -view(Arg *arg) {
    1.77 -	unsigned int i;
    1.78 -
    1.79 -	for(i = 0; i < ntags; i++)
    1.80 -		seltag[i] = (arg->i == -1) ? True : False;
    1.81 -	if(arg->i >= 0 && arg->i < ntags)
    1.82 -		seltag[arg->i] = True;
    1.83 +toggleview() {
    1.84 +	seltag = !seltag;
    1.85  	arrange();
    1.86  }
    1.87  
    1.88 @@ -583,12 +572,6 @@
    1.89  	return c;
    1.90  }
    1.91  
    1.92 -Client *
    1.93 -getprev(Client *c) {
    1.94 -	for(; c && !isvisible(c); c = c->prev);
    1.95 -	return c;
    1.96 -}
    1.97 -
    1.98  void
    1.99  initrregs(void) {
   1.100  	unsigned int i;
   1.101 @@ -606,13 +589,6 @@
   1.102  			else
   1.103  				rreg[i].clregex = reg;
   1.104  		}
   1.105 -		if(rule[i].tpattern) {
   1.106 -			reg = emallocz(sizeof(regex_t));
   1.107 -			if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
   1.108 -				free(reg);
   1.109 -			else
   1.110 -				rreg[i].tregex = reg;
   1.111 -		}
   1.112  	}
   1.113  }
   1.114  
   1.115 @@ -625,10 +601,8 @@
   1.116  	XClassHint ch = { 0 };
   1.117  
   1.118  	if(matched) {
   1.119 -		for(i = 0; i < ntags; i++)
   1.120 -			c->tags[i] = trans->tags[i];
   1.121 -	}
   1.122 -	else {
   1.123 +		c->tag = trans->tag;
   1.124 +	} else {
   1.125  		XGetClassHint(dpy, c->win, &ch);
   1.126  		snprintf(prop, sizeof prop, "%s:%s:%s",
   1.127  				ch.res_class ? ch.res_class : "",
   1.128 @@ -636,12 +610,14 @@
   1.129  		for(i = 0; i < len; i++)
   1.130  			if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
   1.131  				c->isfloat = rule[i].isfloat;
   1.132 -				for(j = 0; rreg[i].tregex && j < ntags; j++) {
   1.133 -					if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
   1.134 -						matched = True;
   1.135 -						c->tags[j] = True;
   1.136 -					}
   1.137 +				if (rule[i].tag < 0) {
   1.138 +					c->tag = seltag;
   1.139 +				} else if (rule[i].tag == 0) {
   1.140 +					c->tag = True;
   1.141 +				} else {
   1.142 +					c->tag = False;
   1.143  				}
   1.144 +				matched = True;
   1.145          break;  /* perform only the first rule matching */
   1.146  			}
   1.147  		if(ch.res_class)
   1.148 @@ -649,49 +625,19 @@
   1.149  		if(ch.res_name)
   1.150  			XFree(ch.res_name);
   1.151  	}
   1.152 -	if(!matched)
   1.153 -		for(i = 0; i < ntags; i++)
   1.154 -			c->tags[i] = seltag[i];
   1.155 -}
   1.156 -
   1.157 -void
   1.158 -tag(Arg *arg) {
   1.159 -	unsigned int i;
   1.160 -
   1.161 -	if(!sel)
   1.162 -		return;
   1.163 -	for(i = 0; i < ntags; i++)
   1.164 -		sel->tags[i] = (arg->i == -1) ? True : False;
   1.165 -	if(arg->i >= 0 && arg->i < ntags)
   1.166 -		sel->tags[arg->i] = True;
   1.167 -	arrange();
   1.168 +	if(!matched) {
   1.169 +		c->tag = seltag;
   1.170 +	}
   1.171  }
   1.172  
   1.173  void
   1.174  toggletag(Arg *arg) {
   1.175 -	unsigned int i;
   1.176 -
   1.177  	if(!sel)
   1.178  		return;
   1.179 -	sel->tags[arg->i] = !sel->tags[arg->i];
   1.180 -	for(i = 0; i < ntags && !sel->tags[i]; i++);
   1.181 -	if(i == ntags)
   1.182 -		sel->tags[arg->i] = True;
   1.183 -	arrange();
   1.184 +	sel->tag = !sel->tag;
   1.185 +	toggleview();
   1.186  }
   1.187  
   1.188 -/* begin code by jukka */
   1.189 -void
   1.190 -viewnext(Arg *arg) {
   1.191 -  unsigned int i;
   1.192 -  Bool last = seltag[ntags-1];
   1.193 -
   1.194 -  for (i=ntags-1; i>0; --i)
   1.195 -    seltag[i] = seltag[i-1];
   1.196 -  seltag[0] = last;
   1.197 -  arrange();
   1.198 -}
   1.199 -/* end code by jukka */
   1.200  
   1.201  
   1.202  
   1.203 @@ -809,7 +755,7 @@
   1.204  			x += textw(tags[a.i]);
   1.205  			if(ev->x < x) {
   1.206  				if(ev->button == Button1) {
   1.207 -					view(&a);
   1.208 +					toggleview();
   1.209  				}
   1.210  				return;
   1.211  			}
   1.212 @@ -1141,7 +1087,7 @@
   1.213  	dc.x = dc.y = 0;
   1.214  	for(i = 0; i < ntags; i++) {
   1.215  		dc.w = textw(tags[i]);
   1.216 -		drawtext(tags[i], (seltag[i] ? dc.sel : dc.norm));
   1.217 +		drawtext(tags[i], ( (i == 0 && seltag || i == 1 && !seltag) ? dc.sel : dc.norm));
   1.218  		dc.x += dc.w + 1;
   1.219  	}
   1.220  	dc.w = bmw;
   1.221 @@ -1374,7 +1320,7 @@
   1.222  	Window trans;
   1.223  
   1.224  	c = emallocz(sizeof(Client));
   1.225 -	c->tags = emallocz(ntags * sizeof(Bool));
   1.226 +	c->tag = True;
   1.227  	c->win = w;
   1.228  	c->x = wa->x;
   1.229  	c->y = wa->y;
   1.230 @@ -1567,7 +1513,6 @@
   1.231  	}
   1.232  	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   1.233  	setclientstate(c, WithdrawnState);
   1.234 -	free(c->tags);
   1.235  	free(c);
   1.236  	XSync(dpy, False);
   1.237  	XSetErrorHandler(xerror);
   1.238 @@ -1616,7 +1561,6 @@
   1.239  	XFreeCursor(dpy, cursor[CurMove]);
   1.240  	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   1.241  	XSync(dpy, False);
   1.242 -	free(seltag);
   1.243  }
   1.244  
   1.245  static void
   1.246 @@ -1677,9 +1621,8 @@
   1.247  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   1.248  	grabkeys();
   1.249  	initrregs();
   1.250 -	for(ntags = 0; tags[ntags]; ntags++);
   1.251 -	seltag = emallocz(sizeof(Bool) * ntags);
   1.252 -	seltag[0] = True;
   1.253 +	ntags = 2;
   1.254 +	seltag = True;
   1.255  	/* style */
   1.256  	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
   1.257  	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
   1.258 @@ -1778,13 +1721,14 @@
   1.259  	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
   1.260  		fputs("dwm-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n", stdout);
   1.261  		exit(EXIT_SUCCESS);
   1.262 +	} else if(argc != 1) {
   1.263 +		eprint("usage: dwm [-v]\n");
   1.264  	}
   1.265 -	else if(argc != 1)
   1.266 -		eprint("usage: dwm [-v]\n");
   1.267  	setlocale(LC_CTYPE, "");
   1.268  	dpy = XOpenDisplay(0);
   1.269 -	if(!dpy)
   1.270 +	if(!dpy) {
   1.271  		eprint("dwm: cannot open display\n");
   1.272 +	}
   1.273  	xfd = ConnectionNumber(dpy);
   1.274  	screen = DefaultScreen(dpy);
   1.275  	root = RootWindow(dpy, screen);
   1.276 @@ -1793,8 +1737,9 @@
   1.277  	/* this causes an error if some other window manager is running */
   1.278  	XSelectInput(dpy, root, SubstructureRedirectMask);
   1.279  	XSync(dpy, False);
   1.280 -	if(otherwm)
   1.281 +	if(otherwm) {
   1.282  		eprint("dwm: another window manager is already running\n");
   1.283 +	}
   1.284  
   1.285  	XSync(dpy, False);
   1.286  	XSetErrorHandler(NULL);