summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-01-31 19:36:12 -0700
committerChristian Kolset <christian.kolset@gmail.com>2026-01-31 19:36:38 -0700
commit4b08a81dedf169b1dd70da951a64be612b4b75e6 (patch)
tree0d6d893244d34b2252dbd4ca2b664871f97aebfc /dwm.c
parent5d984affdafe9e7f46855ebe53761aebd6b8c8b9 (diff)
Applied dwm-attachdirection patch manually.
Allows for easy switching between: - attachbelow - attachabove - attachaside - attachtop - attachbottom - default using config.h
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c147
1 files changed, 143 insertions, 4 deletions
diff --git a/dwm.c b/dwm.c
index 6f26857..8a784ce 100644
--- a/dwm.c
+++ b/dwm.c
@@ -57,7 +57,8 @@
#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 ISINC(X) ((X) > 1000 && (X) < 3000)
-#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky)
+#define ISVISIBLEONTAG(C, T) ((C->tags & T))
+#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
#define PREVSEL 3000
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
@@ -182,6 +183,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 attachtop(Client *c);
+static void attachbottom(Client *c);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
@@ -222,6 +228,7 @@ static void maprequest(XEvent *e);
static void monocle(Monitor *m);
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);
@@ -483,6 +490,74 @@ attach(Client *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)
{
c->snext = c->mon->stack;
@@ -1452,7 +1527,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);
@@ -1585,6 +1678,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)
{
for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
@@ -1838,7 +1941,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);
setclienttagprop(c);
focus(NULL);
@@ -2433,7 +2554,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)