diff -r cdd1db1c525b config.def.h --- a/config.def.h Fri Oct 19 09:56:51 2007 +0200 +++ b/config.def.h Sat Oct 20 17:09:46 2007 +0200 @@ -13,6 +13,7 @@ /* tagging */ const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" }; +#define ntags (sizeof tags / sizeof tags[0]) Rule rules[] = { /* class:instance:title regex tags regex isfloating */ { "Firefox", "www", False }, @@ -52,43 +53,43 @@ Key keys[] = { \ { MODKEY, XK_Tab, viewprevtag, NULL }, \ { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ { MODKEY|ShiftMask, XK_c, killclient, NULL }, \ - { MODKEY, XK_0, view, NULL }, \ - { MODKEY, XK_1, view, tags[0] }, \ - { MODKEY, XK_2, view, tags[1] }, \ - { MODKEY, XK_3, view, tags[2] }, \ - { MODKEY, XK_4, view, tags[3] }, \ - { MODKEY, XK_5, view, tags[4] }, \ - { MODKEY, XK_6, view, tags[5] }, \ - { MODKEY, XK_7, view, tags[6] }, \ - { MODKEY, XK_8, view, tags[7] }, \ - { MODKEY, XK_9, view, tags[8] }, \ - { MODKEY|ControlMask, XK_1, toggleview, tags[0] }, \ - { MODKEY|ControlMask, XK_2, toggleview, tags[1] }, \ - { MODKEY|ControlMask, XK_3, toggleview, tags[2] }, \ - { MODKEY|ControlMask, XK_4, toggleview, tags[3] }, \ - { MODKEY|ControlMask, XK_5, toggleview, tags[4] }, \ - { MODKEY|ControlMask, XK_6, toggleview, tags[5] }, \ - { MODKEY|ControlMask, XK_7, toggleview, tags[6] }, \ - { MODKEY|ControlMask, XK_8, toggleview, tags[7] }, \ - { MODKEY|ControlMask, XK_9, toggleview, tags[8] }, \ - { MODKEY|ShiftMask, XK_0, tag, NULL }, \ - { MODKEY|ShiftMask, XK_1, tag, tags[0] }, \ - { MODKEY|ShiftMask, XK_2, tag, tags[1] }, \ - { MODKEY|ShiftMask, XK_3, tag, tags[2] }, \ - { MODKEY|ShiftMask, XK_4, tag, tags[3] }, \ - { MODKEY|ShiftMask, XK_5, tag, tags[4] }, \ - { MODKEY|ShiftMask, XK_6, tag, tags[5] }, \ - { MODKEY|ShiftMask, XK_7, tag, tags[6] }, \ - { MODKEY|ShiftMask, XK_8, tag, tags[7] }, \ - { MODKEY|ShiftMask, XK_9, tag, tags[8] }, \ - { MODKEY|ControlMask|ShiftMask, XK_1, toggletag, tags[0] }, \ - { MODKEY|ControlMask|ShiftMask, XK_2, toggletag, tags[1] }, \ - { MODKEY|ControlMask|ShiftMask, XK_3, toggletag, tags[2] }, \ - { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, tags[3] }, \ - { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, tags[4] }, \ - { MODKEY|ControlMask|ShiftMask, XK_6, toggletag, tags[5] }, \ - { MODKEY|ControlMask|ShiftMask, XK_7, toggletag, tags[6] }, \ - { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, tags[7] }, \ - { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, tags[8] }, \ + { MODKEY, XK_0, view, index_to_tag(ntags) }, \ + { MODKEY, XK_1, view, index_to_tag(0) }, \ + { MODKEY, XK_2, view, index_to_tag(1) }, \ + { MODKEY, XK_3, view, index_to_tag(2) }, \ + { MODKEY, XK_4, view, index_to_tag(3) }, \ + { MODKEY, XK_5, view, index_to_tag(4) }, \ + { MODKEY, XK_6, view, index_to_tag(5) }, \ + { MODKEY, XK_7, view, index_to_tag(6) }, \ + { MODKEY, XK_8, view, index_to_tag(7) }, \ + { MODKEY, XK_9, view, index_to_tag(8) }, \ + { MODKEY|ControlMask, XK_1, toggleview, index_to_tag(0) }, \ + { MODKEY|ControlMask, XK_2, toggleview, index_to_tag(1) }, \ + { MODKEY|ControlMask, XK_3, toggleview, index_to_tag(2) }, \ + { MODKEY|ControlMask, XK_4, toggleview, index_to_tag(3) }, \ + { MODKEY|ControlMask, XK_5, toggleview, index_to_tag(4) }, \ + { MODKEY|ControlMask, XK_6, toggleview, index_to_tag(5) }, \ + { MODKEY|ControlMask, XK_7, toggleview, index_to_tag(6) }, \ + { MODKEY|ControlMask, XK_8, toggleview, index_to_tag(7) }, \ + { MODKEY|ControlMask, XK_9, toggleview, index_to_tag(8) }, \ + { MODKEY|ShiftMask, XK_0, tag, index_to_tag(ntags) }, \ + { MODKEY|ShiftMask, XK_1, tag, index_to_tag(0) }, \ + { MODKEY|ShiftMask, XK_2, tag, index_to_tag(1) }, \ + { MODKEY|ShiftMask, XK_3, tag, index_to_tag(2) }, \ + { MODKEY|ShiftMask, XK_4, tag, index_to_tag(3) }, \ + { MODKEY|ShiftMask, XK_5, tag, index_to_tag(4) }, \ + { MODKEY|ShiftMask, XK_6, tag, index_to_tag(5) }, \ + { MODKEY|ShiftMask, XK_7, tag, index_to_tag(6) }, \ + { MODKEY|ShiftMask, XK_8, tag, index_to_tag(7) }, \ + { MODKEY|ShiftMask, XK_9, tag, index_to_tag(8) }, \ + { MODKEY|ControlMask|ShiftMask, XK_1, toggletag, index_to_tag(0) }, \ + { MODKEY|ControlMask|ShiftMask, XK_2, toggletag, index_to_tag(1) }, \ + { MODKEY|ControlMask|ShiftMask, XK_3, toggletag, index_to_tag(2) }, \ + { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, index_to_tag(3) }, \ + { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, index_to_tag(4) }, \ + { MODKEY|ControlMask|ShiftMask, XK_6, toggletag, index_to_tag(5) }, \ + { MODKEY|ControlMask|ShiftMask, XK_7, toggletag, index_to_tag(6) }, \ + { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, index_to_tag(7) }, \ + { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, index_to_tag(8) }, \ { MODKEY|ShiftMask, XK_q, quit, NULL }, \ }; diff -r cdd1db1c525b dwm.c --- a/dwm.c Fri Oct 19 09:56:51 2007 +0200 +++ b/dwm.c Sat Oct 20 17:09:46 2007 +0200 @@ -143,7 +143,6 @@ long getstate(Window w); long getstate(Window w); Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); void grabbuttons(Client *c, Bool focused); -unsigned int idxoftag(const char *tag); void initfont(const char *fontstr); Bool isarrange(void (*func)()); Bool isoccupied(unsigned int t); @@ -230,12 +229,13 @@ Regs *regs = NULL; Regs *regs = NULL; /* configuration, allows nested code to access above variables */ +#define index_to_tag(x) ((char const *)(x)) +#define tag_to_index(x) ((unsigned int)(x)) #include "config.h" /* statically define the number of tags. */ -unsigned int ntags = sizeof tags / sizeof tags[0]; -Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True}; -Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True}; +Bool seltags[ntags] = {[0] = True}; +Bool prevtags[ntags] = {[0] = True}; /* function implementations */ void @@ -841,16 +841,6 @@ grabbuttons(Client *c, Bool focused) { else XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); -} - -unsigned int -idxoftag(const char *tag) { - unsigned int i; - - for(i = 0; i < ntags; i++) - if(tags[i] == tag) - return i; - return 0; } void @@ -1543,8 +1533,8 @@ tag(const char *arg) { if(!sel) return; for(i = 0; i < ntags; i++) - sel->tags[i] = arg == NULL; - i = idxoftag(arg); + sel->tags[i] = tag_to_index(arg) == ntags; + i = tag_to_index(arg); if(i >= 0 && i < ntags) sel->tags[i] = True; arrange(); @@ -1660,7 +1650,7 @@ toggletag(const char *arg) { if(!sel) return; - i = idxoftag(arg); + i = tag_to_index(arg); sel->tags[i] = !sel->tags[i]; for(j = 0; j < ntags && !sel->tags[j]; j++); if(j == ntags) @@ -1672,7 +1662,7 @@ toggleview(const char *arg) { toggleview(const char *arg) { unsigned int i, j; - i = idxoftag(arg); + i = tag_to_index(arg); seltags[i] = !seltags[i]; for(j = 0; j < ntags && !seltags[j]; j++); if(j == ntags) @@ -1842,8 +1832,8 @@ view(const char *arg) { memcpy(prevtags, seltags, sizeof seltags); for(i = 0; i < ntags; i++) - seltags[i] = arg == NULL; - i = idxoftag(arg); + seltags[i] = tag_to_index(arg) == ntags; + i = tag_to_index(arg); if(i >= 0 && i < ntags) seltags[i] = True; arrange();