diff -u dwm-1.9/config.default.h dwm-1.9.modified/config.default.h --- dwm-1.9/config.default.h 2006-10-06 12:59:22.000000000 +0100 +++ dwm-1.9.modified/config.default.h 2006-10-06 13:41:07.000000000 +0100 @@ -20,6 +20,8 @@ #define MASTER 600 /* per thousand */ #define MODKEY Mod1Mask +#define NO_MONITORS 1 /* only correct for 1 or 2 */ + #define KEYS \ static Key key[] = { \ /* modifier key function arguments */ \ @@ -27,8 +29,6 @@ { MODKEY, XK_Tab, focusnext, { 0 } }, \ { MODKEY|ShiftMask, XK_Tab, focusprev, { 0 } }, \ { MODKEY, XK_Return, zoom, { 0 } }, \ - { MODKEY, XK_g, resizecol, { .i = 15 } }, \ - { MODKEY, XK_s, resizecol, { .i = -15 } }, \ { MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \ { MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \ { MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \ @@ -40,7 +40,7 @@ { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, { .i = 3 } }, \ { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, { .i = 4 } }, \ { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ - { MODKEY, XK_space, togglemode, { 0 } }, \ + { MODKEY, XK_f, togglemode, { 0 } }, \ { MODKEY, XK_0, viewall, { 0 } }, \ { MODKEY, XK_1, view, { .i = 0 } }, \ { MODKEY, XK_2, view, { .i = 1 } }, \ @@ -53,6 +53,34 @@ { MODKEY|ControlMask, XK_4, toggleview, { .i = 3 } }, \ { MODKEY|ControlMask, XK_5, toggleview, { .i = 4 } }, \ { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ + { MODKEY|ControlMask, XK_n, adjustnumbercols, { .i=1 } }, \ + { MODKEY|ControlMask|ShiftMask, XK_n, adjustnumbercols, { .i=-1 } }, \ + { MODKEY, XK_n, adjustcoltypes, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_n, adjustcoltypes, { .i=-1 } }, \ + { MODKEY, XK_s, sortallbytitle, { 0 } }, \ + { MODKEY, XK_p, setAndJump, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_p, unsetAndJump, { .i=-1 } }, \ + { MODKEY|ControlMask, XK_p, setwithnexttag, { .i=1 } }, \ + { MODKEY|ControlMask|ShiftMask, XK_p, zapcurrenttag, { .i=-1 } }, \ + { MODKEY, XK_o, setAndJump, { .i=-1 } }, \ + { MODKEY|ShiftMask, XK_o, unsetAndJump, { .i=1 } }, \ + { MODKEY|ControlMask, XK_o, setwithnexttag, { .i=-1 } }, \ + { MODKEY|ControlMask|ShiftMask, XK_o, zapcurrenttag, { .i=1 } }, \ + { MODKEY, XK_space, movewrtcurrenttag, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_space, movewrtcurrenttag, { .i=-1 } }, \ + { MODKEY|ControlMask, XK_space, pushAllClients, { .i=1 } }, \ + { MODKEY|ControlMask|ShiftMask, XK_space, pushAllClients, { .i=-1 } }, \ + { MODKEY, XK_l, popcurrenttag, { 0 } }, \ + { MODKEY, XK_F1, moveToPosn, {.i=1} },\ + { MODKEY, XK_F2, moveToPosn, {.i=2} },\ + { MODKEY, XK_F3, moveToPosn, {.i=3} },\ + { MODKEY, XK_F4, moveToPosn, {.i=4} },\ + { MODKEY, XK_F5, moveToPosn, {.i=5} },\ + { MODKEY, XK_F6, moveToPosn, {.i=6} },\ + { MODKEY, XK_F7, moveToPosn, {.i=7} },\ + { MODKEY, XK_F8, moveToPosn, {.i=8} },\ + { MODKEY, XK_F9, moveToPosn, {.i=9} },\ + { MODKEY, XK_F10, moveToPosn, {.i=10} }\ }; /* Query class:instance:title for regex matching info with following command: diff -u dwm-1.9/dwm.1 dwm-1.9.modified/dwm.1 --- dwm-1.9/dwm.1 2006-10-06 12:59:22.000000000 +0100 +++ dwm-1.9.modified/dwm.1 2006-10-06 14:41:57.000000000 +0100 @@ -112,6 +112,132 @@ .SH CUSTOMIZATION dwm is customized by creating a custom config.h and (re)compiling the source code. This keeps it fast, secure and simple. +.SH MODIFICATIONS BY LARGE NUMBERS OF CLIENTS PATCH +This patch includes some functions I find useful for working with +large setups, particularly xinerama. There is a #define in +config.h for +.BR NO_MONITORS +which can be set to 1 or 2. (The +formulae used are incorrect for more than 2 monitors.) +.P +Note the column width adjust keybindings +.BR Mod-g +and +.BR Mod-s +have been removed +because they don't work under the modified tiling code. Also, +the `float toggle' has been remapped to +.BR ModKey-f +to make +the space key available for the move workspace function which I +use much more extensively. +.P +Firstly, the number of +columns on the screen is totally dynamic. +.TP +.B ModKey-Ctrl-n +increases the +.BR total +number of columns on the screen by 1. +.TP +.B ModKey-Ctrl-Shift-n +decreases the +.BR total +number of columns on the screen by 1. +.P +Given the +current number of columns, if +.BR NO_MONITORS +is 1 or there are +an even number of columns, all columns are assigned the same +width. If +.BR NO_MONITORS +is 2 with an odd number of columns, +then floor(no cols/2) will be placed on left screen and +ceil(no cols/2) will be placed on the right screen. (There might +be 1-2 pixel rounding errors at various points.) In addition +to the total number of columns, the number of `full columns' +versus `stack columns' can be modified. +.TP +.B ModKey-n +increases the number of +.BR full +columns on the screen by 1. +.TP +.B ModKey-Shift-n +decreases the number of +.BR full +columns on the screen by 1. +.P +Other than increasing the total number, types and widths of +columns, the tiling algorithm should be functionally equivalent +to the mainstream dwm layout algorithm, with the exception +that currently all full and stack columns are set to the same +width regardless of the +.BR MASTERW +setting. +.P +.B ModKey-s +sorts all the clients by title name. +.P +.B ModKey-[F1..F10] +move the selected client into position x in the dislayed list. +.P +For the final commands, it will be less confusing if we +define the HI_TAG as the highest tag being currently +viewed. (If only one tag is being viewed, it is the current +tag.) +.TP +.B ModKey-space +is +.BR now +set to deselect HI_TAG and select HI_TAG+1, i.e., relative +increment of HI_TAG (keeping lower selected tags unchanged). +.TP +.B ModKey-Shift-space +is set to deselect HI_TAG and select HI_TAG-1, i.e., relative +decrement of HI_TAG (keeping lower selected tags unchanged). +.TP +.B ModKey-Ctrl-space +tags all clients with HI_TAG+1 and then deselects HI_TAG and select HI_TAG+1, i.e., relative +push HI_TAG+1 onto all clients and move (keeping lower selected tags unchanged). +.TP +.B ModKey-Ctrl-Shift-space +tags all clients with HI_TAG-1 and then deselects HI_TAG and select HI_TAG-1, i.e., relative +push HI_TAG-1 onto all clients and move(keeping lower selected tags unchanged). +.TP +.B ModKey-p +sets HI_TAG+1 on the current client (keeping +any existing tags). This is so that multiple ModKey-p's +pushes the SAME tag onto all the clients. +.TP +.B Mod-Shift-p +removes HI_TAG from the current client (which effectively +banishes is). These basic versions also deselect HI_TAG +and move to HI_TAG+1. +.P +Adding the +.BR Ctrl +modifier to these +just modifies the selected client without moving. (I find I +tend to use the `select and move' version most frequently.) +.P +Thus the +.BR "p" +based keybindings adjust HI_TAG in a positive direction. Likewise +there are equivalent +.BR "o" +keybindings that do the same things with respect to HI_TAG, +except in a negative direction. +Similar interpretation applies to `o', except in the opposite +direction. +.P +This is all rather abstract: the workflow I use it for is +to `push' a subset of the current clients onto a new, +scratch tag (eg, to concentrate on something), +work with them for a while, then pop the temporary +view out of existance and fall back to the original. +.P .SH CAVEATS The status bar may display .BR "broken pipe" diff -u dwm-1.9/dwm.h dwm-1.9.modified/dwm.h --- dwm-1.9/dwm.h 2006-10-06 12:59:22.000000000 +0100 +++ dwm-1.9.modified/dwm.h 2006-10-06 13:37:25.000000000 +0100 @@ -93,6 +93,19 @@ Window twin; }; +static +inline +int +clamp(int x,int lo,int hi) +{ + if(xhi){ + return hi; + } + return x; +} + extern const char *tags[]; /* all tags */ extern char stext[1024]; /* status text */ extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */ @@ -148,6 +161,13 @@ 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 */ +extern void setwithnexttag(Arg *arg); /* set highestTag+arg->i on client */ +extern void popcurrenttag(Arg *arg); /* unset highestTag+arg->i on client */ +extern void movewrtcurrenttag(Arg *arg); /*deselect highestTag & select highestTag+arg->i */ +extern void zapcurrenttag(Arg *arg); /* unset highestTag from all clients (if possible) */ +extern void setAndJump(Arg *arg); /* set highestTag+arg->i on client and move to it*/ +extern void unsetAndJump(Arg *arg); /* unset highestTag on client & move to highestTag+arg->i */ +extern void pushAllClients(Arg *arg); /*apply highestTag+arg->i to all clients */ /* util.c */ extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ @@ -169,3 +189,7 @@ extern void view(Arg *arg); /* views the tag with arg's index */ extern void viewall(Arg *arg); /* views all tags, arg is ignored */ extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ +extern void adjustnumbercols(Arg *arg); /* change number of columns */ +extern void adjustcoltypes(Arg *arg); /* increment/decrement number of full columns */ +extern void sortallbytitle(Arg *arg); /*sort all clients in title order */ +extern void moveToPosn(Arg *arg); /* put client at position arg->i (restrictions) */ diff -u dwm-1.9/tag.c dwm-1.9.modified/tag.c --- dwm-1.9/tag.c 2006-10-06 12:59:22.000000000 +0100 +++ dwm-1.9.modified/tag.c 2006-10-06 14:44:48.000000000 +0100 @@ -133,3 +133,125 @@ sel->weight = (i == ntags) ? arg->i : i; arrange(); } + +/* begin changes and additions */ + +/* find the highest currently viewed tag */ +int +highestTagUsed() +{ + int i; + for(i=ntags-1;i>=0;--i){ + if(seltag[i]){ + return i; + } + } + return 0; /*should never happen*/ +} + +/*take care of updating the weight*/ +void +flipTag(Client *c,int idx) +{ + c->tags[idx]=True; + if(idxweight){ + c->weight=idx; + } +} + +void +setwithnexttag(Arg *arg) +{ + if(sel){ + flipTag(sel,clamp(highestTagUsed()+arg->i,0,ntags-1)); + arrange(); + } +} + +void +pushAllClients(Arg *arg) +{ + int hiTag=highestTagUsed(),toSet=hiTag+arg->i; + if(toSet>=0 && toSetnext) { + if(c->tags[hiTag]){/* prevent potentially much pointless work */ + flipTag(c,toSet); + } + } + movewrtcurrenttag(arg); + } +} + +void +setAndJump(Arg *arg) +{ + /* arg->i is +/-1*/ + setwithnexttag(arg); + movewrtcurrenttag(arg); +} + +void +unsetAndJump(Arg *arg) +{ + /* arg->i is +/-1*/ + popcurrenttag(arg); + movewrtcurrenttag(arg); +} + +Bool +unsetspecifiedtag(Client *c,int toZap) +{ + int i; + c->tags[toZap]=False; + for(i = 0; i < ntags && !c->tags[i]; i++) /*do nothing*/; + + if(i == ntags){ /* oops: wiped out last tag */ + c->tags[toZap] = True; + c->weight=toZap; + return False; + }else{ + c->weight=i; + return True; + } +} + +void +popcurrenttag(Arg *arg) +{ + if(sel && unsetspecifiedtag(sel,highestTagUsed())){ + arrange(); + } +} + +void +movewrtcurrenttag(Arg *arg) +{ + int curTag=highestTagUsed(); + if(arg && (arg->i!=1 || curTag!=ntags-1) && (arg->i!=-1 || curTag!=0)){ + seltag[curTag]=False; + seltag[curTag+arg->i]=True; + arrange(); + } +} + +void +zapcurrenttag(Arg *arg) +{ + /* require arg.i=+/- 1 */ + Client *c; + int toZap=highestTagUsed(); + Bool ok=True; + for(c = clients; c; c = c->next) { + if(c->tags[toZap]){/* prevent potentially much pointless work */ + ok=ok && unsetspecifiedtag(c,toZap); + } + } + int dest=toZap+arg->i; + if(ok && dest>=0 && destprev = tail; @@ -94,63 +96,171 @@ restack(); } -void -dotile(void) { - unsigned int i, n, mpx, stackw, stackh, th; - Client *c; - - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) +/* begin changes and additions */ +static const int MAX_COLS=8; +static int noCols=2; +static int noStackCols=1; + +/* change the total number of columns */ +void +adjustnumbercols(Arg *arg) +{ + if(arg && (arg->i!=1 || noColsi!=-1 || noCols>1)){ + noCols+=arg->i; + noStackCols=noCols-1; + arrange(); + } +} + +/* change the balance between number of full and stacked columns */ +void +adjustcoltypes(Arg *arg) +{ + if(arg && (arg->i!=1 || noStackCols>0) && (arg->i!=-1 || noStackColsi; + arrange(); + } +} + +/***************************************************************************** + * for moment, restrict to either 1 or 2 monitor setup + * first build width/height tables, then fill them rather than merge two + * into combined code to ease future experiments + * + * peculiarities: + * + ****************************************************************************/ +void +dotile(void) +{ + int n, i; + Client *c; + for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; - mpx = (sw * master) / 1000; - stackw = sw - mpx; - stackh = sh - bh; - th = stackh; - if(n > 1) - th /= (n - 1); + int noStackColsP=noStackCols; /* no stacks we'll actually use this time */ + int noInSCols=n-(noCols-noStackColsP); /* no clients in stack cols */ + int nP = clamp(n,1,noCols); /* no cols actually used on this view */ + while(!(noInSCols*bh <= (sh-bh)*noStackColsP) && noInSCols>0){ /* inc stack cols until fits */ + ++noStackColsP; + noInSCols=n-(noCols-noStackColsP); + } + Bool useNonTrivialCols=noStackColsP>0 && n >= noCols + && noInSCols*bh <= (sh-bh)*noStackColsP; /* got enough height for at least titles? */ + int noOfShortCols = noCols - noInSCols%noStackColsP; /* x%0==0 as desired */ + /* build tables of essential layout parameters */ + int colEndOn[MAX_COLS],heights[MAX_COLS],widths[MAX_COLS]; + for(i = 0; i < nP; ++i){ + heights[i] = sh-bh;/* default to every column full height */ + if(useNonTrivialCols && i>=noCols-noStackColsP){ + int no = noInSCols/noStackColsP + (i>=noOfShortCols?1:0); /* no clients in this col */ + heights[i] /= no; + colEndOn[i] = no + (i==0 ?-1:colEndOn[i-1]);/* col i finishes on this client */ + }else{ + colEndOn[i] = i; + } + int div=nP; + if(NO_MONITORS>1 && nP%2!=0 && nP>1){ + div+=(inext) { + if(isvisible(c)) { + if(c->isfloat) { + resize(c, True, TopLeft); + continue; + } + c->ismax = False; + c->x = cumWid; + c->y = cumHgt; + c->w = widths[colNo] - 2 * BORDERPX; + c->h = heights[colNo] - 2 * BORDERPX; + if(i == colEndOn[colNo]){ /* next client starts a new column */ + c->h = sh - 2 - c->y; /* soak up rounding down error pixels */ + cumWid+=widths[colNo]; + ++colNo; + cumHgt = sy + bh; + }else if(useNonTrivialCols){ + cumHgt += heights[colNo]; + } + resize(c, False, TopLeft); + i++; + } + else + ban(c); + } + if(!sel || !isvisible(sel)) + sel = getnext(clients); + if(sel) + focus(sel); + else + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + restack(); +} - for(i = 0, c = clients; c; c = c->next) - if(isvisible(c)) { - if(c->isfloat) { - resize(c, True, TopLeft); - continue; - } - c->ismax = False; - c->x = sx; - c->y = sy + bh; - if(n == 1) { /* only 1 window */ - c->w = sw - 2 * BORDERPX; - c->h = sh - 2 * BORDERPX - bh; - } - else if(i == 0) { /* master window */ - c->w = mpx - 2 * BORDERPX; - c->h = sh - bh - 2 * BORDERPX; - } - else { /* tile window */ - c->x += mpx; - c->w = stackw - 2 * BORDERPX; - if(th > bh) { - c->y = sy + (i - 1) * th + bh; - if(i + 1 == n) - c->h = sh - c->y - 2 * BORDERPX; - else - c->h = th - 2 * BORDERPX; - } - else /* fallback if th < bh */ - c->h = stackh - 2 * BORDERPX; - } - resize(c, False, TopLeft); - i++; - } - else - ban(c); +static Client * +minname() +{ + Client *c, *min; - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); + if((clients && clients->isfloat) || arrange == dofloat) + return clients; /* don't touch floating order */ + for(min = c = clients; c; c = c->next) + if(c->weight < min->weight + || (c->weight == min->weight && strncasecmp(c->name,min->name,sizeof(c->name))<0)) + min = c; + return min; +} + +/* sort all the clients (whether displayed or not) by title */ +void +sortallbytitle(Arg *arg) +{ + reorder(&minname); + arrange(); +} + +//precondition: arg must have .i set to integer >=1 +//something is still a bit flakey here +void +moveToPosn(Arg *arg) +{ + unsigned int n; + Client *c,*d=0;//we'll re-insert just after client d + int seenSel=0; + if(arg->i==0 || !sel || !clients || sel->isfloat || arrange!=dotile){ + return; + } + for(n = 0, c = clients; c; c = c->next){ + if(isvisible(c) && !c->isfloat){ + if(c==sel){ + seenSel=1; + }else if(n==arg->i-1+seenSel){ + d=c; + } + n++; + } + } + c=sel; + if(!d || c==d){//situation we can't/shouldn't deal with + return; + } + detach(c); + c->next=d->next; + c->prev=d; + c->prev->next=c; + if(c->next){ + c->next->prev=c; + } + focus(c); + arrange(); } +/* end changes and additions */ + void focusnext(Arg *arg) { Client *c; @@ -261,7 +371,7 @@ for(i = 0; i < ntags && !seltag[i]; i++); if(i == ntags) seltag[arg->i] = True; /* cannot toggle last view */ - reorder(); + reorder(&minclient); arrange(); } @@ -272,7 +382,7 @@ for(i = 0; i < ntags; i++) seltag[i] = False; seltag[arg->i] = True; - reorder(); + reorder(&minclient); arrange(); } @@ -282,7 +392,7 @@ for(i = 0; i < ntags; i++) seltag[i] = True; - reorder(); + reorder(&minclient); arrange(); }