Files
nni.dev 18fe157743 patch-added: swapmons
fixed: key-bindings conflict

fixed: whitespaces, improved: README

fixed: typos && refactor: patch
2026-09-02 13:54:37 +05:30

69 lines
2.3 KiB
Diff

From 5a134ae84949b36336d268f73ae14e9254356e03 Mon Sep 17 00:00:00 2001
From: "nni.dev" <nni001@noreply.codeberg.org>
Date: Fri, 28 Aug 2026 16:56:30 +0530
Subject: [PATCH] patch: swaps client from Mon A to Mon B while preserving tags
---
config.def.h | 2 ++
dwl.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..21dd3d7 100644
--- a/config.def.h
+++ b/config.def.h
@@ -144,6 +144,8 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
+ { MODKEY, XKB_KEY_x, swapmon, {.i = WLR_DIRECTION_LEFT} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_x, swapmon, {.i = WLR_DIRECTION_RIGHT} },
TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
diff --git a/dwl.c b/dwl.c
index e14ad43..3dfa3ff 100644
--- a/dwl.c
+++ b/dwl.c
@@ -292,6 +292,7 @@ static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
+static void swapmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);
@@ -1556,6 +1557,29 @@ focusmon(const Arg *arg)
focusclient(focustop(selmon), 1);
}
+void
+swapmon(const Arg *arg)
+{
+ Client *c1 = focustop(selmon);
+ Monitor *m2 = dirtomon(arg->i);
+ Client *c2 = focustop(m2);
+
+ if (!c1 || m2 == selmon)
+ return;
+
+ /* Move Client to monitor 2 */
+ setmon(c1, m2, c1->tags);
+
+ /* If monitor2 has active client, move to monitor1 */
+ if (c2) {
+ setmon(c2, selmon, c2->tags);
+ }
+ /*Keep Focus on the last active monitor*/
+ focusclient(c1, 1);
+ arrange(selmon);
+ arrange(m2);
+}
+
void
focusstack(const Arg *arg)
{
--
2.55.0