diff -u --new-file dwm-1.6/config.default.h dwm-1.6.modified/config.default.h --- dwm-1.6/config.default.h 2006-09-16 10:20:20.000000000 +0100 +++ dwm-1.6.modified/config.default.h 2006-09-16 20:18:20.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 */ \ @@ -29,8 +31,6 @@ { MODKEY|ShiftMask, XK_Tab, focusprev, { 0 } }, \ { MODKEY, XK_Return, zoom, { 0 } }, \ { MODKEY, XK_m, togglemax, { 0 } }, \ - { MODKEY, XK_g, resizecol, { .i = 20 } }, \ - { MODKEY, XK_s, resizecol, { .i = -20 } }, \ { MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \ { MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \ { MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \ @@ -42,7 +42,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 } }, \ @@ -55,6 +55,33 @@ { 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} },\ }; /* Query class:instance:title for regex matching info with following command: diff -u --new-file dwm-1.6/dwm.h dwm-1.6.modified/dwm.h --- dwm-1.6/dwm.h 2006-09-16 10:20:20.000000000 +0100 +++ dwm-1.6.modified/dwm.h 2006-09-16 20:06:14.000000000 +0100 @@ -91,6 +91,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 */ @@ -145,6 +158,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 */ @@ -166,3 +186,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 column, 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 --new-file dwm-1.6/patchDoc.txt dwm-1.6.modified/patchDoc.txt --- dwm-1.6/patchDoc.txt 1970-01-01 01:00:00.000000000 +0100 +++ dwm-1.6.modified/patchDoc.txt 2006-09-16 20:20:14.000000000 +0100 @@ -0,0 +1,65 @@ +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.) + +Note the column width adjust keybindings have been removed +because they don't work under the modified tiling code. Also, +the `float toggle' has been remapped to ModKey-f to make +the space key available for new functionality. + +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. + +The keys ModKey-Fx for x=1..9 will move the selected +client into position x in the dislayed list. + +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). These basic versions also deselect HI_TAG +and move to HI_TAG+1. Adding the Ctrl modifier to these +just modifies the selected client without moving. (I find I +tend to use the `select and move' version most frequently.) +Similar interpretation applies to `o', except in the opposite +direction. + +ModKey-Ctrl-Shift-o +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. diff -u --new-file dwm-1.6/tag.c dwm-1.6.modified/tag.c --- dwm-1.6/tag.c 2006-09-16 10:20:20.000000000 +0100 +++ dwm-1.6.modified/tag.c 2006-09-16 20:07:43.000000000 +0100 @@ -137,3 +137,124 @@ sel->weight = (i == ntags) ? arg->i : i; arrange(NULL); } +/* 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(NULL); + } +} + +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(NULL); + } +} + +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(NULL); + } +} + +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; @@ -77,69 +79,166 @@ restack(); } -void -dotile(Arg *arg) { - int h, i, n, w; - Client *c; - - maximized = False; +/* 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 || noCols!=MAX_COLS) && (arg->i!=-1 || noCols!=1)){ + noCols+=arg->i; + noStackCols=noCols-1; + arrange(NULL); + } +} + +/* change the balance between number of full and stacked columns */ +void +adjustcoltypes(Arg *arg) +{ + if(arg && (arg->i!=1 || noStackCols!=0) && (arg->i!=-1 || noStackCols!=noCols)){ + noStackCols-=arg->i; + arrange(NULL); + } +} + +/***************************************************************************** + * 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 + * peculiarities: + * if + ****************************************************************************/ +void +dotile(Arg *arg) +{ + int n, i; + Client *c; + + maximized = False; + + for(n = 0, c = clients; c; c = c->next) + if(isvisible(c) && !c->isfloat) + n++; + 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; + /* 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->x = cumWid; + c->y = cumHgt; + c->w = widths[colNo] - 2; + c->h = heights[colNo] - 2; + 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(); +} - w = sw - mw; - for(n = 0, c = clients; c; c = c->next) - if(isvisible(c) && !c->isfloat) - n++; +static Client * +minname() +{ + Client *c, *min; - if(n > 1) - h = (sh - bh) / (n - 1); - else - h = sh - bh; + for(min = c = clients; c; c = c->next) + if(strncasecmp(c->name,min->name,sizeof(c->name))<0) + min = c; + return min; +} - for(i = 0, c = clients; c; c = c->next) { - 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)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); +/* sort all the clients (whether displayed or not) by title */ +void +sortallbytitle(Arg *arg) +{ + reorder(&minname); + arrange(NULL); +} + +//precondition: arg must have .i set to integer >=1 +void +moveToPosn(Arg *arg) +{ + unsigned int n; + Client *c,*d=0;//we'll re-insert just after client d + if(arg->i==0 || !sel || !clients || sel==clients || sel->isfloat || arrange!=dotile || maximized){ + return; + } + for(n = 0, c = clients; c; c = c->next){ + if(isvisible(c) && !c->isfloat){ + if(n==arg->i-1){ + d=c; + } + n++; + } + } + c=sel; + if(!d || c==d || clients==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(NULL); } +/* end changes and additions */ + void focusnext(Arg *arg) { Client *c; @@ -246,7 +345,7 @@ for(i = 0; i < ntags && !seltag[i]; i++); if(i == ntags) seltag[arg->i] = True; /* cannot toggle last view */ - reorder(); + reorder(&minclient); arrange(NULL); } @@ -257,7 +356,7 @@ for(i = 0; i < ntags; i++) seltag[i] = False; seltag[arg->i] = True; - reorder(); + reorder(&minclient); arrange(NULL); } @@ -267,7 +366,7 @@ for(i = 0; i < ntags; i++) seltag[i] = True; - reorder(); + reorder(&minclient); arrange(NULL); }