dwm-runrules-20250820-cfb8627.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-runrules-20250820-cfb8627.diff (3181B)
       ---
            1 From 9a37cd46b9151c0ff28b0f0a17a244fe44fcb1de Mon Sep 17 00:00:00 2001
            2 From: Ian Laird <irlaird@gmail.com>
            3 Date: Wed, 20 Aug 2025 18:35:45 -0700
            4 Subject: [PATCH] Adds 2 methods to reapply rules to existing client windows.
            5 
            6 ---
            7  config.def.h |  2 ++
            8  dwm.c        | 32 ++++++++++++++++++++++++++++----
            9  2 files changed, 30 insertions(+), 4 deletions(-)
           10 
           11 diff --git a/config.def.h b/config.def.h
           12 index 9efa774..6b27df6 100644
           13 --- a/config.def.h
           14 +++ b/config.def.h
           15 @@ -64,6 +64,8 @@ static const Key keys[] = {
           16          /* modifier                     key        function        argument */
           17          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           18          { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
           19 +        { MODKEY,                       XK_r,      runrulesfocused,{0} },
           20 +        { MODKEY|ShiftMask,             XK_r,      runrulesall,    {0} },
           21          { MODKEY,                       XK_b,      togglebar,      {0} },
           22          { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
           23          { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
           24 diff --git a/dwm.c b/dwm.c
           25 index 1443802..bd3bcd5 100644
           26 --- a/dwm.c
           27 +++ b/dwm.c
           28 @@ -141,7 +141,7 @@ typedef struct {
           29  } Rule;
           30  
           31  /* function declarations */
           32 -static void applyrules(Client *c);
           33 +static void applyrules(Client *c, int default_tags);
           34  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
           35  static void arrange(Monitor *m);
           36  static void arrangemon(Monitor *m);
           37 @@ -193,6 +193,8 @@ static void resizeclient(Client *c, int x, int y, int w, int h);
           38  static void resizemouse(const Arg *arg);
           39  static void restack(Monitor *m);
           40  static void run(void);
           41 +static void runrulesall(const Arg *args);
           42 +static void runrulesfocused(const Arg *args);
           43  static void scan(void);
           44  static int sendevent(Client *c, Atom proto);
           45  static void sendmon(Client *c, Monitor *m);
           46 @@ -275,7 +277,7 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
           47  
           48  /* function implementations */
           49  void
           50 -applyrules(Client *c)
           51 +applyrules(Client *c, int default_tags)
           52  {
           53          const char *class, *instance;
           54          unsigned int i;
           55 @@ -307,7 +309,7 @@ applyrules(Client *c)
           56                  XFree(ch.res_class);
           57          if (ch.res_name)
           58                  XFree(ch.res_name);
           59 -        c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
           60 +        c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : default_tags ? default_tags : c->mon->tagset[c->mon->seltags];
           61  }
           62  
           63  int
           64 @@ -1049,7 +1051,7 @@ manage(Window w, XWindowAttributes *wa)
           65                  c->tags = t->tags;
           66          } else {
           67                  c->mon = selmon;
           68 -                applyrules(c);
           69 +                applyrules(c, 0);
           70          }
           71  
           72          if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
           73 @@ -1389,6 +1391,28 @@ run(void)
           74                          handler[ev.type](&ev); /* call handler */
           75  }
           76  
           77 +static void
           78 +runrulesfocused(const Arg *args)
           79 +{
           80 +        if (selmon->sel) {
           81 +        applyrules(selmon->sel, 0);
           82 +                focus(NULL);
           83 +                arrange(selmon);
           84 +        }
           85 +}
           86 +
           87 +static void
           88 +runrulesall(const Arg *args)
           89 +{
           90 +    for (Monitor *m = selmon; m; m=m->next) {
           91 +        for (Client *c = m->clients; c; c = c->next) {
           92 +            applyrules(c, c->tags);
           93 +        }
           94 +        arrange(m);
           95 +    }
           96 +    focus(NULL);
           97 +}
           98 +
           99  void
          100  scan(void)
          101  {
          102 -- 
          103 2.50.1
          104