diff -u --new-file dwm-1.1/config.default.h dwm-1.1.modified/config.default.h --- dwm-1.1/config.default.h 2006-08-28 09:19:51.000000000 +0100 +++ dwm-1.1.modified/config.default.h 2006-08-28 13:12:45.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.1/dwm.h dwm-1.1.modified/dwm.h --- dwm-1.1/dwm.h 2006-08-28 09:19:51.000000000 +0100 +++ dwm-1.1.modified/dwm.h 2006-08-28 13:13:31.000000000 +0100 @@ -137,3 +137,10 @@ 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); +extern void setwithnexttag(Arg *arg); +extern void popcurrenttag(Arg *arg); +extern void movewrtcurrenttag(Arg *arg); +extern void zapcurrenttag(Arg *arg); diff -u --new-file dwm-1.1/patchDoc.txt dwm-1.1.modified/patchDoc.txt --- dwm-1.1/patchDoc.txt 1970-01-01 01:00:00.000000000 +0100 +++ dwm-1.1.modified/patchDoc.txt 2006-08-28 13:36:52.000000000 +0100 @@ -0,0 +1,47 @@ +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. + +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.1/view.c dwm-1.1.modified/view.c --- dwm-1.1/view.c 2006-08-28 09:19:51.000000000 +0100 +++ dwm-1.1.modified/view.c 2006-08-28 13:11:17.000000000 +0100 @@ -30,70 +30,242 @@ restack(); } +/* begin changes and additions */ +static const int MAX_COLS=8; +static int noCols=2; +static int noFullCols=1; +static int noStackCols=1; + +inline +int +min(int x,int y) +{ + return xi==1 && noCols==MAX_COLS) + || (arg->i==-1 && noCols==1)){ + return; + } + noCols+=arg->i; + noFullCols=1; + noStackCols=noCols-noFullCols; + arrange(NULL); +} + +/* 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); +} + +//for moment, hardwire to either 1 or 2 monitor setup void dotile(Arg *arg) { - int h, i, n, w; - Client *c; + int n, i, horizSlide=noStackCols/2; + Client *c; + int noPerCol[MAX_COLS],heights[MAX_COLS],widths[MAX_COLS]; + + for(n = 0, c = clients; c; c = c->next) + if(isvisible(c) && !c->isfloat) + n++; + int nP = n==0 ? 1 : min(n,noCols); /* n==0 not used but avoid faults */ + Bool useNonTrivialCols=noStackCols>0 && n >= noCols + && (n-noFullCols)*bh <= (sh-bh)*noStackCols; + /* build tables of essential layout parameters */ + for(i = 0; i < nP; ++i){ /* default to every column full height */ + noPerCol[i] = i; + heights[i] = sh-bh; + int div=nP; + if(NO_MONITORS>1 && nP%2!=0 && nP>1){ + div+=(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; /*set to infinity so we never leave final column*/ + } + /* use tables to assign actual client positions in layout */ + int colNo = 0; + int cumHgt = sy + bh,cumWid=sx; + 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 = cumWid; + c->y = cumHgt; + c->w = widths[colNo] - 2; + c->h = 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 */ + 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(); +} - w = sw - mw; - for(n = 0, c = clients; c; c = c->next) - if(isvisible(c) && !c->isfloat) - n++; +/* 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); +} - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; - 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 || !isvisible(sel)) - sel = getnext(clients); - if(sel) - focus(sel); +/* 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 +processmodifiedtagging(void) +{ + settitle(sel); + if(!isvisible(sel)) + arrange(NULL); else - XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - restack(); + drawstatus(); +} + +void +setwithnexttag(Arg *arg) +{ + sel->tags[min(highestTagUsed()+1,ntags-1)]=True; + processmodifiedtagging(); +} + +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 */ void focusnext(Arg *arg)