dwm-meillo

changeset 114:dfa5cd0969a6

implemented regexp matching for rules
author arg@10ksloc.org
date Wed, 19 Jul 2006 17:42:08 +0200
parents b2445fd41f5e
children 329fd7dae530
files client.c dwm.h event.c tag.c
diffstat 4 files changed, 40 insertions(+), 32 deletions(-) [+]
line diff
     1.1 --- a/client.c	Wed Jul 19 16:38:39 2006 +0200
     1.2 +++ b/client.c	Wed Jul 19 17:42:08 2006 +0200
     1.3 @@ -247,8 +247,9 @@
     1.4  			GrabModeAsync, GrabModeSync, None, None);
     1.5  
     1.6  	if(!c->isfloat)
     1.7 -		c->isfloat = trans
     1.8 -			|| ((c->maxw == c->minw) && (c->maxh == c->minh));
     1.9 +		c->isfloat = trans || (c->maxw && c->minw &&
    1.10 +				(c->maxw == c->minw) && (c->maxh == c->minh));
    1.11 +
    1.12  
    1.13  	setgeom(c);
    1.14  	settitle(c);
     2.1 --- a/dwm.h	Wed Jul 19 16:38:39 2006 +0200
     2.2 +++ b/dwm.h	Wed Jul 19 17:42:08 2006 +0200
     2.3 @@ -30,8 +30,6 @@
     2.4  typedef enum Corner Corner;
     2.5  typedef struct DC DC;
     2.6  typedef struct Fnt Fnt;
     2.7 -typedef struct Key Key;
     2.8 -typedef struct Rule Rule;
     2.9  
    2.10  union Arg {
    2.11  	const char **argv;
    2.12 @@ -84,20 +82,6 @@
    2.13  	Window title;
    2.14  };
    2.15  
    2.16 -struct Rule {
    2.17 -	const char *class;
    2.18 -	const char *instance;
    2.19 -	char *tags[TLast];
    2.20 -	Bool isfloat;
    2.21 -};
    2.22 -
    2.23 -struct Key {
    2.24 -	unsigned long mod;
    2.25 -	KeySym keysym;
    2.26 -	void (*func)(Arg *arg);
    2.27 -	Arg arg;
    2.28 -};
    2.29 -
    2.30  extern char *tags[TLast], stext[1024];
    2.31  extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
    2.32  extern void (*handler[LASTEvent])(XEvent *);
    2.33 @@ -108,7 +92,6 @@
    2.34  extern Cursor cursor[CurLast];
    2.35  extern DC dc;
    2.36  extern Display *dpy;
    2.37 -extern Key key[];
    2.38  extern Window root, barwin;
    2.39  
    2.40  /* client.c */
     3.1 --- a/event.c	Wed Jul 19 16:38:39 2006 +0200
     3.2 +++ b/event.c	Wed Jul 19 17:42:08 2006 +0200
     3.3 @@ -12,6 +12,14 @@
     3.4  #define MouseMask       (ButtonMask | PointerMotionMask)
     3.5  
     3.6  /* CUSTOMIZE */
     3.7 +
     3.8 +typedef struct {
     3.9 +	unsigned long mod;
    3.10 +	KeySym keysym;
    3.11 +	void (*func)(Arg *arg);
    3.12 +	Arg arg;
    3.13 +} Key;
    3.14 +
    3.15  const char *browse[] = { "firefox", NULL };
    3.16  const char *gimp[] = { "gimp", NULL };
    3.17  const char *term[] = { 
    3.18 @@ -20,7 +28,7 @@
    3.19  };
    3.20  const char *xlock[] = { "xlock", NULL };
    3.21  
    3.22 -Key key[] = {
    3.23 +static Key key[] = {
    3.24  	/* modifier				key			function	arguments */
    3.25  	{ ControlMask,			XK_0,		appendtag,	{ .i = Tscratch } }, 
    3.26  	{ ControlMask,			XK_1,		appendtag,	{ .i = Tdev } }, 
     4.1 --- a/tag.c	Wed Jul 19 16:38:39 2006 +0200
     4.2 +++ b/tag.c	Wed Jul 19 17:42:08 2006 +0200
     4.3 @@ -4,15 +4,25 @@
     4.4   */
     4.5  #include "dwm.h"
     4.6  
     4.7 +#include <regex.h>
     4.8 +#include <stdio.h>
     4.9  #include <string.h>
    4.10 +#include <sys/types.h>
    4.11  #include <X11/Xutil.h>
    4.12  
    4.13  /* static */
    4.14  
    4.15 +typedef struct {
    4.16 +	const char *pattern;
    4.17 +	char *tags[TLast];
    4.18 +	Bool isfloat;
    4.19 +} Rule;
    4.20 +
    4.21  /* CUSTOMIZE */ 
    4.22  static Rule rule[] = {
    4.23 -	/* class			instance	tags						isfloat */
    4.24 -	{ "Firefox-bin",	"firefox-bin",	{ [Twww] = "www" },			False },
    4.25 +	/* class			instance	tags		isfloat */
    4.26 +	{ "Firefox.*",	{ [Twww] = "www" },			False },
    4.27 +	{ "Gimp.*",		{ 0 },						True},
    4.28  };
    4.29  
    4.30  /* extern */
    4.31 @@ -164,10 +174,13 @@
    4.32  void
    4.33  settags(Client *c)
    4.34  {
    4.35 -	XClassHint ch;
    4.36 +	char classinst[256];
    4.37  	static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
    4.38  	unsigned int i, j;
    4.39 +	regex_t regex;
    4.40 +	regmatch_t tmp;
    4.41  	Bool matched = False;
    4.42 +	XClassHint ch;
    4.43  
    4.44  	if(!len) {
    4.45  		c->tags[tsel] = tags[tsel];
    4.46 @@ -175,24 +188,27 @@
    4.47  	}
    4.48  
    4.49  	if(XGetClassHint(dpy, c->win, &ch)) {
    4.50 -		if(ch.res_class && ch.res_name) {
    4.51 -			for(i = 0; i < len; i++)
    4.52 -				if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
    4.53 -					&& !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
    4.54 -				{
    4.55 -					for(j = 0; j < TLast; j++)
    4.56 +		snprintf(classinst, sizeof(classinst), "%s:%s",
    4.57 +				ch.res_class ? ch.res_class : "",
    4.58 +				ch.res_name ? ch.res_name : "");
    4.59 +		for(i = 0; !matched && i < len; i++) {
    4.60 +			if(!regcomp(&regex, rule[i].pattern, 0)) {
    4.61 +				if(!regexec(&regex, classinst, 1, &tmp, 0)) {
    4.62 +					for(j = 0; j < TLast; j++) {
    4.63 +						if(rule[i].tags[j])
    4.64 +							matched = True;
    4.65  						c->tags[j] = rule[i].tags[j];
    4.66 +					}
    4.67  					c->isfloat = rule[i].isfloat;
    4.68 -					matched = True;
    4.69 -					break;
    4.70  				}
    4.71 +				regfree(&regex);
    4.72 +			}
    4.73  		}
    4.74  		if(ch.res_class)
    4.75  			XFree(ch.res_class);
    4.76  		if(ch.res_name)
    4.77  			XFree(ch.res_name);
    4.78  	}
    4.79 -
    4.80  	if(!matched)
    4.81  		c->tags[tsel] = tags[tsel];
    4.82  }