dwm-meillo

annotate tag.c @ 384:126e78129f1d

configurenotify remembers max geom now, and restores this if necessary, however it accepts to touch the max size on configurerequest, this shouldn't break fillscreen apps (tested with mplayer)
author Anselm R. Garbe <arg@10kloc.org>
date Tue, 29 Aug 2006 17:31:55 +0200
parents 2ec9cead84a7
children 6786cd59468f
rev   line source
garbeam@75 1 /*
garbeam@75 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@75 3 * See LICENSE file for license details.
garbeam@75 4 */
garbeam@76 5 #include "dwm.h"
arg@114 6 #include <regex.h>
arg@114 7 #include <stdio.h>
arg@191 8 #include <stdlib.h>
garbeam@75 9 #include <string.h>
arg@114 10 #include <sys/types.h>
garbeam@75 11 #include <X11/Xutil.h>
garbeam@75 12
garbeam@76 13
arg@114 14 typedef struct {
arg@191 15 const char *clpattern;
arg@191 16 const char *tpattern;
arg@114 17 Bool isfloat;
arg@114 18 } Rule;
arg@114 19
arg@191 20 typedef struct {
arg@191 21 regex_t *clregex;
arg@191 22 regex_t *tregex;
arg@191 23 } RReg;
arg@191 24
arg@191 25 /* static */
arg@191 26
arg@146 27 TAGS
arg@146 28 RULES
garbeam@84 29
arg@191 30 static RReg *rreg = NULL;
arg@191 31 static unsigned int len = 0;
arg@191 32
arg@383 33 static void
arg@384 34 commit()
arg@383 35 {
arg@383 36 /* asserts sel != NULL */
arg@383 37 settitle(sel);
arg@383 38 if(!isvisible(sel))
arg@383 39 arrange(NULL);
arg@383 40 else
arg@383 41 drawstatus();
arg@383 42 }
arg@383 43
arg@125 44 /* extern */
arg@125 45
garbeam@76 46 Client *
arg@142 47 getnext(Client *c)
garbeam@75 48 {
arg@261 49 for(; c && !isvisible(c); c = c->next);
garbeam@76 50 return c;
garbeam@75 51 }
garbeam@75 52
arg@127 53 Client *
arg@127 54 getprev(Client *c)
arg@127 55 {
arg@261 56 for(; c && !isvisible(c); c = c->prev);
arg@127 57 return c;
arg@127 58 }
arg@127 59
garbeam@75 60 void
arg@191 61 initrregs()
arg@191 62 {
arg@191 63 unsigned int i;
arg@191 64 regex_t *reg;
arg@191 65
arg@191 66 if(rreg)
arg@191 67 return;
arg@191 68 len = sizeof(rule) / sizeof(rule[0]);
arg@191 69 rreg = emallocz(len * sizeof(RReg));
arg@191 70
arg@191 71 for(i = 0; i < len; i++) {
arg@191 72 if(rule[i].clpattern) {
arg@191 73 reg = emallocz(sizeof(regex_t));
arg@191 74 if(regcomp(reg, rule[i].clpattern, 0))
arg@191 75 free(reg);
arg@191 76 else
arg@191 77 rreg[i].clregex = reg;
arg@191 78 }
arg@191 79 if(rule[i].tpattern) {
arg@191 80 reg = emallocz(sizeof(regex_t));
arg@191 81 if(regcomp(reg, rule[i].tpattern, 0))
arg@191 82 free(reg);
arg@191 83 else
arg@191 84 rreg[i].tregex = reg;
arg@191 85 }
arg@191 86 }
arg@191 87 }
arg@191 88
arg@270 89 void
garbeam@76 90 settags(Client *c)
garbeam@76 91 {
arg@336 92 char prop[512];
arg@191 93 unsigned int i, j;
arg@114 94 regmatch_t tmp;
garbeam@76 95 Bool matched = False;
arg@114 96 XClassHint ch;
garbeam@76 97
garbeam@76 98 if(XGetClassHint(dpy, c->win, &ch)) {
arg@336 99 snprintf(prop, sizeof(prop), "%s:%s:%s",
arg@114 100 ch.res_class ? ch.res_class : "",
arg@336 101 ch.res_name ? ch.res_name : "", c->name);
arg@191 102 for(i = 0; !matched && i < len; i++)
arg@336 103 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
arg@191 104 c->isfloat = rule[i].isfloat;
arg@191 105 for(j = 0; rreg[i].tregex && j < ntags; j++) {
arg@191 106 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
arg@191 107 matched = True;
arg@191 108 c->tags[j] = True;
arg@191 109 }
garbeam@76 110 }
arg@114 111 }
garbeam@76 112 if(ch.res_class)
garbeam@76 113 XFree(ch.res_class);
garbeam@76 114 if(ch.res_name)
garbeam@76 115 XFree(ch.res_name);
garbeam@76 116 }
garbeam@76 117 if(!matched)
arg@261 118 for(i = 0; i < ntags; i++)
arg@262 119 c->tags[i] = seltag[i];
arg@381 120 for(i = 0; i < ntags && !c->tags[i]; i++);
arg@381 121 c->weight = i;
garbeam@76 122 }
garbeam@76 123
garbeam@76 124 void
arg@284 125 tag(Arg *arg)
arg@284 126 {
arg@284 127 unsigned int i;
arg@284 128
arg@284 129 if(!sel)
arg@284 130 return;
arg@284 131
arg@284 132 for(i = 0; i < ntags; i++)
arg@284 133 sel->tags[i] = False;
arg@284 134 sel->tags[arg->i] = True;
arg@384 135 commit();
arg@284 136 }
arg@284 137
arg@284 138 void
arg@284 139 toggletag(Arg *arg)
arg@284 140 {
arg@284 141 unsigned int i;
arg@284 142
arg@284 143 if(!sel)
arg@284 144 return;
arg@284 145
arg@284 146 sel->tags[arg->i] = !sel->tags[arg->i];
arg@284 147 for(i = 0; i < ntags && !sel->tags[i]; i++);
arg@284 148 if(i == ntags)
arg@284 149 sel->tags[arg->i] = True;
arg@384 150 commit();
arg@284 151 }