diff --git a/README.md b/README.md index 2a45bc7..4734a43 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,5 @@ Most patches can be found on the suckless website: [https://dwm.suckless.org/pat * [alwaysfullscreen](https://dwm.suckless.org/patches/alwaysfullscreen/) - Do not allow the focus to drift from the active fullscreen client when using focusstack() * [anybar](https://github.com/mihirlad55/dwm-anybar) (Polybar Tray Fix Version) - Enables dwm to manage external status bars such as lemonbar and polybar * [aspectresize](https://dwm.suckless.org/patches/aspectresize/) - Allows you to resize a window while maintaining aspect ratio +* [attachbelow](https://dwm.suckless.org/patches/attachbelow/) (Toggleable) - Make new clients attach below the selected client, instead of always becoming the new master * [fixborders](https://dwm.suckless.org/patches/alpha/) - Make borders opaque diff --git a/config.def.h b/config.def.h index 6433817..ed0bb25 100644 --- a/config.def.h +++ b/config.def.h @@ -39,6 +39,7 @@ static const Rule rules[] = { 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 resizehints = 1; /* 1 means respect size hints in tiled resizals */ +static int attachbelow = 1; /* 1 means attach after the currently active window */ static const Layout layouts[] = { /* symbol arrange function */ @@ -64,43 +65,44 @@ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, static const char *termcmd[] = { "st", NULL }; static Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_p, spawn, {.v = dmenucmd } }, - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_d, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY, XK_Return, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY|ShiftMask, XK_j, aspectresize, {.i = +24} }, - { MODKEY|ShiftMask, XK_k, aspectresize, {.i = -24} }, - { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY|ShiftMask, XK_f, togglefullscr, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { MODKEY|ShiftMask, XK_q, quit, {0} }, + /* modifier key function argument */ + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY, XK_i, incnmaster, {.i = +1 } }, + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_j, aspectresize, {.i = +24} }, + { MODKEY|ShiftMask, XK_k, aspectresize, {.i = -24} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY|ShiftMask, XK_f, togglefullscr, {0} }, + { MODKEY, XK_Tab, toggleAttachBelow, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, + { MODKEY, XK_comma, focusmon, {.i = -1 } }, + { MODKEY, XK_period, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, + { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) + TAGKEYS( XK_4, 3) + TAGKEYS( XK_5, 4) + TAGKEYS( XK_6, 5) + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) + { MODKEY|ShiftMask, XK_q, quit, {0} }, }; /* button definitions */ diff --git a/dwm.1 b/dwm.1 index eb64e03..16a91cc 100644 --- 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 @@ -122,14 +125,17 @@ Toggle focused window between tiled and floating state. .B Mod1\-Shift\-f Toggle fullscreen (actualfullscreen patch). .TP +.B Mod1\-Shift\-tab +Toggle attach below (attachbelow patch). +.TP .B Mod1\-Tab Toggles to the previously selected tags. .TP .B Mod1\-Shift\-j -Increase window size while maintaining aspect ratio. +Increase window size while maintaining aspect ratio (aspectresize patch). .TP .B Mod1\-Shift\-k -Decrease window size while maintaining aspect ratio. +Decrease window size while maintaining aspect ratio (aspectresize patch). .TP .B Mod1\-Shift\-[1..n] Apply nth tag to focused window. diff --git a/dwm.c b/dwm.c index 79971f6..ef05569 100644 --- a/dwm.c +++ b/dwm.c @@ -150,6 +150,8 @@ static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void aspectresize(const Arg *arg); static void attach(Client *c); +static void attachBelow(Client *c); +static void toggleAttachBelow(); static void attachstack(Client *c); static void buttonpress(XEvent *e); static void checkotherwm(void); @@ -441,6 +443,26 @@ 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 == c || 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 toggleAttachBelow() +{ + attachbelow = !attachbelow; +} void attachstack(Client *c) @@ -1109,7 +1131,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); @@ -1530,7 +1555,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); @@ -2074,7 +2102,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) diff --git a/patches/dwm-attachbelow-toggleable-6.2.diff b/patches/dwm-attachbelow-toggleable-6.2.diff new file mode 100644 index 0000000..3fe2c0d --- /dev/null +++ b/patches/dwm-attachbelow-toggleable-6.2.diff @@ -0,0 +1,199 @@ +From ee036687ed9e1bb973b9e34694a57cf5dd67652d Mon Sep 17 00:00:00 2001 +From: Jonathan Hodgson +Date: Mon, 6 May 2019 18:34:40 +0100 +Subject: [PATCH 1/4] Adds attach below option + +--- + config.def.h | 1 + + dwm.c | 31 ++++++++++++++++++++++++++++--- + 2 files changed, 29 insertions(+), 3 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..51ad933 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -35,6 +35,7 @@ static const Rule rules[] = { + 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 resizehints = 1; /* 1 means respect size hints in tiled resizals */ ++static const int attachbelow = 1; /* 1 means attach at the end */ + + static const Layout layouts[] = { + /* symbol arrange function */ +diff --git a/dwm.c b/dwm.c +index 4465af1..bd715a2 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -147,6 +147,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); +@@ -405,6 +406,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 == c || 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) +@@ -1062,7 +1078,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); +@@ -1417,7 +1436,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); +@@ -1897,7 +1919,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) +-- +2.21.0 + + +From e212c1d8cbdcc56c33c717131dfa7c1689e27e9f Mon Sep 17 00:00:00 2001 +From: Jonathan Hodgson +Date: Mon, 6 May 2019 19:27:57 +0100 +Subject: [PATCH 2/4] fixes comment + +--- + config.def.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index 51ad933..cb8053a 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -35,7 +35,7 @@ static const Rule rules[] = { + 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 resizehints = 1; /* 1 means respect size hints in tiled resizals */ +-static const int attachbelow = 1; /* 1 means attach at the end */ ++static const int attachbelow = 1; /* 1 means attach after the currently active window */ + + static const Layout layouts[] = { + /* symbol arrange function */ +-- +2.21.0 + + +From 7568ea3f8756e7e82b30c4943556ae646a445d1c Mon Sep 17 00:00:00 2001 +From: Jonathan Hodgson +Date: Mon, 6 May 2019 20:00:30 +0100 +Subject: [PATCH 3/4] Makes changes to man page to reflect attach below patch + +--- + dwm.1 | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/dwm.1 b/dwm.1 +index 13b3729..fb6e76c 100644 +--- 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 +-- +2.21.0 + + +From 362b95a5b9f91673f27f3e3343b5738df3c9d6e9 Mon Sep 17 00:00:00 2001 +From: Jonathan Hodgson +Date: Sun, 2 Jun 2019 15:11:57 +0100 +Subject: [PATCH 4/4] Allows attach below to be toggled + +--- + config.def.h | 2 +- + dwm.c | 6 ++++++ + 2 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index cb8053a..b4d35aa 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -35,7 +35,7 @@ static const Rule rules[] = { + 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 resizehints = 1; /* 1 means respect size hints in tiled resizals */ +-static const int attachbelow = 1; /* 1 means attach after the currently active window */ ++static int attachbelow = 1; /* 1 means attach after the currently active window */ + + static const Layout layouts[] = { + /* symbol arrange function */ +diff --git a/dwm.c b/dwm.c +index bd715a2..5d88653 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -148,6 +148,7 @@ static void arrange(Monitor *m); + static void arrangemon(Monitor *m); + static void attach(Client *c); + static void attachBelow(Client *c); ++static void toggleAttachBelow(); + static void attachstack(Client *c); + static void buttonpress(XEvent *e); + static void checkotherwm(void); +@@ -422,6 +423,11 @@ attachBelow(Client *c) + + } + ++void toggleAttachBelow() ++{ ++ attachbelow = !attachbelow; ++} ++ + void + attachstack(Client *c) + { +-- +2.21.0 +