@@ -43,6 +43,7 @@ static const Layout layouts[] = { | |||
{ "[M]", monocle }, | |||
{ "|M|", centeredmaster }, | |||
{ ">M>", centeredfloatingmaster }, | |||
{ "HHH", grid }, | |||
}; | |||
/* key definitions */ | |||
@@ -61,10 +62,12 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() | |||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; | |||
static const char *termcmd[] = { "x-terminal-emulator", NULL }; | |||
#include "movestack.c" | |||
static Key keys[] = { | |||
/* modifier key function argument */ | |||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, | |||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, | |||
{ MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, | |||
{ MODKEY, XK_b, togglebar, {0} }, | |||
{ MODKEY, XK_j, focusstackvis, {.i = +1 } }, | |||
{ MODKEY, XK_k, focusstackvis, {.i = -1 } }, | |||
@@ -74,6 +77,8 @@ static Key keys[] = { | |||
{ MODKEY, XK_d, incnmaster, {.i = -1 } }, | |||
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, | |||
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, | |||
{ MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, | |||
{ MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, | |||
{ MODKEY, XK_Return, zoom, {0} }, | |||
{ MODKEY, XK_Tab, view, {0} }, | |||
{ MODKEY|ShiftMask, XK_c, killclient, {0} }, | |||
@@ -83,6 +88,7 @@ static Key keys[] = { | |||
{ MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, | |||
{ MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, | |||
{ MODKEY, XK_space, setlayout, {0} }, | |||
{ MODKEY, XK_g, setlayout, {.v = &layouts[5]} }, | |||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} }, | |||
{ MODKEY, XK_0, view, {.ui = ~0 } }, | |||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, | |||
@@ -0,0 +1,44 @@ | |||
From 3e020d93df3aaec92d2daa142cd1f0d5301b3197 Mon Sep 17 00:00:00 2001 | |||
From: Mateus Auler <mateusauler@protonmail.com> | |||
Date: Fri, 17 Jul 2020 12:36:36 -0300 | |||
Subject: [PATCH] Ability to map a key combination to switch focus to | |||
the master window. | |||
--- | |||
dwm.c | 16 ++++++++++++++++ | |||
1 file changed, 16 insertions(+) | |||
diff --git a/dwm.c b/dwm.c | |||
index 9fd0286..be01927 100644 | |||
--- a/dwm.c | |||
+++ b/dwm.c | |||
@@ -235,6 +235,8 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); | |||
static int xerrorstart(Display *dpy, XErrorEvent *ee); | |||
static void zoom(const Arg *arg); | |||
+static void focusmaster(const Arg *arg); | |||
+ | |||
/* variables */ | |||
static const char broken[] = "broken"; | |||
static char stext[256]; | |||
@@ -2150,3 +2152,17 @@ main(int argc, char *argv[]) | |||
XCloseDisplay(dpy); | |||
return EXIT_SUCCESS; | |||
} | |||
+ | |||
+void | |||
+focusmaster(const Arg *arg) | |||
+{ | |||
+ Client *c; | |||
+ | |||
+ if (selmon->nmaster < 1) | |||
+ return; | |||
+ | |||
+ c = nexttiled(selmon->clients); | |||
+ | |||
+ if (c) | |||
+ focus(c); | |||
+} | |||
-- | |||
2.27.0 | |||
@@ -0,0 +1,73 @@ | |||
From b04bb473cf9818277d33a591f7fe2dfae96afaaf Mon Sep 17 00:00:00 2001 | |||
From: Joshua Haase <hahj87@gmail.com> | |||
Date: Mon, 15 Aug 2016 17:06:18 -0500 | |||
Subject: [PATCH] Apply modified gridmode patch. | |||
--- | |||
config.def.h | 3 +++ | |||
layouts.c | 27 +++++++++++++++++++++++++++ | |||
2 files changed, 30 insertions(+) | |||
create mode 100644 layouts.c | |||
diff --git a/config.def.h b/config.def.h | |||
index a9ac303..30b7c4a 100644 | |||
--- a/config.def.h | |||
+++ b/config.def.h | |||
@@ -36,11 +36,13 @@ 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 */ | |||
+#include "layouts.c" | |||
static const Layout layouts[] = { | |||
/* symbol arrange function */ | |||
{ "[]=", tile }, /* first entry is default */ | |||
{ "><>", NULL }, /* no layout function means floating behavior */ | |||
{ "[M]", monocle }, | |||
+ { "HHH", grid }, | |||
}; | |||
/* key definitions */ | |||
@@ -76,6 +78,7 @@ static Key keys[] = { | |||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, | |||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, | |||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, | |||
+ { MODKEY, XK_g, setlayout, {.v = &layouts[3]} }, | |||
{ MODKEY, XK_space, setlayout, {0} }, | |||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} }, | |||
{ MODKEY, XK_0, view, {.ui = ~0 } }, | |||
diff --git a/layouts.c b/layouts.c | |||
new file mode 100644 | |||
index 0000000..d26acf3 | |||
--- /dev/null | |||
+++ b/layouts.c | |||
@@ -0,0 +1,27 @@ | |||
+void | |||
+grid(Monitor *m) { | |||
+ unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows; | |||
+ Client *c; | |||
+ | |||
+ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) | |||
+ n++; | |||
+ | |||
+ /* grid dimensions */ | |||
+ for(rows = 0; rows <= n/2; rows++) | |||
+ if(rows*rows >= n) | |||
+ break; | |||
+ cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; | |||
+ | |||
+ /* window geoms (cell height/width) */ | |||
+ ch = m->wh / (rows ? rows : 1); | |||
+ cw = m->ww / (cols ? cols : 1); | |||
+ for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { | |||
+ cx = m->wx + (i / rows) * cw; | |||
+ cy = m->wy + (i % rows) * ch; | |||
+ /* adjust height/width of last row/column's windows */ | |||
+ ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0; | |||
+ aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0; | |||
+ resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False); | |||
+ i++; | |||
+ } | |||
+} | |||
-- | |||
2.14.1 | |||
@@ -0,0 +1,73 @@ | |||
diff -r 050d521d66d8 config.def.h | |||
--- a/config.def.h Tue Aug 24 13:13:20 2010 +0100 | |||
+++ b/config.def.h Sun Sep 05 18:43:07 2010 +0200 | |||
@@ -57,6 +57,7 @@ | |||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; | |||
static const char *termcmd[] = { "st", NULL }; | |||
+#include "movestack.c" | |||
static Key keys[] = { | |||
/* modifier key function argument */ | |||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, | |||
@@ -68,6 +69,8 @@ | |||
{ MODKEY, XK_d, incnmaster, {.i = -1 } }, | |||
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, | |||
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, | |||
+ { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, | |||
+ { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, | |||
{ MODKEY, XK_Return, zoom, {0} }, | |||
{ MODKEY, XK_Tab, view, {0} }, | |||
{ MODKEY|ShiftMask, XK_c, killclient, {0} }, | |||
diff -r 050d521d66d8 movestack.c | |||
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |||
+++ b/movestack.c Sun Sep 05 18:43:07 2010 +0200 | |||
@@ -0,0 +1,49 @@ | |||
+void | |||
+movestack(const Arg *arg) { | |||
+ Client *c = NULL, *p = NULL, *pc = NULL, *i; | |||
+ | |||
+ if(arg->i > 0) { | |||
+ /* find the client after selmon->sel */ | |||
+ for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); | |||
+ if(!c) | |||
+ for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); | |||
+ | |||
+ } | |||
+ else { | |||
+ /* find the client before selmon->sel */ | |||
+ for(i = selmon->clients; i != selmon->sel; i = i->next) | |||
+ if(ISVISIBLE(i) && !i->isfloating) | |||
+ c = i; | |||
+ if(!c) | |||
+ for(; i; i = i->next) | |||
+ if(ISVISIBLE(i) && !i->isfloating) | |||
+ c = i; | |||
+ } | |||
+ /* find the client before selmon->sel and c */ | |||
+ for(i = selmon->clients; i && (!p || !pc); i = i->next) { | |||
+ if(i->next == selmon->sel) | |||
+ p = i; | |||
+ if(i->next == c) | |||
+ pc = i; | |||
+ } | |||
+ | |||
+ /* swap c and selmon->sel selmon->clients in the selmon->clients list */ | |||
+ if(c && c != selmon->sel) { | |||
+ Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; | |||
+ selmon->sel->next = c->next==selmon->sel?c:c->next; | |||
+ c->next = temp; | |||
+ | |||
+ if(p && p != c) | |||
+ p->next = c; | |||
+ if(pc && pc != selmon->sel) | |||
+ pc->next = selmon->sel; | |||
+ | |||
+ if(selmon->sel == selmon->clients) | |||
+ selmon->clients = c; | |||
+ else if(c == selmon->clients) | |||
+ selmon->clients = selmon->sel; | |||
+ | |||
+ arrange(selmon); | |||
+ } | |||
+} | |||
+ |
@@ -0,0 +1,90 @@ | |||
diff -up a/config.def.h b/config.def.h | |||
--- a/config.def.h 2019-06-06 21:23:27.006661784 +0200 | |||
+++ b/config.def.h 2019-06-20 15:05:59.083102462 +0200 | |||
@@ -58,11 +58,14 @@ static const Layout layouts[] = { | |||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ | |||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; | |||
static const char *termcmd[] = { "st", NULL }; | |||
+static const char scratchpadname[] = "scratchpad"; | |||
+static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; | |||
static Key keys[] = { | |||
/* modifier key function argument */ | |||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, | |||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, | |||
+ { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, | |||
{ MODKEY, XK_b, togglebar, {0} }, | |||
{ MODKEY, XK_j, focusstack, {.i = +1 } }, | |||
{ MODKEY, XK_k, focusstack, {.i = -1 } }, | |||
diff -up a/dwm.c b/dwm.c | |||
--- a/dwm.c 2019-06-06 21:23:27.023328450 +0200 | |||
+++ b/dwm.c 2019-06-20 15:07:01.089767947 +0200 | |||
@@ -213,6 +213,7 @@ static void tagmon(const Arg *arg); | |||
static void tile(Monitor *); | |||
static void togglebar(const Arg *arg); | |||
static void togglefloating(const Arg *arg); | |||
+static void togglescratch(const Arg *arg); | |||
static void toggletag(const Arg *arg); | |||
static void toggleview(const Arg *arg); | |||
static void unfocus(Client *c, int setfocus); | |||
@@ -273,6 +274,8 @@ static Window root, wmcheckwin; | |||
/* configuration, allows nested code to access above variables */ | |||
#include "config.h" | |||
+static unsigned int scratchtag = 1 << LENGTH(tags); | |||
+ | |||
/* compile-time check if all tags fit into an unsigned int bit array. */ | |||
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; | |||
@@ -1052,6 +1055,14 @@ manage(Window w, XWindowAttributes *wa) | |||
&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); | |||
c->bw = borderpx; | |||
+ selmon->tagset[selmon->seltags] &= ~scratchtag; | |||
+ if (!strcmp(c->name, scratchpadname)) { | |||
+ c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; | |||
+ c->isfloating = True; | |||
+ c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); | |||
+ c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); | |||
+ } | |||
+ | |||
wc.border_width = c->bw; | |||
XConfigureWindow(dpy, w, CWBorderWidth, &wc); | |||
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); | |||
@@ -1661,6 +1672,7 @@ spawn(const Arg *arg) | |||
{ | |||
if (arg->v == dmenucmd) | |||
dmenumon[0] = '0' + selmon->num; | |||
+ selmon->tagset[selmon->seltags] &= ~scratchtag; | |||
if (fork() == 0) { | |||
if (dpy) | |||
close(ConnectionNumber(dpy)); | |||
@@ -1748,6 +1760,28 @@ togglefloating(const Arg *arg) | |||
} | |||
void | |||
+togglescratch(const Arg *arg) | |||
+{ | |||
+ Client *c; | |||
+ unsigned int found = 0; | |||
+ | |||
+ for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); | |||
+ if (found) { | |||
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; | |||
+ if (newtagset) { | |||
+ selmon->tagset[selmon->seltags] = newtagset; | |||
+ focus(NULL); | |||
+ arrange(selmon); | |||
+ } | |||
+ if (ISVISIBLE(c)) { | |||
+ focus(c); | |||
+ restack(selmon); | |||
+ } | |||
+ } else | |||
+ spawn(arg); | |||
+} | |||
+ | |||
+void | |||
toggletag(const Arg *arg) | |||
{ | |||
unsigned int newtags; |
@@ -238,6 +238,7 @@ static void tagmon(const Arg *arg); | |||
static void tile(Monitor *); | |||
static void togglebar(const Arg *arg); | |||
static void togglefloating(const Arg *arg); | |||
static void togglescratch(const Arg *arg); | |||
static void toggletag(const Arg *arg); | |||
static void toggleview(const Arg *arg); | |||
static void togglewin(const Arg *arg); | |||
@@ -264,6 +265,8 @@ static void zoom(const Arg *arg); | |||
static void centeredmaster(Monitor *m); | |||
static void centeredfloatingmaster(Monitor *m); | |||
static void focusmaster(const Arg *arg); | |||
/* variables */ | |||
static const char broken[] = "broken"; | |||
static char stext[256]; | |||
@@ -309,6 +312,8 @@ struct Pertag { | |||
int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ | |||
}; | |||
static unsigned int scratchtag = 1 << LENGTH(tags); | |||
/* compile-time check if all tags fit into an unsigned int bit array. */ | |||
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; | |||
@@ -1244,6 +1249,14 @@ manage(Window w, XWindowAttributes *wa) | |||
&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); | |||
c->bw = borderpx; | |||
selmon->tagset[selmon->seltags] &= ~scratchtag; | |||
if (!strcmp(c->name, scratchpadname)) { | |||
c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; | |||
c->isfloating = True; | |||
c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); | |||
c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); | |||
} | |||
wc.border_width = c->bw; | |||
XConfigureWindow(dpy, w, CWBorderWidth, &wc); | |||
XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix); | |||
@@ -1881,6 +1894,7 @@ spawn(const Arg *arg) | |||
{ | |||
if (arg->v == dmenucmd) | |||
dmenumon[0] = '0' + selmon->num; | |||
selmon->tagset[selmon->seltags] &= ~scratchtag; | |||
if (fork() == 0) { | |||
if (dpy) | |||
close(ConnectionNumber(dpy)); | |||
@@ -1961,6 +1975,28 @@ togglefloating(const Arg *arg) | |||
arrange(selmon); | |||
} | |||
void | |||
togglescratch(const Arg *arg) | |||
{ | |||
Client *c; | |||
unsigned int found = 0; | |||
for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); | |||
if (found) { | |||
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; | |||
if (newtagset) { | |||
selmon->tagset[selmon->seltags] = newtagset; | |||
focus(NULL); | |||
arrange(selmon); | |||
} | |||
if (ISVISIBLE(c)) { | |||
focus(c); | |||
restack(selmon); | |||
} | |||
} else | |||
spawn(arg); | |||
} | |||
void | |||
toggletag(const Arg *arg) | |||
{ | |||
@@ -2562,3 +2598,17 @@ centeredfloatingmaster(Monitor *m) | |||
tx += WIDTH(c); | |||
} | |||
} | |||
void | |||
focusmaster(const Arg *arg) | |||
{ | |||
Client *c; | |||
if (selmon->nmaster < 1) | |||
return; | |||
c = nexttiled(selmon->clients); | |||
if (c) | |||
focus(c); | |||
} |
@@ -0,0 +1,27 @@ | |||
void | |||
grid(Monitor *m) { | |||
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows; | |||
Client *c; | |||
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) | |||
n++; | |||
/* grid dimensions */ | |||
for(rows = 0; rows <= n/2; rows++) | |||
if(rows*rows >= n) | |||
break; | |||
cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; | |||
/* window geoms (cell height/width) */ | |||
ch = m->wh / (rows ? rows : 1); | |||
cw = m->ww / (cols ? cols : 1); | |||
for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { | |||
cx = m->wx + (i / rows) * cw; | |||
cy = m->wy + (i % rows) * ch; | |||
/* adjust height/width of last row/column's windows */ | |||
ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0; | |||
aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0; | |||
resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False); | |||
i++; | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
void | |||
movestack(const Arg *arg) { | |||
Client *c = NULL, *p = NULL, *pc = NULL, *i; | |||
if(arg->i > 0) { | |||
/* find the client after selmon->sel */ | |||
for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); | |||
if(!c) | |||
for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); | |||
} | |||
else { | |||
/* find the client before selmon->sel */ | |||
for(i = selmon->clients; i != selmon->sel; i = i->next) | |||
if(ISVISIBLE(i) && !i->isfloating) | |||
c = i; | |||
if(!c) | |||
for(; i; i = i->next) | |||
if(ISVISIBLE(i) && !i->isfloating) | |||
c = i; | |||
} | |||
/* find the client before selmon->sel and c */ | |||
for(i = selmon->clients; i && (!p || !pc); i = i->next) { | |||
if(i->next == selmon->sel) | |||
p = i; | |||
if(i->next == c) | |||
pc = i; | |||
} | |||
/* swap c and selmon->sel selmon->clients in the selmon->clients list */ | |||
if(c && c != selmon->sel) { | |||
Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; | |||
selmon->sel->next = c->next==selmon->sel?c:c->next; | |||
c->next = temp; | |||
if(p && p != c) | |||
p->next = c; | |||
if(pc && pc != selmon->sel) | |||
pc->next = selmon->sel; | |||
if(selmon->sel == selmon->clients) | |||
selmon->clients = c; | |||
else if(c == selmon->clients) | |||
selmon->clients = selmon->sel; | |||
arrange(selmon); | |||
} | |||
} | |||