aewl

changeset 767:706991d15451

removed rexexp for old strstr matching; simplifications
author meillo@marmaro.de
date Fri, 05 Dec 2008 20:50:31 +0100
parents 3f7c68a720b5
children a1c6805aa018
files aewl.c config.h
diffstat 2 files changed, 33 insertions(+), 62 deletions(-) [+]
line diff
     1.1 --- a/aewl.c	Fri Dec 05 19:43:56 2008 +0100
     1.2 +++ b/aewl.c	Fri Dec 05 20:50:31 2008 +0100
     1.3 @@ -44,7 +44,6 @@
     1.4  #include "config.h"
     1.5  #include <errno.h>
     1.6  #include <locale.h>
     1.7 -#include <regex.h>
     1.8  #include <stdio.h>
     1.9  #include <stdarg.h>
    1.10  #include <stdlib.h>
    1.11 @@ -103,15 +102,13 @@
    1.12  };
    1.13  
    1.14  typedef struct {
    1.15 -	const char *clpattern;
    1.16 +	const char* class;
    1.17 +	const char* instance;
    1.18 +	const char* title;
    1.19  	int tag;
    1.20  	Bool isfloat;
    1.21  } Rule;
    1.22  
    1.23 -typedef struct {
    1.24 -	regex_t *clregex;
    1.25 -} RReg;
    1.26 -
    1.27  
    1.28  typedef struct {
    1.29  	unsigned long mod;
    1.30 @@ -151,7 +148,6 @@
    1.31  
    1.32  static int (*xerrorxlib)(Display *, XErrorEvent *);
    1.33  static Bool otherwm, readin;
    1.34 -static RReg *rreg = NULL;
    1.35  static unsigned int len = 0;
    1.36  
    1.37  
    1.38 @@ -184,7 +180,6 @@
    1.39  int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
    1.40  
    1.41  /* tag.c */
    1.42 -void initrregs(void);			/* initialize regexps of rules defined in config.h */
    1.43  Client *getnext(Client *c);		/* returns next visible client */
    1.44  void settag(Client *c, Client *trans);	/* sets tag of c */
    1.45  
    1.46 @@ -567,60 +562,36 @@
    1.47  }
    1.48  
    1.49  void
    1.50 -initrregs(void) {
    1.51 +settag(Client *c, Client *trans) {
    1.52  	unsigned int i;
    1.53 -	regex_t *reg;
    1.54 +	XClassHint ch = { 0 };
    1.55  
    1.56 -	if(rreg)
    1.57 +	if(trans) {
    1.58 +		c->tag = trans->tag;
    1.59  		return;
    1.60 +	}
    1.61 +	c->tag = seltag;  /* default */
    1.62 +	XGetClassHint(dpy, c->win, &ch);
    1.63  	len = sizeof rule / sizeof rule[0];
    1.64 -	rreg = emallocz(len * sizeof(RReg));
    1.65  	for(i = 0; i < len; i++) {
    1.66 -		if(rule[i].clpattern) {
    1.67 -			reg = emallocz(sizeof(regex_t));
    1.68 -			if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
    1.69 -				free(reg);
    1.70 -			else
    1.71 -				rreg[i].clregex = reg;
    1.72 +		if((rule[i].title && strstr(c->name, rule[i].title))
    1.73 +		   || (ch.res_class && rule[i].class && strstr(ch.res_class, rule[i].class))
    1.74 +		   || (ch.res_name && rule[i].instance && strstr(ch.res_name, rule[i].instance))) {
    1.75 +			c->isfloat = rule[i].isfloat;
    1.76 +			if (rule[i].tag < 0) {
    1.77 +				c->tag = seltag;
    1.78 +			} else if (rule[i].tag) {
    1.79 +				c->tag = True;
    1.80 +			} else {
    1.81 +				c->tag = False;
    1.82 +			}
    1.83 +			break;
    1.84  		}
    1.85  	}
    1.86 -}
    1.87 -
    1.88 -void
    1.89 -settag(Client *c, Client *trans) {
    1.90 -	char prop[512];
    1.91 -	unsigned int i;
    1.92 -	regmatch_t tmp;
    1.93 -	Bool matched = (trans != NULL);
    1.94 -	XClassHint ch = { 0 };
    1.95 -
    1.96 -	if(matched) {
    1.97 -		c->tag = trans->tag;
    1.98 -	} else {
    1.99 -		XGetClassHint(dpy, c->win, &ch);
   1.100 -		snprintf(prop, sizeof prop, "%s:%s:%s",
   1.101 -				ch.res_class ? ch.res_class : "",
   1.102 -				ch.res_name ? ch.res_name : "", c->name);
   1.103 -		for(i = 0; i < len && !matched; i++)
   1.104 -			if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
   1.105 -				c->isfloat = rule[i].isfloat;
   1.106 -				if (rule[i].tag < 0) {
   1.107 -					c->tag = seltag;
   1.108 -				} else if (rule[i].tag) {
   1.109 -					c->tag = True;
   1.110 -				} else {
   1.111 -					c->tag = False;
   1.112 -				}
   1.113 -				matched = True;
   1.114 -			}
   1.115 -		if(ch.res_class)
   1.116 -			XFree(ch.res_class);
   1.117 -		if(ch.res_name)
   1.118 -			XFree(ch.res_name);
   1.119 -	}
   1.120 -	if(!matched) {
   1.121 -		c->tag = seltag;
   1.122 -	}
   1.123 +	if(ch.res_class)
   1.124 +		XFree(ch.res_class);
   1.125 +	if(ch.res_name)
   1.126 +		XFree(ch.res_name);
   1.127  }
   1.128  
   1.129  void
   1.130 @@ -1592,7 +1563,6 @@
   1.131  	wa.cursor = cursor[CurNormal];
   1.132  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   1.133  	grabkeys();
   1.134 -	initrregs();
   1.135  	seltag = True;
   1.136  	/* style */
   1.137  	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
     2.1 --- a/config.h	Fri Dec 05 19:43:56 2008 +0100
     2.2 +++ b/config.h	Fri Dec 05 20:50:31 2008 +0100
     2.3 @@ -43,10 +43,11 @@
     2.4   * xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/ { printf("%s\n",$2) }' */
     2.5  #define RULES \
     2.6  static Rule rule[] = { \
     2.7 -	/* class:instance:title regex, tag (1=tag/0=untag/-1=curr), isfloat */ \
     2.8 -	{ "URxvt.*",	  	  	0,	    	False }, \
     2.9 -	{ "MPlayer.*",		  	-1,	    	True }, \
    2.10 -	{ "qiv.*",		  	    -1,	    	False }, \
    2.11 -	{ "Gimp.*",	      		1,		True }, \
    2.12 -	{ ".*",		          	1,	    	False }, \
    2.13 +	/* class, instance, title, tag (1=tag/0=untag/-1=curr), isfloat */ \
    2.14 +	{ "URxvt", NULL, NULL,	  	  	0,	    	False }, \
    2.15 +	{ "urxvt", NULL, NULL,	  	  	0,	    	False }, \
    2.16 +	{ "MPlayer", NULL, NULL,	  	-1,	    	True }, \
    2.17 +	{  NULL, "qiv", NULL,	  	    -1,	    	False }, \
    2.18 +	{ "Gimp", NULL, NULL,	      		1,		True }, \
    2.19 +	{ "", "", "",		          	1,	    	False }, \
    2.20  };