sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-ruleregex-20261010-bf78dff.diff (1342B)


      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] 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