Mercurial > aewl
comparison aewl.c @ 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 |
comparison
equal
deleted
inserted
replaced
766:3f7c68a720b5 | 767:706991d15451 |
---|---|
42 | 42 |
43 | 43 |
44 #include "config.h" | 44 #include "config.h" |
45 #include <errno.h> | 45 #include <errno.h> |
46 #include <locale.h> | 46 #include <locale.h> |
47 #include <regex.h> | |
48 #include <stdio.h> | 47 #include <stdio.h> |
49 #include <stdarg.h> | 48 #include <stdarg.h> |
50 #include <stdlib.h> | 49 #include <stdlib.h> |
51 #include <string.h> | 50 #include <string.h> |
52 #include <unistd.h> | 51 #include <unistd.h> |
101 Client *snext; | 100 Client *snext; |
102 Window win; | 101 Window win; |
103 }; | 102 }; |
104 | 103 |
105 typedef struct { | 104 typedef struct { |
106 const char *clpattern; | 105 const char* class; |
106 const char* instance; | |
107 const char* title; | |
107 int tag; | 108 int tag; |
108 Bool isfloat; | 109 Bool isfloat; |
109 } Rule; | 110 } Rule; |
110 | |
111 typedef struct { | |
112 regex_t *clregex; | |
113 } RReg; | |
114 | 111 |
115 | 112 |
116 typedef struct { | 113 typedef struct { |
117 unsigned long mod; | 114 unsigned long mod; |
118 KeySym keysym; | 115 KeySym keysym; |
149 Client *stack = NULL; | 146 Client *stack = NULL; |
150 DC dc = {0}; | 147 DC dc = {0}; |
151 | 148 |
152 static int (*xerrorxlib)(Display *, XErrorEvent *); | 149 static int (*xerrorxlib)(Display *, XErrorEvent *); |
153 static Bool otherwm, readin; | 150 static Bool otherwm, readin; |
154 static RReg *rreg = NULL; | |
155 static unsigned int len = 0; | 151 static unsigned int len = 0; |
156 | 152 |
157 | 153 |
158 RULES | 154 RULES |
159 | 155 |
182 /* main.c */ | 178 /* main.c */ |
183 void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ | 179 void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ |
184 int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ | 180 int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
185 | 181 |
186 /* tag.c */ | 182 /* tag.c */ |
187 void initrregs(void); /* initialize regexps of rules defined in config.h */ | |
188 Client *getnext(Client *c); /* returns next visible client */ | 183 Client *getnext(Client *c); /* returns next visible client */ |
189 void settag(Client *c, Client *trans); /* sets tag of c */ | 184 void settag(Client *c, Client *trans); /* sets tag of c */ |
190 | 185 |
191 /* util.c */ | 186 /* util.c */ |
192 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ | 187 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
565 for(; c && !isvisible(c); c = c->next); | 560 for(; c && !isvisible(c); c = c->next); |
566 return c; | 561 return c; |
567 } | 562 } |
568 | 563 |
569 void | 564 void |
570 initrregs(void) { | 565 settag(Client *c, Client *trans) { |
571 unsigned int i; | 566 unsigned int i; |
572 regex_t *reg; | 567 XClassHint ch = { 0 }; |
573 | 568 |
574 if(rreg) | 569 if(trans) { |
575 return; | 570 c->tag = trans->tag; |
571 return; | |
572 } | |
573 c->tag = seltag; /* default */ | |
574 XGetClassHint(dpy, c->win, &ch); | |
576 len = sizeof rule / sizeof rule[0]; | 575 len = sizeof rule / sizeof rule[0]; |
577 rreg = emallocz(len * sizeof(RReg)); | |
578 for(i = 0; i < len; i++) { | 576 for(i = 0; i < len; i++) { |
579 if(rule[i].clpattern) { | 577 if((rule[i].title && strstr(c->name, rule[i].title)) |
580 reg = emallocz(sizeof(regex_t)); | 578 || (ch.res_class && rule[i].class && strstr(ch.res_class, rule[i].class)) |
581 if(regcomp(reg, rule[i].clpattern, REG_EXTENDED)) | 579 || (ch.res_name && rule[i].instance && strstr(ch.res_name, rule[i].instance))) { |
582 free(reg); | 580 c->isfloat = rule[i].isfloat; |
583 else | 581 if (rule[i].tag < 0) { |
584 rreg[i].clregex = reg; | 582 c->tag = seltag; |
585 } | 583 } else if (rule[i].tag) { |
586 } | 584 c->tag = True; |
587 } | 585 } else { |
588 | 586 c->tag = False; |
589 void | |
590 settag(Client *c, Client *trans) { | |
591 char prop[512]; | |
592 unsigned int i; | |
593 regmatch_t tmp; | |
594 Bool matched = (trans != NULL); | |
595 XClassHint ch = { 0 }; | |
596 | |
597 if(matched) { | |
598 c->tag = trans->tag; | |
599 } else { | |
600 XGetClassHint(dpy, c->win, &ch); | |
601 snprintf(prop, sizeof prop, "%s:%s:%s", | |
602 ch.res_class ? ch.res_class : "", | |
603 ch.res_name ? ch.res_name : "", c->name); | |
604 for(i = 0; i < len && !matched; i++) | |
605 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { | |
606 c->isfloat = rule[i].isfloat; | |
607 if (rule[i].tag < 0) { | |
608 c->tag = seltag; | |
609 } else if (rule[i].tag) { | |
610 c->tag = True; | |
611 } else { | |
612 c->tag = False; | |
613 } | |
614 matched = True; | |
615 } | 587 } |
616 if(ch.res_class) | 588 break; |
617 XFree(ch.res_class); | 589 } |
618 if(ch.res_name) | 590 } |
619 XFree(ch.res_name); | 591 if(ch.res_class) |
620 } | 592 XFree(ch.res_class); |
621 if(!matched) { | 593 if(ch.res_name) |
622 c->tag = seltag; | 594 XFree(ch.res_name); |
623 } | |
624 } | 595 } |
625 | 596 |
626 void | 597 void |
627 toggletag() { | 598 toggletag() { |
628 if(!sel) | 599 if(!sel) |
1590 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | 1561 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
1591 | EnterWindowMask | LeaveWindowMask; | 1562 | EnterWindowMask | LeaveWindowMask; |
1592 wa.cursor = cursor[CurNormal]; | 1563 wa.cursor = cursor[CurNormal]; |
1593 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); | 1564 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
1594 grabkeys(); | 1565 grabkeys(); |
1595 initrregs(); | |
1596 seltag = True; | 1566 seltag = True; |
1597 /* style */ | 1567 /* style */ |
1598 dc.norm[ColBG] = getcolor(NORMBGCOLOR); | 1568 dc.norm[ColBG] = getcolor(NORMBGCOLOR); |
1599 dc.norm[ColFG] = getcolor(NORMFGCOLOR); | 1569 dc.norm[ColFG] = getcolor(NORMFGCOLOR); |
1600 dc.sel[ColBG] = getcolor(SELBGCOLOR); | 1570 dc.sel[ColBG] = getcolor(SELBGCOLOR); |