commit ea2148a392b778af0870dba2862cd93b115fddd9
parent 62c6235e4942726bbae5e19bc2807626e03860ca
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date: Sun, 21 May 2023 00:31:34 +0200
[nat] new command to swap monitor contents
Diffstat:
M | config.def.h | | | 2 | ++ |
M | dwm.c | | | 55 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -95,6 +95,8 @@ static const Key keys[] = {
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
+ { MODKEY|ControlMask, XK_comma, swapmon, {.i = -1 } },
+ { MODKEY|ControlMask, XK_period, swapmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
TAGKEYS( XK_1, 0)
diff --git a/dwm.c b/dwm.c
@@ -218,6 +218,7 @@ static void showhide(Client *c);
static void spawn(const Arg *arg);
static void swapclient(const Arg *arg);
static void swapfocus(const Arg *arg);
+static void swapmon(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
@@ -1999,6 +2000,60 @@ swapfocus(const Arg *arg)
}
void
+swapmon(const Arg *arg)
+{
+ Client *c;
+ Monitor *targetmon;
+ Monitor tmp;
+
+ if (!mons->next)
+ return;
+
+ targetmon = dirtomon(arg->i);
+ tmp = *selmon;
+
+ selmon->mfact = targetmon->mfact;
+ selmon->nmaster = targetmon->nmaster;
+ selmon->seltags = targetmon->seltags;
+ selmon->sellt = targetmon->sellt;
+ selmon->tagset[0] = targetmon->tagset[0];
+ selmon->tagset[1] = targetmon->tagset[1];
+ selmon->showbar = targetmon->showbar;
+ selmon->topbar = targetmon->topbar;
+ selmon->clients = targetmon->clients;
+ selmon->sel = targetmon->sel;
+ selmon->stack = targetmon->stack;
+ selmon->lt[0] = targetmon->lt[0];
+ selmon->lt[1] = targetmon->lt[1];
+ selmon->pertag = targetmon->pertag;
+
+ targetmon->mfact = tmp.mfact;
+ targetmon->nmaster = tmp.nmaster;
+ targetmon->seltags = tmp.seltags;
+ targetmon->sellt = tmp.sellt;
+ targetmon->tagset[0] = tmp.tagset[0];
+ targetmon->tagset[1] = tmp.tagset[1];
+ targetmon->showbar = tmp.showbar;
+ targetmon->topbar = tmp.topbar;
+ targetmon->clients = tmp.clients;
+ targetmon->sel = tmp.sel;
+ targetmon->stack = tmp.stack;
+ targetmon->lt[0] = tmp.lt[0];
+ targetmon->lt[1] = tmp.lt[1];
+ targetmon->pertag = tmp.pertag;
+
+ for (c = selmon->clients; c; c = c->next)
+ c->mon = selmon;
+
+ for (c = targetmon->clients; c; c = c->next)
+ c->mon = targetmon;
+
+ arrange(selmon);
+ focus(targetmon->sel);
+ arrange(targetmon);
+}
+
+void
togglemark(const Arg *arg)
{
if (!selmon->sel)