patch-added: swapmons

fixed: key-bindings conflict

fixed: whitespaces, improved: README

fixed: typos && refactor: patch
This commit is contained in:
nni.dev
2026-09-02 13:54:37 +05:30
parent 2591ce4fe4
commit 18fe157743
2 changed files with 93 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
### Description
This patch is for dual-monitor setups (and can be extended for more monitors). It swaps the active client on Monitor-A with the active client on Monitor-B while preserving original tags of the swapped clients.
Example 1: Monitor-A and Monitor-B are both displaying only tag [1].
The active clients on each monitor has only tag [1] associated.
`swapmon` will simply move the focused client on Monitor-A to Monitor-B and vice versa.
Both monitors will still only display tag [1].
The active clients will still only have tag [1] associated and will each be visible on the monitor to which it was swapped.
Example 2: Monitor-A is displaying only tag [2].
Monitor-B is displaying only tag [1].
The active client on Monitor-A has only tag [2] associated.
The active client on Monitor-B has only tag [1] associated.
`swapmon` will move the active client from Monitor-A to Monitor-B BUT the client will still be associated with tag [2] only and will not be visible since Monitor-B is displaying only tag [1].
Similarly, the active client on Monitor-B will be moved to Monitor-A but the client will still be associated with tag [1] and will not be visible since Monitor-A is displaying only tag [2].
If a client is associated with more than one tag, it will retain all of its associated tags when it is moved to another monitor by `swapmon`.
The reason I preserve tags is that I usually stick to the same ones to stay organized, so it really helps.
### Download
- dwl-0.8: [swapmons-0.8.patch](/dwl/dwl-patches/raw/branch/main/patches/swapmons/swapmons_v0.1.patch)
### Authors - latest at top
- [nni_dev](https://codeberg.org/nni001)
- anni_19_ [dwl Discord](https://discord.gg/jJxZnrGPWN)
+68
View File
@@ -0,0 +1,68 @@
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