summaryrefslogtreecommitdiffstats
path: root/dwl.c
diff options
context:
space:
mode:
authorwochap <gean.marroquin@gmail.com>2024-04-11 12:45:47 -0500
committerSquibid <me@zacharyscheiman.com>2025-02-12 00:27:20 -0600
commit3a912ae2b4e99507d8c3b1ce0add52f9043fa055 (patch)
tree9d0ee415082d2ec413c952e67ae9f083a65e2267 /dwl.c
parentce17d0f303a11a8eaaf1a78202002b111bec9008 (diff)
downloaddwl-3a912ae2b4e99507d8c3b1ce0add52f9043fa055.tar.gz
dwl-3a912ae2b4e99507d8c3b1ce0add52f9043fa055.tar.bz2
dwl-3a912ae2b4e99507d8c3b1ce0add52f9043fa055.zip
implement regex support in rules for app_id and title Enables the use of regular expressions for window rules "app_id" and "title"
Diffstat (limited to '')
-rw-r--r--dwl.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/dwl.c b/dwl.c
index 44796b9..6d4ba98 100644
--- a/dwl.c
+++ b/dwl.c
@@ -11,6 +11,7 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
+#include <regex.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
@@ -402,6 +403,7 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
+static int regex_match(const char *pattern, const char *str);
/* variables */
static pid_t child_pid = -1;
@@ -551,8 +553,8 @@ applyrules(Client *c)
title = client_get_title(c);
for (r = rules; r < END(rules); r++) {
- if ((!r->title || strstr(title, r->title))
- && (!r->id || strstr(appid, r->id))) {
+ if ((!r->title || regex_match(r->title, title))
+ && (!r->id || regex_match(r->id, appid))) {
c->isfloating = r->isfloating;
newtags |= r->tags;
i = 0;
@@ -3519,6 +3521,19 @@ zoom(const Arg *arg)
arrange(selmon);
}
+int
+regex_match(const char *pattern, const char *str) {
+ regex_t regex;
+ int reti;
+ if (regcomp(&regex, pattern, REG_EXTENDED) != 0)
+ return 0;
+ reti = regexec(&regex, str, (size_t)0, NULL, 0);
+ regfree(&regex);
+ if (reti == 0)
+ return 1;
+ return 0;
+}
+
#ifdef XWAYLAND
void
activatex11(struct wl_listener *listener, void *data)