commit c443c249af578afc1fe31b0720f0208afc2d7a78
parent e4a31fc3e1216d3301d2b00836cb6808eef37153
Author: Miles Alan <m@milesalan.com>
Date: Sun, 26 Apr 2020 08:57:53 -0500
Attachbelow patch
Diffstat:
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -23,6 +23,9 @@ static const char *colors[][3] = {
[SchemeTabInactive] = { col_gray1, col_gray3, col_gray1 }
};
+/* 1 means attach after the currently active window */
+static const int attachbelow = 1;
+
/* tagging */
static const char *tags[] = { "1", "2", "3", "4" };
diff --git a/dwm.1 b/dwm.1
@@ -29,6 +29,9 @@ color. The tags of the focused window are indicated with a filled square in the
top left corner. The tags which are applied to one or more windows are
indicated with an empty square in the top left corner.
.P
+The attach below patch makes newly spawned windows attach after the currently
+selected window
+.P
dwm draws a small border around windows to indicate the focus state.
.SH OPTIONS
.TP
diff --git a/dwm.c b/dwm.c
@@ -156,6 +156,7 @@ 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 attachBelow(Client *c);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
@@ -537,6 +538,21 @@ attach(Client *c)
c->next = c->mon->clients;
c->mon->clients = c;
}
+void
+attachBelow(Client *c)
+{
+ //If there is nothing on the monitor or the selected client is floating, attach as normal
+ if(c->mon->sel == NULL || c->mon->sel->isfloating) {
+ attach(c);
+ return;
+ }
+
+ //Set the new client's next property to the same as the currently selected clients next
+ c->next = c->mon->sel->next;
+ //Set the currently selected clients next property to the new client
+ c->mon->sel->next = c;
+
+}
void
attachstack(Client *c)
@@ -1426,7 +1442,10 @@ manage(Window w, XWindowAttributes *wa)
c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating)
XRaiseWindow(dpy, c->win);
- attach(c);
+ if( attachbelow )
+ attachBelow(c);
+ else
+ attach(c);
attachstack(c);
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
@@ -1847,7 +1866,10 @@ sendmon(Client *c, Monitor *m)
detachstack(c);
c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
- attach(c);
+ if( attachbelow )
+ attachBelow(c);
+ else
+ attach(c);
attachstack(c);
focus(NULL);
arrange(NULL);
@@ -2349,7 +2371,10 @@ updategeom(void)
m->clients = c->next;
detachstack(c);
c->mon = mons;
- attach(c);
+ if( attachbelow )
+ attachBelow(c);
+ else
+ attach(c);
attachstack(c);
}
if (m == selmon)