dwm-ruleregex-20260508-44a91a2.diff (1630B)
1 From 44a91a205ebd86a5be6648a1e4a4a8f24aea2dd5 Mon Sep 17 00:00:00 2001 2 From: hamster3332 <malic.s@gmx.de> 3 Date: Fri, 8 May 2026 18:51:42 +0200 4 Subject: [PATCH] Dwm patch for using regular expressions for window rules 5 6 --- 7 dwm.c | 19 ++++++++++++++++--- 8 1 file changed, 16 insertions(+), 3 deletions(-) 9 10 diff --git a/dwm.c b/dwm.c 11 index ab3a84c..0cb186c 100644 12 --- a/dwm.c 13 +++ b/dwm.c 14 @@ -28,6 +28,7 @@ 15 #include <stdlib.h> 16 #include <string.h> 17 #include <unistd.h> 18 +#include <regex.h> 19 #include <sys/types.h> 20 #include <sys/wait.h> 21 #include <X11/cursorfont.h> 22 @@ -273,6 +274,18 @@ static Window root, wmcheckwin; 23 /* compile-time check if all tags fit into an unsigned int bit array. */ 24 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 25 26 +/* applying extended regex to string */ 27 +int applyregex(const char *str, const char *pattern) { 28 + regex_t re; 29 + int res = regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB); 30 + if (res != 0) return strstr(str, pattern) != NULL; 31 + 32 + res = regexec(&re, str, 0, NULL, 0); 33 + regfree(&re); 34 + 35 + return !res; 36 +} 37 + 38 /* function implementations */ 39 void 40 applyrules(Client *c) 41 @@ -292,9 +305,9 @@ applyrules(Client *c) 42 43 for (i = 0; i < LENGTH(rules); i++) { 44 r = &rules[i]; 45 - if ((!r->title || strstr(c->name, r->title)) 46 - && (!r->class || strstr(class, r->class)) 47 - && (!r->instance || strstr(instance, r->instance))) 48 + if ((!r->title || applyregex(c->name, r->title)) 49 + && (!r->class || applyregex(class, r->class)) 50 + && (!r->instance || applyregex(instance, r->instance))) 51 { 52 c->isfloating = r->isfloating; 53 c->tags |= r->tags; 54 -- 55 2.54.0 56