dwm-meillo

changeset 178:e848966a1ac6

removed TLast tag enum, now tags is simple defined as char *[] array, the rest is calculated correctly, rules take an int array for the tags
author arg@10ksloc.org
date Thu, 03 Aug 2006 12:12:26 +0200
parents e890cee887d1
children 621222b67c3b
files client.c config.arg.h config.default.h draw.c dwm.h event.c main.c tag.c
diffstat 8 files changed, 66 insertions(+), 71 deletions(-) [+]
line diff
     1.1 --- a/client.c	Thu Aug 03 11:38:26 2006 +0200
     1.2 +++ b/client.c	Thu Aug 03 12:12:26 2006 +0200
     1.3 @@ -16,7 +16,7 @@
     1.4  	int i;
     1.5  
     1.6  	c->tw = 0;
     1.7 -	for(i = 0; i < TLast; i++)
     1.8 +	for(i = 0; i < ntags; i++)
     1.9  		if(c->tags[i])
    1.10  			c->tw += textw(tags[i]);
    1.11  	c->tw += textw(c->name);
    1.12 @@ -211,6 +211,7 @@
    1.13  	XSetWindowAttributes twa;
    1.14  
    1.15  	c = emallocz(sizeof(Client));
    1.16 +	c->tags = emallocz(ntags * sizeof(Bool));
    1.17  	c->win = w;
    1.18  	c->x = c->tx = wa->x;
    1.19  	c->y = c->ty = wa->y;
    1.20 @@ -429,6 +430,7 @@
    1.21  		if(!sel)
    1.22  			sel = clients;
    1.23  	}
    1.24 +	free(c->tags);
    1.25  	free(c);
    1.26  
    1.27  	XSync(dpy, False);
     2.1 --- a/config.arg.h	Thu Aug 03 11:38:26 2006 +0200
     2.2 +++ b/config.arg.h	Thu Aug 03 12:12:26 2006 +0200
     2.3 @@ -3,18 +3,11 @@
     2.4   * See LICENSE file for license details.
     2.5   */
     2.6  
     2.7 -enum { Tfnord, Tdev, Tnet, Twork, Tmisc, TLast };
     2.8  #define TAGS \
     2.9 -const char *tags[TLast] = { \
    2.10 -	[Tfnord] = "fnord", \
    2.11 -	[Tdev] = "dev", \
    2.12 -	[Tnet] = "net", \
    2.13 -	[Twork] = "work", \
    2.14 -	[Tmisc] = "misc", \
    2.15 -};
    2.16 +const char *tags[] = { "fnord", "dev", "net", "work", "misc", NULL };
    2.17  
    2.18  #define DEFMODE			dotile /* dofloat */
    2.19 -#define DEFTAG			Tdev
    2.20 +#define DEFTAG			1 /* index */
    2.21  #define FONT			"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
    2.22  #define BGCOLOR			"#0a2c2d"
    2.23  #define FGCOLOR			"#ddeeee"
    2.24 @@ -33,11 +26,11 @@
    2.25  	const char *xlock[] = { "xlock", NULL }; \
    2.26  static Key key[] = { \
    2.27  	/* modifier		key		function	arguments */ \
    2.28 -	{ MODKEY,		XK_0,		view,		{ .i = Tfnord } }, \
    2.29 -	{ MODKEY,		XK_1,		view,		{ .i = Tdev } }, \
    2.30 -	{ MODKEY,		XK_2,		view,		{ .i = Tnet } }, \
    2.31 -	{ MODKEY,		XK_3,		view,		{ .i = Twork } }, \
    2.32 -	{ MODKEY,		XK_4,		view,		{ .i = Tmisc} }, \
    2.33 +	{ MODKEY,		XK_0,		view,		{ .i = 0 } }, \
    2.34 +	{ MODKEY,		XK_1,		view,		{ .i = 1 } }, \
    2.35 +	{ MODKEY,		XK_2,		view,		{ .i = 2 } }, \
    2.36 +	{ MODKEY,		XK_3,		view,		{ .i = 3 } }, \
    2.37 +	{ MODKEY,		XK_4,		view,		{ .i = 4 } }, \
    2.38  	{ MODKEY,		XK_h,		viewprev,	{ 0 } }, \
    2.39  	{ MODKEY,		XK_j,		focusnext,	{ 0 } }, \
    2.40  	{ MODKEY,		XK_k,		focusprev,	{ 0 } }, \
    2.41 @@ -45,16 +38,16 @@
    2.42  	{ MODKEY,		XK_m,		togglemax,	{ 0 } }, \
    2.43  	{ MODKEY,		XK_space,	togglemode,	{ 0 } }, \
    2.44  	{ MODKEY,		XK_Return,	zoom,		{ 0 } }, \
    2.45 -	{ MODKEY|ControlMask,	XK_0,		appendtag,	{ .i = Tfnord } }, \
    2.46 -	{ MODKEY|ControlMask,	XK_1,		appendtag,	{ .i = Tdev } }, \
    2.47 -	{ MODKEY|ControlMask,	XK_2,		appendtag,	{ .i = Tnet } }, \
    2.48 -	{ MODKEY|ControlMask,	XK_3,		appendtag,	{ .i = Twork } }, \
    2.49 -	{ MODKEY|ControlMask,	XK_4,		appendtag,	{ .i = Tmisc } }, \
    2.50 -	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = Tfnord } }, \
    2.51 -	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = Tdev } }, \
    2.52 -	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = Tnet } }, \
    2.53 -	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = Twork } }, \
    2.54 -	{ MODKEY|ShiftMask,	XK_4,		replacetag,	{ .i = Tmisc } }, \
    2.55 +	{ MODKEY|ControlMask,	XK_0,		appendtag,	{ .i = 0 } }, \
    2.56 +	{ MODKEY|ControlMask,	XK_1,		appendtag,	{ .i = 1 } }, \
    2.57 +	{ MODKEY|ControlMask,	XK_2,		appendtag,	{ .i = 2 } }, \
    2.58 +	{ MODKEY|ControlMask,	XK_3,		appendtag,	{ .i = 3 } }, \
    2.59 +	{ MODKEY|ControlMask,	XK_4,		appendtag,	{ .i = 4 } }, \
    2.60 +	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = 0 } }, \
    2.61 +	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = 1 } }, \
    2.62 +	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = 2 } }, \
    2.63 +	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = 3 } }, \
    2.64 +	{ MODKEY|ShiftMask,	XK_4,		replacetag,	{ .i = 5 } }, \
    2.65  	{ MODKEY|ShiftMask,	XK_c,		killclient,	{ 0 } }, \
    2.66  	{ MODKEY|ShiftMask,	XK_q,		quit,		{ 0 } }, \
    2.67  	{ MODKEY|ShiftMask,	XK_Return,	spawn,		{ .argv = term } }, \
    2.68 @@ -64,10 +57,11 @@
    2.69  };
    2.70  
    2.71  #define RULES \
    2.72 +	const unsigned int firefox[] = { 2 }; \
    2.73  static Rule rule[] = { \
    2.74 -	/* class:instance	tags				isfloat */ \
    2.75 -	{ "Firefox.*",		{ [Tnet] = True },		False }, \
    2.76 -	{ "Gimp.*",		{ 0 },				True}, \
    2.77 -	{ "MPlayer.*",		{ 0 },				True}, \
    2.78 -	{ "Acroread.*",		{ 0 },				True}, \
    2.79 +	/* class:instance	tags		isfloat */ \
    2.80 +	{ "Firefox.*",		firefox,	False }, \
    2.81 +	{ "Gimp.*",		NULL,		True}, \
    2.82 +	{ "MPlayer.*",		NULL,		True}, \
    2.83 +	{ "Acroread.*",		NULL,		True}, \
    2.84  };
     3.1 --- a/config.default.h	Thu Aug 03 11:38:26 2006 +0200
     3.2 +++ b/config.default.h	Thu Aug 03 12:12:26 2006 +0200
     3.3 @@ -3,18 +3,11 @@
     3.4   * See LICENSE file for license details.
     3.5   */
     3.6  
     3.7 -enum { Tfnord, Tdev, Tnet, Twork, Tmisc, TLast };
     3.8  #define TAGS \
     3.9 -const char *tags[TLast] = { \
    3.10 -	[Tfnord] = "fnord", \
    3.11 -	[Tdev] = "dev", \
    3.12 -	[Tnet] = "net", \
    3.13 -	[Twork] = "work", \
    3.14 -	[Tmisc] = "misc", \
    3.15 -};
    3.16 +const char *tags[] = { "0", "1", "2", "3", "4", NULL };
    3.17  
    3.18  #define DEFMODE			dotile /* dofloat */
    3.19 -#define DEFTAG			Tdev
    3.20 +#define DEFTAG			1 /* index */
    3.21  #define FONT			"fixed"
    3.22  #define BGCOLOR			"#666699"
    3.23  #define FGCOLOR			"#eeeeee"
    3.24 @@ -27,11 +20,11 @@
    3.25  	const char *term[] = { "xterm", NULL }; \
    3.26  static Key key[] = { \
    3.27  	/* modifier		key		function	arguments */ \
    3.28 -	{ MODKEY,		XK_0,		view,		{ .i = Tfnord } }, \
    3.29 -	{ MODKEY,		XK_1,		view,		{ .i = Tdev } }, \
    3.30 -	{ MODKEY,		XK_2,		view,		{ .i = Tnet } }, \
    3.31 -	{ MODKEY,		XK_3,		view,		{ .i = Twork } }, \
    3.32 -	{ MODKEY,		XK_4,		view,		{ .i = Tmisc} }, \
    3.33 +	{ MODKEY,		XK_0,		view,		{ .i = 0 } }, \
    3.34 +	{ MODKEY,		XK_1,		view,		{ .i = 1 } }, \
    3.35 +	{ MODKEY,		XK_2,		view,		{ .i = 2 } }, \
    3.36 +	{ MODKEY,		XK_3,		view,		{ .i = 3 } }, \
    3.37 +	{ MODKEY,		XK_4,		view,		{ .i = 4 } }, \
    3.38  	{ MODKEY,		XK_h,		viewprev,	{ 0 } }, \
    3.39  	{ MODKEY,		XK_j,		focusnext,	{ 0 } }, \
    3.40  	{ MODKEY,		XK_k,		focusprev,	{ 0 } }, \
    3.41 @@ -39,24 +32,25 @@
    3.42  	{ MODKEY,		XK_m,		togglemax,	{ 0 } }, \
    3.43  	{ MODKEY,		XK_space,	togglemode,	{ 0 } }, \
    3.44  	{ MODKEY,		XK_Return,	zoom,		{ 0 } }, \
    3.45 -	{ MODKEY|ControlMask,	XK_0,		appendtag,	{ .i = Tfnord } }, \
    3.46 -	{ MODKEY|ControlMask,	XK_1,		appendtag,	{ .i = Tdev } }, \
    3.47 -	{ MODKEY|ControlMask,	XK_2,		appendtag,	{ .i = Tnet } }, \
    3.48 -	{ MODKEY|ControlMask,	XK_3,		appendtag,	{ .i = Twork } }, \
    3.49 -	{ MODKEY|ControlMask,	XK_4,		appendtag,	{ .i = Tmisc } }, \
    3.50 -	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = Tfnord } }, \
    3.51 -	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = Tdev } }, \
    3.52 -	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = Tnet } }, \
    3.53 -	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = Twork } }, \
    3.54 -	{ MODKEY|ShiftMask,	XK_4,		replacetag,	{ .i = Tmisc } }, \
    3.55 +	{ MODKEY|ControlMask,	XK_0,		appendtag,	{ .i = 0 } }, \
    3.56 +	{ MODKEY|ControlMask,	XK_1,		appendtag,	{ .i = 1 } }, \
    3.57 +	{ MODKEY|ControlMask,	XK_2,		appendtag,	{ .i = 2 } }, \
    3.58 +	{ MODKEY|ControlMask,	XK_3,		appendtag,	{ .i = 3 } }, \
    3.59 +	{ MODKEY|ControlMask,	XK_4,		appendtag,	{ .i = 4 } }, \
    3.60 +	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = 0 } }, \
    3.61 +	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = 1 } }, \
    3.62 +	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = 2 } }, \
    3.63 +	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = 3 } }, \
    3.64 +	{ MODKEY|ShiftMask,	XK_4,		replacetag,	{ .i = 4 } }, \
    3.65  	{ MODKEY|ShiftMask,	XK_c,		killclient,	{ 0 } }, \
    3.66  	{ MODKEY|ShiftMask,	XK_q,		quit,		{ 0 } }, \
    3.67  	{ MODKEY|ShiftMask,	XK_Return,	spawn,		{ .argv = term } }, \
    3.68  };
    3.69  
    3.70  #define RULES \
    3.71 +	const unsigned int firefox[] = { 2 }; \
    3.72  static Rule rule[] = { \
    3.73 -	/* class:instance	tags				isfloat */ \
    3.74 -	{ "Firefox.*",		{ [Tnet] = True },		False }, \
    3.75 -	{ "Gimp.*",		{ 0 },				True}, \
    3.76 +	/* class:instance	tags		isfloat */ \
    3.77 +	{ "Firefox.*",		firefox,	False }, \
    3.78 +	{ "Gimp.*",		NULL,		True}, \
    3.79  };
     4.1 --- a/draw.c	Thu Aug 03 11:38:26 2006 +0200
     4.2 +++ b/draw.c	Thu Aug 03 12:12:26 2006 +0200
     4.3 @@ -114,7 +114,7 @@
     4.4  	drawtext(NULL, !istile, False);
     4.5  
     4.6  	dc.w = 0;
     4.7 -	for(i = 0; i < TLast; i++) {
     4.8 +	for(i = 0; i < ntags; i++) {
     4.9  		dc.x += dc.w;
    4.10  		dc.w = textw(tags[i]);
    4.11  		if(istile)
    4.12 @@ -153,7 +153,7 @@
    4.13  	dc.x = dc.y = 0;
    4.14  
    4.15  	dc.w = 0;
    4.16 -	for(i = 0; i < TLast; i++) {
    4.17 +	for(i = 0; i < ntags; i++) {
    4.18  		if(c->tags[i]) {
    4.19  			dc.x += dc.w;
    4.20  			dc.w = textw(tags[i]);
     5.1 --- a/dwm.h	Thu Aug 03 11:38:26 2006 +0200
     5.2 +++ b/dwm.h	Thu Aug 03 12:12:26 2006 +0200
     5.3 @@ -60,16 +60,17 @@
     5.4  	unsigned int border;
     5.5  	Bool isfloat;
     5.6  	Bool ismax;
     5.7 -	Bool tags[TLast];
     5.8 +	Bool *tags;
     5.9  	Client *next;
    5.10  	Client *prev;
    5.11  	Window win;
    5.12  	Window title;
    5.13  };
    5.14  
    5.15 -extern const char *tags[TLast];
    5.16 +extern const char *tags[];
    5.17  extern char stext[1024];
    5.18  extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
    5.19 +extern unsigned int ntags;
    5.20  extern void (*handler[LASTEvent])(XEvent *);
    5.21  extern void (*arrange)(Arg *);
    5.22  extern Atom wmatom[WMLast], netatom[NetLast];
     6.1 --- a/event.c	Thu Aug 03 11:38:26 2006 +0200
     6.2 +++ b/event.c	Thu Aug 03 12:12:26 2006 +0200
     6.3 @@ -105,7 +105,7 @@
     6.4  		switch(ev->button) {
     6.5  		default:
     6.6  			x = 0;
     6.7 -			for(a.i = 0; a.i < TLast; a.i++) {
     6.8 +			for(a.i = 0; a.i < ntags; a.i++) {
     6.9  				x += textw(tags[a.i]);
    6.10  				if(ev->x < x) {
    6.11  					view(&a);
     7.1 --- a/main.c	Thu Aug 03 11:38:26 2006 +0200
     7.2 +++ b/main.c	Thu Aug 03 12:12:26 2006 +0200
     7.3 @@ -85,6 +85,7 @@
     7.4  char stext[1024];
     7.5  int tsel = DEFTAG;
     7.6  int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
     7.7 +unsigned int ntags;
     7.8  Atom wmatom[WMLast], netatom[NetLast];
     7.9  Bool running = True;
    7.10  Bool issel = True;
    7.11 @@ -210,6 +211,8 @@
    7.12  
    7.13  	grabkeys();
    7.14  
    7.15 +	for(ntags = 0; tags[ntags]; ntags++);
    7.16 +
    7.17  	/* style */
    7.18  	dc.bg = getcolor(BGCOLOR);
    7.19  	dc.fg = getcolor(FGCOLOR);
     8.1 --- a/tag.c	Thu Aug 03 11:38:26 2006 +0200
     8.2 +++ b/tag.c	Thu Aug 03 12:12:26 2006 +0200
     8.3 @@ -13,7 +13,7 @@
     8.4  
     8.5  typedef struct {
     8.6  	const char *pattern;
     8.7 -	Bool tags[TLast];
     8.8 +	const unsigned int *tags;
     8.9  	Bool isfloat;
    8.10  } Rule;
    8.11  
    8.12 @@ -145,7 +145,7 @@
    8.13  	if(!sel)
    8.14  		return;
    8.15  
    8.16 -	for(i = 0; i < TLast; i++)
    8.17 +	for(i = 0; i < ntags; i++)
    8.18  		sel->tags[i] = False;
    8.19  	appendtag(arg);
    8.20  }
    8.21 @@ -155,7 +155,7 @@
    8.22  {
    8.23  	char classinst[256];
    8.24  	static unsigned int len = sizeof(rule) / sizeof(rule[0]);
    8.25 -	unsigned int i, j;
    8.26 +	unsigned int i, j, n;
    8.27  	regex_t regex;
    8.28  	regmatch_t tmp;
    8.29  	Bool matched = False;
    8.30 @@ -168,10 +168,11 @@
    8.31  		for(i = 0; !matched && i < len; i++) {
    8.32  			if(!regcomp(&regex, rule[i].pattern, 0)) {
    8.33  				if(!regexec(&regex, classinst, 1, &tmp, 0)) {
    8.34 -					for(j = 0; j < TLast; j++) {
    8.35 -						if((c->tags[j] = rule[i].tags[j]))
    8.36 -							matched = True;
    8.37 -					}
    8.38 +					n = rule[i].tags ?
    8.39 +						sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0;
    8.40 +					matched = n != 0;
    8.41 +					for(j = 0; j < n; j++)
    8.42 +						c->tags[rule[i].tags[j]] = True;
    8.43  					c->isfloat = rule[i].isfloat;
    8.44  				}
    8.45  				regfree(&regex);
    8.46 @@ -204,13 +205,13 @@
    8.47  void
    8.48  viewnext(Arg *arg)
    8.49  {
    8.50 -	arg->i = (tsel < TLast-1) ? tsel+1 : 0;
    8.51 +	arg->i = (tsel < ntags-1) ? tsel+1 : 0;
    8.52  	view(arg);
    8.53  }
    8.54  
    8.55  void
    8.56  viewprev(Arg *arg)
    8.57  {
    8.58 -	arg->i = (tsel > 0) ? tsel-1 : TLast-1;
    8.59 +	arg->i = (tsel > 0) ? tsel-1 : ntags-1;
    8.60  	view(arg);
    8.61  }