diff -u --new-file dwm-1.2/config.default.h dwm-1.2.modified/config.default.h --- dwm-1.2/config.default.h 2006-08-30 12:00:05.000000000 +0100 +++ dwm-1.2.modified/config.default.h 2006-08-30 14:47:07.000000000 +0100 @@ -21,6 +21,8 @@ #define MODKEY Mod1Mask #define MASTERW 60 /* percent */ +#define NO_MONITORS 2 /*only correct for 1 or 2 */ + #define KEYS \ static Key key[] = { \ /* modifier key function arguments */ \ @@ -52,6 +54,16 @@ { MODKEY|ControlMask, XK_4, toggleview, { .i = 3 } }, \ { MODKEY|ControlMask, XK_5, toggleview, { .i = 4 } }, \ { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ + { MODKEY, XK_n, adjustnumbercols, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_n, adjustnumbercols, { .i=-1 } }, \ + { MODKEY, XK_b, adjustcoltypes, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_b, adjustcoltypes, { .i=-1 } }, \ + { MODKEY, XK_s, sortallbytitle, { 0 } }, \ + { MODKEY, XK_p, setwithnexttag, { 0 } }, \ + { MODKEY|ShiftMask, XK_p, popcurrenttag, { 0 } }, \ + { MODKEY, XK_o, movewrtcurrenttag, { .i=1 } }, \ + { MODKEY|ShiftMask, XK_o, movewrtcurrenttag, { .i=-1 } }, \ + { MODKEY|ControlMask, XK_p, zapcurrenttag, { 0 } }, \ }; /* Query class:instance:title for regex matching info with following command: diff -u --new-file dwm-1.2/dwm.h dwm-1.2.modified/dwm.h --- dwm-1.2/dwm.h 2006-08-30 12:00:05.000000000 +0100 +++ dwm-1.2.modified/dwm.h 2006-08-30 14:55:19.000000000 +0100 @@ -66,6 +66,8 @@ Window twin; }; +#define min(x,y) (x)<(y)?(x):(y) + extern const char *tags[]; extern char stext[1024]; extern int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh; @@ -119,6 +121,10 @@ extern void settags(Client *c); extern void tag(Arg *arg); extern void toggletag(Arg *arg); +extern void setwithnexttag(Arg *arg); +extern void popcurrenttag(Arg *arg); +extern void movewrtcurrenttag(Arg *arg); +extern void zapcurrenttag(Arg *arg); /* util.c */ extern void *emallocz(unsigned int size); @@ -138,3 +144,6 @@ extern void toggleview(Arg *arg); extern void view(Arg *arg); extern void zoom(Arg *arg); +extern void adjustnumbercols(Arg *arg); +extern void adjustcoltypes(Arg *arg); +extern void sortallbytitle(Arg *arg); diff -u --new-file dwm-1.2/patchDoc.txt dwm-1.2.modified/patchDoc.txt --- dwm-1.2/patchDoc.txt 1970-01-01 01:00:00.000000000 +0100 +++ dwm-1.2.modified/patchDoc.txt 2006-08-30 14:51:52.000000000 +0100 @@ -0,0 +1,55 @@ +This patch includes some functions I find useful for working with +large setups, particularly xinerama. There is a #define in +config.h NO_MONITORS which can be set to 1 or 2. (The +formulae used are incorrect for more than 2 monitors.) + +Firstly, the number of +columns on the screen is totally dynamic and can be increased +(with ModKey-n) or decreased (with ModKey-Shift-n). Given the +current number of columns, if NO_MONITORS is 1 or there are +an even number of columns, all columns are assigned the same +width. If 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. (Might +get 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 increased (with ModKey-b) or +decreased (with ModKey-Shift-b). + +Other than increasing the total number, types and widths of +columns, the tiling algorithm should be functionally equivalent +to the mainstream dwm layout algorithm, except for one final +wrinkle: when NO_MONITORS is 2 the display is essentially +`wrapped around' by floor(noCols/4) in an attempt to put +the zoomed column (which is what the user is presumably +primarily working with) towards the centre of the overall +display, rather than stuck on the far left side of the two +monitors. causing the neck to be constantly slightly turned. +If you dislike this behaviour you can disable it by making +the initial assignment to `slideCol' in dotile() unconditionally 0. + +Secondly, ModKey-s sorts all the clients by title name. + +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.) 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. Mod-Shift-p +removes HI_TAG from the current client (which effectively +banishes is). ModKey-Ctrl-p +removes HI_TAG from all clients UNLESS that is their last tag, +for which clients it does nothing. If it managed to +remove HI_TAG from all clients which have it, it sets +the HI_TAG-1 in the selected views and rearranges. + +This is all rather abstract: the workflow I use it for is +to `push' a subset of the current clients onto a new, +scratch view (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. + +To facilitate relative movement, Mod-o deselects HI_TAG and +selects HI_TAG+1 (ie, `moves upward by 1 tag') whilst +Mod-Shift-o deselects HI_TAG and +selects HI_TAG-1 (ie, `moves downward by 1 tag') diff -u --new-file dwm-1.2/tag.c dwm-1.2.modified/tag.c --- dwm-1.2/tag.c 2006-08-30 12:00:05.000000000 +0100 +++ dwm-1.2.modified/tag.c 2006-08-30 14:42:12.000000000 +0100 @@ -149,3 +149,78 @@ sel->tags[arg->i] = True; commit(); } + +/* 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*/ +} + +void +setwithnexttag(Arg *arg) +{ + sel->tags[min(highestTagUsed()+1,ntags-1)]=True; + commit(); +} + +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; + return False; + } + return True; +} + +void +popcurrenttag(Arg *arg) +{ + if(sel && unsetspecifiedtag(sel,highestTagUsed())){ + arrange(NULL); + } +} + +void +movewrtcurrenttag(Arg *arg) +{ + int curTag=highestTagUsed(); + if(!arg || (arg->i==1 && curTag==ntags-1) || (arg->i==-1 && curTag==0)){ + return; + } + seltag[curTag]=False; + seltag[curTag+arg->i]=True; + arrange(NULL); +} + +void +zapcurrenttag(Arg *arg) +{ + Client *c; + int toZap=highestTagUsed(),i; + Bool ok=True; + for(c = clients; c; c = c->next) { + if(c->tags[toZap]){/* prevent potentially much pointless work */ + ok=ok && unsetspecifiedtag(c,toZap); + } + } + if(ok && toZap>0){ + seltag[toZap]=False; + seltag[toZap-1]=True; + } + arrange(NULL); +} +/* end changes and additions */ + diff -u --new-file dwm-1.2/view.c dwm-1.2.modified/view.c --- dwm-1.2/view.c 2006-08-30 12:00:05.000000000 +0100 +++ dwm-1.2.modified/view.c 2006-08-30 14:51:16.000000000 +0100 @@ -74,69 +74,166 @@ restack(); } +/* begin changes and additions */ +static const int MAX_COLS=8; +static int noCols=2; +static int noFullCols=1; +static int noStackCols=1; + +/* change the total number of columns */ void -dotile(Arg *arg) +adjustnumbercols(Arg *arg) { - int h, i, n, w; - Client *c; + if(!arg || (arg->i==1 && noCols==MAX_COLS) + || (arg->i==-1 && noCols==1)){ + return; + } + noCols+=arg->i; + noFullCols=1; + noStackCols=noCols-noFullCols; + arrange(NULL); +} - w = sw - mw; - for(n = 0, c = clients; c; c = c->next) - if(isvisible(c) && !c->isfloat) - n++; +/* change the balance between number of full and stacked columns */ +void +adjustcoltypes(Arg *arg) +{ + if(!arg || (arg->i==1 && noFullCols==noCols) + || (arg->i==-1 && noFullCols==0)){ + return; + } + noFullCols+=arg->i; + noStackCols-=arg->i; + arrange(NULL); +} - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; +/***************************************************************************** + * for moment, restrict to either 1 or 2 monitor setup + * first build width/height tables, then fill them rather than merge two + * to into combined code to ease future experiments + * slideCol causes wraparound so zoomed column starts quarter way in + ****************************************************************************/ +void +dotile(Arg *arg) +{ + int n, i; + Client *c; - for(i = 0, c = clients; c; c = c->next) { - c->ismax = False; - if(isvisible(c)) { - if(c->isfloat) { - resize(c, True, TopLeft); - continue; - } - if(n == 1) { - c->x = sx; - c->y = sy + bh; - c->w = sw - 2; - c->h = sh - 2 - bh; - } - else if(i == 0) { - c->x = sx; - c->y = sy + bh; - c->w = mw - 2; - c->h = sh - 2 - bh; - } - else if(h > bh) { - c->x = sx + mw; - c->y = sy + (i - 1) * h + bh; - c->w = w - 2; - if(i + 1 == n) - c->h = sh - c->y - 2; - else - c->h = h - 2; - } - else { /* fallback if h < bh */ - c->x = sx + mw; - c->y = sy + bh; - c->w = w - 2; - c->h = sh - 2 - bh; - } - resize(c, False, TopLeft); - i++; - } - else - ban(c); - } - if((sel = getnext(clients))) - focus(sel); - else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - restack(); + for(n = 0, c = clients; c; c = c->next) + if(isvisible(c) && !c->isfloat) + n++; + int nP = n==0 ? 1 : min(n,noCols); /* no cols actually used on this view */ + Bool useNonTrivialCols=noStackCols>0 && n >= noCols + && (n-noFullCols)*bh <= (sh-bh)*noStackCols; + /* figure out the two (possibly identical) column widths */ + int wideW=nP,narrowW=nP; + if(NO_MONITORS>1 && nP%2!=0 && nP>1){ + wideW-=1; + narrowW+=1; + } + wideW=sw/wideW; + narrowW=sw/narrowW; + /* build tables of essential layout parameters */ + int noPerCol[MAX_COLS],heights[MAX_COLS],widths[MAX_COLS]; + widths[0]=sx; + for(i = 0; i < nP; ++i){ /* default to every column full height */ + noPerCol[i] = i; + heights[i] = sh-bh; + if(i>0){ + widths[i]=(i<=nP/2 ? wideW : narrowW) + widths[i-1]; /* <= correct */ + } + } + if(useNonTrivialCols){ /* figure the stack column client's heights */ + int noOfShortCols = noCols - (n-noFullCols)%noStackCols; + int noInShortCol = (n-noFullCols)/noStackCols; + for(i = noFullCols; i < noCols; ++i){ + int no = noInShortCol + (i>=noOfShortCols?1:0); + heights[i] = (sh - bh) / no; + noPerCol[i] = no + (i==0 ? -1 : noPerCol[i - 1]);/* cumulative total when new col begins */ + } + }else{ + noPerCol[nP-1]=65535; /* `infinity' so we never leave final column*/ + } + /* use tables to assign actual client positions in layout */ + int colNo = 0, cumHgt = sy + bh, slideCol=(NO_MONITORS==1 ? 0 : nP/4); + for(i = 0, c = clients; c; c = c->next) { + c->ismax = False; + if(isvisible(c)) { + if(c->isfloat) { + resize(c, True, TopLeft); + continue; + } + c->x = widths[slideCol]; + c->y = cumHgt; + c->w = (slideColh = heights[colNo] - 2; + if(i == noPerCol[colNo]){ /* next client starts a new column */ + c->h = sh - 2 - c->y; /* soak up rounding down error pixels */ + ++colNo; + slideCol=(slideCol+1)%nP; + 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(); } +/* sort all the clients (whether displayed or not) by title */ +void +sortallbytitle(Arg *arg) +{ + Client *t; + if(!clients || !(clients->next)){ + return; + } + Client fakeRoot; + int len; + fakeRoot.next=clients; + clients->prev=&fakeRoot; + /* figure how many elements in list */ + for(len=0, t=clients; t ;t=t->next){ + ++len; + } + /* use simple bubble sort as it's easier to figure the pointers*/ + while(--len>0){ + Client *fst=fakeRoot.next; + int cnt=len; + while(--cnt>0){ + Client *snd=fst->next; + if(strncasecmp(fst->name,snd->name,sizeof(fst->name))>0){ + /* set-up external pointers */ + fst->prev->next=snd; + if(snd->next){ + snd->next->prev=fst; + } + /* set-up internal pointers */ + fst->next=snd->next; + snd->prev=fst->prev; + snd->next=fst; + fst->prev=snd; + }else{ + fst=snd; + } + } + } + clients=fakeRoot.next; + arrange(NULL); +} + +/* end changes and additions */ + void focusnext(Arg *arg) {