dwm-ruleregex-20261011-a83e54e.diff (2327B)
1 From bf78dff9137dd705bfd15319a2ce0318fc122852 Mon Sep 17 00:00:00 2001 2 From: MaliCopter <mali.copter@gmx.de> 3 Date: Sat, 10 Oct 2026 16:55:11 +0200 4 Subject: [PATCH 1/2] Rewrote Ruleregex patch for cleaner code 5 6 --- 7 dwm.c | 21 ++++++++++++++++++--- 8 1 file changed, 18 insertions(+), 3 deletions(-) 9 10 diff --git a/dwm.c b/dwm.c 11 index ab3a84c..3ac731c 100644 12 --- a/dwm.c 13 +++ b/dwm.c 14 @@ -274,6 +274,21 @@ static Window root, wmcheckwin; 15 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 16 17 /* function implementations */ 18 +int 19 +applyregex(const char *name, const char *pattern) 20 +{ 21 + regex_t re; 22 + int result; 23 + 24 + if (regcomp(&re, pattern, REG_EXTENDED) != 0) goto fail; 25 + result = regexec(&re, name, 0, NULL, 0); 26 + regfree(&re); 27 + if (result == 0) return 1; 28 + 29 + fail: 30 + return strstr(name, pattern) != NULL; 31 +} 32 + 33 void 34 applyrules(Client *c) 35 { 36 @@ -292,9 +307,9 @@ applyrules(Client *c) 37 38 for (i = 0; i < LENGTH(rules); i++) { 39 r = &rules[i]; 40 - if ((!r->title || strstr(c->name, r->title)) 41 - && (!r->class || strstr(class, r->class)) 42 - && (!r->instance || strstr(instance, r->instance))) 43 + if ((!r->title || applyregex(c->name, r->title)) 44 + && (!r->class || applyregex(class, r->class)) 45 + && (!r->instance || applyregex(instance, r->instance))) 46 { 47 c->isfloating = r->isfloating; 48 c->tags |= r->tags; 49 -- 50 2.55.0 51 52 53 From a83e54e545d4766dcc18c27be35e7689d9a9ca95 Mon Sep 17 00:00:00 2001 54 From: MaliCopter <mali.copter@gmx.de> 55 Date: Sun, 11 Oct 2026 13:54:15 +0200 56 Subject: [PATCH 2/2] dwm ruleregex (hopefully) final fix 57 58 --- 59 dwm.c | 7 ++++--- 60 1 file changed, 4 insertions(+), 3 deletions(-) 61 62 diff --git a/dwm.c b/dwm.c 63 index 3ac731c..aea3cc4 100644 64 --- a/dwm.c 65 +++ b/dwm.c 66 @@ -28,6 +28,7 @@ 67 #include <stdlib.h> 68 #include <string.h> 69 #include <unistd.h> 70 +#include <regex.h> 71 #include <sys/types.h> 72 #include <sys/wait.h> 73 #include <X11/cursorfont.h> 74 @@ -280,13 +281,13 @@ applyregex(const char *name, const char *pattern) 75 regex_t re; 76 int result; 77 78 - if (regcomp(&re, pattern, REG_EXTENDED) != 0) goto fail; 79 + result = regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB); 80 + if (result != 0) return strstr(name, pattern) != NULL; 81 result = regexec(&re, name, 0, NULL, 0); 82 regfree(&re); 83 if (result == 0) return 1; 84 85 - fail: 86 - return strstr(name, pattern) != NULL; 87 + return 0; 88 } 89 90 void 91 -- 92 2.55.0