commit 1a6fd1063af890f59fa7163ff39334c07bba3983
parent 1abf7046cd66d800b274e95d8f325cd14e67f07f
Author: Alex Balgavy <alexander.balgavy@spaceapplications.com>
Date: Thu, 18 Apr 2024 19:01:37 +0200
Rules: allow overriding with more specific title
Tags in rules are no longer additive, but each rule overrides the next.
Windows with a more specific (longer) title can override other windows
of the same program. So for example, windows with KeePassXC in the title
can be tiled and set to tag 7, but windows with "AutoType - KeePassXC"
(a more specific/longer match) can be configured as floating and
displayed on the current tag.
Diffstat:
M | config.h | | | 31 | +++++++++++++++++-------------- |
M | dwm.c | | | 13 | +++++++++++-- |
2 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/config.h b/config.h
@@ -41,21 +41,24 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*
- * tags: tag 1 is 000000001, tag 9 is 100000000, etc. https://dwm.suckless.org/customisation/tagmask/
+ * tags: tag 1 is 000000001 (1st from the right), tag 9 is 100000000, etc. https://dwm.suckless.org/customisation/tagmask/
+ * tag 0 is the currently selected tag.
*/
- /* class, instance, title, tags, isfloating, isterminal, noswallow, monitor */
- { "Gimp", NULL, NULL, 0, 0, 0, 0, -1 },
- { TERMCLASS, NULL, NULL, 0, 0, 1, 0, -1 },
- { "Desktop-session-exit.py", NULL, NULL, 0, 1, 0, 0, -1 },
- { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 },
- { "Brave-browser", "brave-browser", NULL, 1 << 8, 0, 0, 0, -1 },
- { "Dragon-drag-and-drop", NULL, NULL, 0, 1, 0, 1, -1 },
- { "ripdrag", NULL, NULL, 0, 1, 0, 1, -1 },
- { "Signal", "signal", "Signal", 1 << 7, 0, 0, 0, -1 },
- { "thunderbird", NULL, NULL, 1 << 4, 0, 0, 0, -1 },
- { "Mattermost", NULL, NULL, 1 << 5, 0, 0, 0, -1 },
- { "KeePassXC", NULL, NULL, 1 << 6, 0, 0, 0, -1 },
- { "Spotify", NULL, NULL, 1 << 3, 0, 0, 1, -1 },
+ /* class, instance, title, tags, isfloating, isterminal, noswallow, monitor */
+ { "Gimp", NULL, NULL, 0, 0, 0, 0, -1 },
+ { TERMCLASS, NULL, NULL, 0, 0, 1, 0, -1 },
+ { "Desktop-session-exit.py", NULL, NULL, 0, 1, 0, 0, -1 },
+ { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 },
+ { "Brave-browser", "brave-browser", NULL, 1 << 8, 0, 0, 0, -1 },
+ { "Dragon-drag-and-drop", NULL, NULL, 0, 1, 0, 1, -1 },
+ { "ripdrag", NULL, NULL, 0, 1, 0, 1, -1 },
+ { "Signal", "signal", "Signal", 1 << 7, 0, 0, 0, -1 },
+ { "thunderbird", NULL, NULL, 1 << 4, 0, 0, 0, -1 },
+ { "Mattermost", NULL, NULL, 1 << 5, 0, 0, 0, -1 },
+ { "KeePassXC", "keepassxc", "Passwords", 1 << 6, 0, 0, 0, -1 },
+ { "KeePassXC", "keepassxc", "KeePassXC", 1 << 6, 0, 0, 0, -1 },
+ { "KeePassXC", "keepassxc", "Auto-Type - KeePassXC", 0, 1, 0, 0, -1 },
+ { "Spotify", NULL, NULL, 1 << 3, 0, 0, 1, -1 },
};
/* layout(s) */
diff --git a/dwm.c b/dwm.c
@@ -362,16 +362,25 @@ applyrules(Client *c)
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
+ int longest_rule_match = 0;
+
for (i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
- if ((!r->title || strstr(c->name, r->title))
+
+ int rule_title_len = 0;
+ if (r->title)
+ rule_title_len = strlen(r->title);
+
+ if ((!r->title || (strstr(c->name, r->title) && (rule_title_len > longest_rule_match)))
&& (!r->class || strstr(class, r->class))
&& (!r->instance || strstr(instance, r->instance)))
{
+ if (r->title)
+ longest_rule_match = rule_title_len;
c->isterminal = r->isterminal;
c->noswallow = r->noswallow;
c->isfloating = r->isfloating;
- c->tags |= r->tags;
+ c->tags = r->tags; // I don't want the rules to be additive
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;