diff --git a/config.h b/config.h index 1fe3884..c782fb7 100644 --- a/config.h +++ b/config.h @@ -55,7 +55,8 @@ static const BarRule barrules[] = { static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ static const int nstack = 0; /* number of clients in primary stack area */ -static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ +static const int attachdirection = 4; /* 0 default, 1 above, 2 aside, 3 below, 4 bottom, 5 top */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const Layout layouts[] = { diff --git a/dwm.c b/dwm.c index 0b060d4..fd1a0eb 100644 --- a/dwm.c +++ b/dwm.c @@ -50,7 +50,8 @@ #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) -#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) +#define ISVISIBLEONTAG(C, T) ((C->tags & T)) +#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags]) #define LENGTH(X) (sizeof X / sizeof X[0]) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X) ((X)->w + 2 * (X)->bw) @@ -215,6 +216,11 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); +static void attachabove(Client *c); +static void attachaside(Client *c); +static void attachbelow(Client *c); +static void attachbottom(Client *c); +static void attachtop(Client *c); static void attachstack(Client *c); static void buttonpress(XEvent *e); static void checkotherwm(void); @@ -253,6 +259,7 @@ static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static Client *nexttagged(Client *c); static Client *nexttiled(Client *c); static void pop(Client *c); static void propertynotify(XEvent *e); @@ -505,6 +512,73 @@ attach(Client *c) c->mon->clients = c; } +void +attachabove(Client *c) +{ + if (c->mon->sel == NULL || c->mon->sel == c->mon->clients || c->mon->sel->isfloating) { + attach(c); + return; + } + + Client *at; + for (at = c->mon->clients; at->next != c->mon->sel; at = at->next); + c->next = at->next; + at->next = c; +} + +void +attachaside(Client *c) { + Client *at = nexttagged(c); + if(!at) { + attach(c); + return; + } + c->next = at->next; + at->next = c; +} + +void +attachbelow(Client *c) +{ + if(c->mon->sel == NULL || c->mon->sel == c || c->mon->sel->isfloating) { + attach(c); + return; + } + c->next = c->mon->sel->next; + c->mon->sel->next = c; +} + +void +attachbottom(Client *c) +{ + Client *below = c->mon->clients; + for (; below && below->next; below = below->next); + c->next = NULL; + if (below) + below->next = c; + else + c->mon->clients = c; +} + +void +attachtop(Client *c) +{ + int n; + Monitor *m = selmon; + Client *below; + + for (n = 1, below = c->mon->clients; + below && below->next && (below->isfloating || !ISVISIBLEONTAG(below, c->tags) || n != m->nmaster); + n = below->isfloating || !ISVISIBLEONTAG(below, c->tags) ? n + 0 : n + 1, below = below->next); + c->next = NULL; + if (below) { + c->next = below->next; + below->next = c; + } + else + c->mon->clients = c; +} + void attachstack(Client *c) { @@ -1424,7 +1498,25 @@ manage(Window w, XWindowAttributes *wa) c->isfloating = c->oldstate = trans != None || c->isfixed; if (c->isfloating) XRaiseWindow(dpy, c->win); - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char *) &(c->win), 1); @@ -1545,6 +1637,16 @@ movemouse(const Arg *arg) } } +Client * +nexttagged(Client *c) { + Client *walked = c->mon->clients; + for(; + walked && (walked->isfloating || !ISVISIBLEONTAG(walked, c->tags)); + walked = walked->next + ); + return walked; +} + Client * nexttiled(Client *c) { @@ -1781,7 +1883,25 @@ sendmon(Client *c, Monitor *m) detachstack(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); focus(NULL); arrange(NULL); @@ -2383,7 +2503,25 @@ updategeom(void) m->clients = c->next; detachstack(c); c->mon = mons; - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); } if (m == selmon)