From c5333e44d94f9d3cf439ac7e257d64f3f3014cfb Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 21 Dec 2025 16:19:15 +0100 Subject: [PATCH] Allow applying custom logic applycustomrules I will use this for custom rules for opening programs just the first time or putting them to a specific tag when opened second time and so on. --- config.def.h | 6 ++++++ dwl.c | 38 +++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/config.def.h b/config.def.h index 63005316c28ccb0119d8daf1aa85fdbc4344d161..ffc55be04dbba89fa78c8700cce5ac5dc8e207c9 100644 --- a/config.def.h +++ b/config.def.h @@ -217,3 +217,9 @@ static const Button buttons[] = { { MODKEY, BTN_MIDDLE, togglefloating, {0} }, { MODKEY, BTN_RIGHT, moveresize, {.ui = CurResize} }, }; + +bool applycustomrules(const char *appid, const char *title, Rule *r) +{ + // TODO: apply any rules you wish + return false; +} diff --git a/dwl.c b/dwl.c index cef9b8a469dde502d68769e31bb8089eb7c8ff91..ad242068b633e75fec9696f128e96b1c2e2184a1 100644 --- a/dwl.c +++ b/dwl.c @@ -261,7 +261,7 @@ typedef struct { int noswallow; int allow_activation; int monitor; - const char scratchkey; + char scratchkey; } Rule; typedef struct { @@ -585,7 +585,7 @@ applyrules(Client *c) const char *appid, *title; uint32_t newtags = 0; int i; - const Rule *r; + Rule *r; Monitor *mon = selmon, *m; c->scratchkey = 0; @@ -594,23 +594,35 @@ applyrules(Client *c) c->pid = client_get_pid(c); + void + applyrule(const Rule *r) + { + c->isfloating = r->isfloating; + c->isterm = r->isterm; + c->noswallow = r->noswallow; + c->scratchkey = r->scratchkey; + c->allow_activation = r->allow_activation; + newtags |= r->tags; + i = 0; + wl_list_for_each(m, &mons, link) { + if (r->monitor == i++) + mon = m; + } + } + for (r = rules; r < END(rules); r++) { if ((!r->title || strstr(title, r->title)) && (!r->id || strstr(appid, r->id))) { - c->isfloating = r->isfloating; - c->isterm = r->isterm; - c->noswallow = r->noswallow; - c->scratchkey = r->scratchkey; - c->allow_activation = r->allow_activation; - newtags |= r->tags; - i = 0; - wl_list_for_each(m, &mons, link) { - if (r->monitor == i++) - mon = m; - } + applyrule(r); } } + // Reset the rule. + Rule rule = (Rule) { NULL, NULL, 0, 0, 0, 0, -1, 0 }; + if (applycustomrules(appid, title, &rule)) { + applyrule(&rule); + } + wl_list_for_each(m, &mons, link) { // tag with different monitor selected by rules if (m->tagset[m->seltags] & newtags) {