aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-12-28 00:27:22 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2022-12-28 00:27:22 -0500
commit3398d028c61165c219bf9361f5b81d3a54e968c8 (patch)
treefcf6bbb62c7d0d6bb86a58e0db4eb3d74356c9e1
parentf2d52d23f74c065f288d9d4b399404fe50f38fc3 (diff)
downloaddwm-3398d028c61165c219bf9361f5b81d3a54e968c8.tar.gz
dwm-3398d028c61165c219bf9361f5b81d3a54e968c8.tar.xz
Use regular expressions for tagging windows by class and name
-rw-r--r--.gitignore3
-rw-r--r--config.h24
-rw-r--r--dwm.c6
-rw-r--r--util2.c53
-rw-r--r--util2.h24
5 files changed, 71 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..80baf9b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+tags
+dwm
diff --git a/config.h b/config.h
index abeeaee..f0c2cc7 100644
--- a/config.h
+++ b/config.h
@@ -37,18 +37,18 @@ static const Rule rules[] = {
* WM_NAME(STRING) = title
*/
/* class instance title tags mask isfloating monitor */
- { "St", NULL, NULL, 1<<0, 0, -1 },
- { "Gimp", NULL, NULL, 1<<2, 0, -1 },
- { "Pavucontrol", NULL, NULL, 1<<6, 0, -1 },
- { "Blueman-manager",NULL, NULL, 1<<6, 0, -1 },
- { "Claws-mail", NULL, NULL, 1<<7, 0, -1 },
- { "Evolution", NULL, NULL, 1<<7, 0, -1 },
- { "Zotero", NULL, NULL, 1<<7, 0, -1 },
- { "Google-chrome", NULL, NULL, 1<<8, 0, -1 },
- { "Chromium", NULL, NULL, 1<<8, 0, -1 },
- { "Firefox", NULL, NULL, 1<<8, 0, -1 },
- { "firefox", NULL, NULL, 1<<8, 0, -1 },
- { "code-oss", NULL, NULL, 1<<1, 0, -1 },
+ { "^St$", NULL, NULL, 1<<0, 0, -1 },
+ { "^Gimp$", NULL, NULL, 1<<2, 0, -1 },
+ { "^Pavucontrol$", NULL, NULL, 1<<6, 0, -1 },
+ { "^Blueman-manager$",NULL, NULL, 1<<6, 0, -1 },
+ { "^Claws-mail$", NULL, NULL, 1<<7, 0, -1 },
+ { "^Evolution$", NULL, NULL, 1<<7, 0, -1 },
+ { "^Zotero$", NULL, NULL, 1<<7, 0, -1 },
+ { "^Google-chrome$", NULL, NULL, 1<<8, 0, -1 },
+ { "^Chromium$", NULL, NULL, 1<<8, 0, -1 },
+ { "^Firefox$", NULL, NULL, 1<<8, 0, -1 },
+ { "^code-oss$", NULL, NULL, 1<<1, 0, -1 },
+ { "^jetbrains.*$", NULL, NULL, 1<<2, 0, -1 },
};
/* layout(s) */
diff --git a/dwm.c b/dwm.c
index ee4137f..67955f6 100644
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,7 @@
#include "drw.h"
#include "util.h"
-#include "util2.h"
+#include "util2.c"
/* macros */
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
@@ -298,8 +298,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/util2.c b/util2.c
new file mode 100644
index 0000000..1ce2c55
--- /dev/null
+++ b/util2.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <err.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <regex.h>
+
+int
+readEnv(FILE *fh)
+{
+ int ret;
+ char name[1024], value[8192];
+
+ while (1) {
+ if ((ret = fscanf(fh, "%1023[^=]=%8191[^\n]\n", &name, &value)) == EOF)
+ break;
+ else if (ret == 0)
+ break;
+
+ fprintf(stderr, "Setting: '%s' = '%s'\n", name, value);
+ setenv(name, value, 1);
+ }
+
+ return 0;
+}
+
+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);
+ fprintf(stderr, "Regex compile err: %s %s\n", regex, reErr);
+ return -1;
+ }
+
+ rc = regexec(re, str, 0, NULL, 0);
+ regfree(re);
+ 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/util2.h b/util2.h
deleted file mode 100644
index ab25acf..0000000
--- a/util2.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <fcntl.h>
-#include <err.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-int
-readEnv(FILE *fh)
-{
- int ret;
- char name[1024], value[8192];
-
- while (1) {
- if ((ret = fscanf(fh, "%1023[^=]=%8191[^\n]\n", &name, &value)) == EOF)
- break;
- else if (ret == 0)
- break;
-
- fprintf(stderr, "Setting: '%s' = '%s'\n", name, value);
- setenv(name, value, 1);
- }
-
- return 0;
-}