sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-swapmonitors-20250510-cfb8627.diff (2172B)


      1 From 4cd2832206eca48190463ac2d3e5ba4e1410c517 Mon Sep 17 00:00:00 2001
      2 From: jameel-sawafta <jameelhsawafta@gmail.com>
      3 Date: Fri, 9 May 2025 22:47:04 +0300
      4 Subject: [PATCH] dwm: add swapmon function to swap monitors
      5 
      6 ---
      7  config.def.h |  1 +
      8  dwm.c        | 33 +++++++++++++++++++++++++++++++++
      9  2 files changed, 34 insertions(+)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 9efa774..7c229cc 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -85,6 +85,7 @@ static const Key keys[] = {
     16  	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
     17  	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
     18  	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
     19 +        { MODKEY|ShiftMask,             XK_apostrophe,  swapmon,   {0} },
     20  	TAGKEYS(                        XK_1,                      0)
     21  	TAGKEYS(                        XK_2,                      1)
     22  	TAGKEYS(                        XK_3,                      2)
     23 diff --git a/dwm.c b/dwm.c
     24 index 1443802..adfe8bd 100644
     25 --- a/dwm.c
     26 +++ b/dwm.c
     27 @@ -232,6 +232,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
     28  static int xerrordummy(Display *dpy, XErrorEvent *ee);
     29  static int xerrorstart(Display *dpy, XErrorEvent *ee);
     30  static void zoom(const Arg *arg);
     31 +static void swapmon(const Arg *arg);
     32  
     33  /* variables */
     34  static const char broken[] = "broken";
     35 @@ -2139,6 +2140,38 @@ zoom(const Arg *arg)
     36  	pop(c);
     37  }
     38  
     39 +void
     40 +swapmon(const Arg *arg)
     41 +{
     42 +    if (mons->next == NULL)
     43 +        return;
     44 +
     45 +    Monitor *m1 = mons;
     46 +    Monitor *m2 = mons->next;
     47 +
     48 +    unsigned int tmp = m1->tagset[m1->seltags];
     49 +    m1->tagset[m1->seltags] = m2->tagset[m2->seltags];
     50 +    m2->tagset[m2->seltags] = tmp;
     51 +
     52 +    Client *c;
     53 +    for (c = m1->clients; c; c = c->next)
     54 +        c->mon = m2;
     55 +    for (c = m2->clients; c; c = c->next)
     56 +        c->mon = m1;
     57 +
     58 +    Client *tmp_clients = m1->clients;
     59 +    m1->clients = m2->clients;
     60 +    m2->clients = tmp_clients;
     61 +
     62 +    Client *tmp_stack = m1->stack;
     63 +    m1->stack = m2->stack;
     64 +    m2->stack = tmp_stack;
     65 +
     66 +    focus(NULL);
     67 +    arrange(m1);
     68 +    arrange(m2);
     69 +}
     70 +
     71  int
     72  main(int argc, char *argv[])
     73  {
     74 -- 
     75 2.49.0
     76