aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-31 08:52:01 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-31 08:52:01 -0500
commit00ce50bf43b34ef9a66bc2ba0c64ba3d965ff6ea (patch)
treec8dd3e7685bf46f91bbe01ffa220542e881e2773
parent7dcc0ef3969f2bbfbee8846d0bddbd39ce197d93 (diff)
downloaddwm-00ce50bf43b34ef9a66bc2ba0c64ba3d965ff6ea.tar.gz
dwm-00ce50bf43b34ef9a66bc2ba0c64ba3d965ff6ea.tar.xz
Allow regexp matching for window title and class
-rw-r--r--config.def.h1
-rw-r--r--dwm.c4
-rw-r--r--util.c30
-rw-r--r--util.h1
4 files changed, 34 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index fa16868..83256f9 100644
--- a/config.def.h
+++ b/config.def.h
@@ -29,6 +29,7 @@ static const Rule rules[] = {
/* class instance title tags mask isfloating monitor */
{ "Gimp", NULL, NULL, 0, 1, -1 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ { "ch.*um", NULL, NULL, 1 << 8, 0, -1 },
};
/* layout(s) */
diff --git a/dwm.c b/dwm.c
index f9719ac..4b107d1 100644
--- a/dwm.c
+++ b/dwm.c
@@ -306,8 +306,8 @@ applyrules(Client *c)
for (i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
- if ((!r->title || strstr(c->name, r->title))
- && (!r->class || strstr(class, r->class))
+ if ((!r->title || reMatch(r->title, c->name) == 0)
+ && (!r->class || reMatch(r->class, class) == 0)
&& (!r->instance || strstr(instance, r->instance)))
{
c->isfloating = r->isfloating;
diff --git a/util.c b/util.c
index 96b82c9..06685ad 100644
--- a/util.c
+++ b/util.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <regex.h>
#include "util.h"
@@ -34,3 +35,32 @@ ecalloc(size_t nmemb, size_t size)
die("calloc:");
return p;
}
+
+int
+reMatch(const char *regex, const char *str) {
+ char reErr[1024] = {0};
+ regex_t *re = calloc(1, sizeof(regex_t));
+ int rc = 0;
+
+ if (!re)
+ return -1;
+
+ rc = regcomp(re, regex, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+ if (rc != 0) {
+ regerror(rc, re, reErr, 1024);
+ regfree(re); re = NULL;
+ fprintf(stderr, "Regex compile err: %s %s\n", regex, reErr);
+ return -1;
+ }
+
+ rc = regexec(re, str, 0, NULL, 0);
+ regfree(re); re = NULL;
+ if (rc != 0) {
+ regerror(rc, re, reErr, 1024);
+ fprintf(stderr, "Regex match error: %s -> %s : %s\n",
+ regex, str, reErr);
+ return -1;
+ }
+
+ return rc;
+}
diff --git a/util.h b/util.h
index f633b51..cd7c08d 100644
--- a/util.h
+++ b/util.h
@@ -6,3 +6,4 @@
void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
+int reMatch(const char *regex, const char *str);