dwm-swapwindows-20250510-cfb8627.diff (2285B)
1 From 00ea4c4e2d221c7f2979bcf403e4c23abf4b3f79 Mon Sep 17 00:00:00 2001 2 From: jameel-sawafta <jameelhsawafta@gmail.com> 3 Date: Fri, 9 May 2025 22:51:56 +0300 4 Subject: [PATCH] dwm: add swapwindow function to swap focused clients between 5 monitors 6 7 --- 8 config.def.h | 1 + 9 dwm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 10 2 files changed, 47 insertions(+) 11 12 diff --git a/config.def.h b/config.def.h 13 index 9efa774..ec0a706 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -85,6 +85,7 @@ static const Key keys[] = { 17 { MODKEY, XK_period, focusmon, {.i = +1 } }, 18 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 19 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 20 + { MODKEY|ShiftMask, XK_slash, swapwindow, {0} }, 21 TAGKEYS( XK_1, 0) 22 TAGKEYS( XK_2, 1) 23 TAGKEYS( XK_3, 2) 24 diff --git a/dwm.c b/dwm.c 25 index 1443802..ee7658f 100644 26 --- a/dwm.c 27 +++ b/dwm.c 28 @@ -232,6 +232,7 @@ static int xerror(Display *dpy, XErrorEvent *ee); 29 static int xerrordummy(Display *dpy, XErrorEvent *ee); 30 static int xerrorstart(Display *dpy, XErrorEvent *ee); 31 static void zoom(const Arg *arg); 32 +static void swapwindow(const Arg *arg); 33 34 /* variables */ 35 static const char broken[] = "broken"; 36 @@ -2139,6 +2140,51 @@ zoom(const Arg *arg) 37 pop(c); 38 } 39 40 +void 41 +swapwindow(const Arg *arg) 42 +{ 43 + if (!selmon || !selmon->sel || !mons->next) 44 + return; 45 + 46 + Monitor *m1 = selmon; 47 + Monitor *m2 = dirtomon(+1); 48 + 49 + Client *c1 = m1->sel; 50 + Client *c2 = m2->sel; 51 + 52 + if (!c2) { 53 + detach(c1); 54 + detachstack(c1); 55 + c1->mon = m2; 56 + attach(c1); 57 + attachstack(c1); 58 + focus(c1); 59 + selmon = m2; 60 + arrange(m1); 61 + arrange(m2); 62 + return; 63 + } 64 + 65 + detach(c1); 66 + detachstack(c1); 67 + detach(c2); 68 + detachstack(c2); 69 + 70 + c1->mon = m2; 71 + attach(c1); 72 + attachstack(c1); 73 + focus(c1); 74 + 75 + c2->mon = m1; 76 + attach(c2); 77 + attachstack(c2); 78 + focus(c2); 79 + 80 + selmon = m1; 81 + arrange(m1); 82 + arrange(m2); 83 +} 84 + 85 int 86 main(int argc, char *argv[]) 87 { 88 -- 89 2.49.0 90