diff options
| author | Anselm R. Garbe <garbeam@gmail.com> | 2007-08-18 13:48:05 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@gmail.com> | 2007-08-18 13:48:05 +0200 |
| commit | 50be6c8b67c500ee4aa07919609fa80785fd389d (patch) | |
| tree | b6cb11170b9273e079a536e6a70c6d8d5bcb7e98 | |
| parent | applied Gottox mwfact patch (diff) | |
| download | dwm-50be6c8b67c500ee4aa07919609fa80785fd389d.tar.gz dwm-50be6c8b67c500ee4aa07919609fa80785fd389d.zip | |
cleaned up settags-handling
| -rw-r--r-- | client.c | 45 | ||||
| -rw-r--r-- | dwm.h | 4 | ||||
| -rw-r--r-- | layout.c | 18 | ||||
| -rw-r--r-- | tag.c | 104 |
4 files changed, 90 insertions, 81 deletions
| @@ -7,6 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | /* static */ | 8 | /* static */ |
| 9 | 9 | ||
| 10 | static char config[128]; | ||
| 11 | |||
| 10 | static void | 12 | static void |
| 11 | attachstack(Client *c) { | 13 | attachstack(Client *c) { |
| 12 | c->snext = stack; | 14 | c->snext = stack; |
| @@ -179,8 +181,31 @@ killclient(const char *arg) { | |||
| 179 | XKillClient(dpy, sel->win); | 181 | XKillClient(dpy, sel->win); |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 184 | Bool | ||
| 185 | loadconfig(Client *c) { | ||
| 186 | unsigned int i; | ||
| 187 | Bool result = False; | ||
| 188 | XTextProperty name; | ||
| 189 | |||
| 190 | /* check if window has set a property */ | ||
| 191 | name.nitems = 0; | ||
| 192 | XGetTextProperty(dpy, c->win, &name, dwmconfig); | ||
| 193 | if(name.nitems && name.encoding == XA_STRING) { | ||
| 194 | strncpy(config, (char *)name.value, sizeof config - 1); | ||
| 195 | config[sizeof config - 1] = '\0'; | ||
| 196 | XFree(name.value); | ||
| 197 | for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++) | ||
| 198 | if((c->tags[i] = config[i] == '1')) | ||
| 199 | result = True; | ||
| 200 | if(i < sizeof config - 1 && config[i] != '\0') | ||
| 201 | c->isfloating = config[i] == '1'; | ||
| 202 | } | ||
| 203 | return result; | ||
| 204 | } | ||
| 205 | |||
| 182 | void | 206 | void |
| 183 | manage(Window w, XWindowAttributes *wa) { | 207 | manage(Window w, XWindowAttributes *wa) { |
| 208 | unsigned int i; | ||
| 184 | Client *c, *t = NULL; | 209 | Client *c, *t = NULL; |
| 185 | Window trans; | 210 | Window trans; |
| 186 | Status rettrans; | 211 | Status rettrans; |
| @@ -221,9 +246,14 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 221 | updatetitle(c); | 246 | updatetitle(c); |
| 222 | if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success)) | 247 | if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success)) |
| 223 | for(t = clients; t && t->win != trans; t = t->next); | 248 | for(t = clients; t && t->win != trans; t = t->next); |
| 224 | settags(c, t); | 249 | if(t) |
| 250 | for(i = 0; i < ntags; i++) | ||
| 251 | c->tags[i] = t->tags[i]; | ||
| 252 | if(!loadconfig(c)) | ||
| 253 | applyrules(c); | ||
| 225 | if(!c->isfloating) | 254 | if(!c->isfloating) |
| 226 | c->isfloating = (rettrans == Success) || c->isfixed; | 255 | c->isfloating = (rettrans == Success) || c->isfixed; |
| 256 | saveconfig(c); | ||
| 227 | attach(c); | 257 | attach(c); |
| 228 | attachstack(c); | 258 | attachstack(c); |
| 229 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ | 259 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ |
| @@ -295,6 +325,19 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | |||
| 295 | } | 325 | } |
| 296 | 326 | ||
| 297 | void | 327 | void |
| 328 | saveconfig(Client *c) { | ||
| 329 | unsigned int i; | ||
| 330 | |||
| 331 | for(i = 0; i < ntags && i < sizeof config - 1; i++) | ||
| 332 | config[i] = c->tags[i] ? '1' : '0'; | ||
| 333 | if(i < sizeof config - 1) | ||
| 334 | config[i++] = c->isfloating ? '1' : '0'; | ||
| 335 | config[i] = '\0'; | ||
| 336 | XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8, | ||
| 337 | PropModeReplace, (unsigned char *)config, i); | ||
| 338 | } | ||
| 339 | |||
| 340 | void | ||
| 298 | unban(Client *c) { | 341 | unban(Client *c) { |
| 299 | if(!c->isbanned) | 342 | if(!c->isbanned) |
| 300 | return; | 343 | return; |
| @@ -96,9 +96,11 @@ void configure(Client *c); /* send synthetic configure event */ | |||
| 96 | void detach(Client *c); /* detaches c from global client list */ | 96 | void detach(Client *c); /* detaches c from global client list */ |
| 97 | void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ | 97 | void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ |
| 98 | void killclient(const char *arg); /* kill sel nicely */ | 98 | void killclient(const char *arg); /* kill sel nicely */ |
| 99 | Bool loadconfig(Client *c); /* loads client properties */ | ||
| 99 | void manage(Window w, XWindowAttributes *wa); /* manage new client */ | 100 | void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
| 100 | void resize(Client *c, int x, int y, | 101 | void resize(Client *c, int x, int y, |
| 101 | int w, int h, Bool sizehints); /* resize with given coordinates c*/ | 102 | int w, int h, Bool sizehints); /* resize with given coordinates c*/ |
| 103 | void saveconfig(Client *c); /* saves client properties */ | ||
| 102 | void unban(Client *c); /* unbans c */ | 104 | void unban(Client *c); /* unbans c */ |
| 103 | void unmanage(Client *c, long state); /* unmanage c */ | 105 | void unmanage(Client *c, long state); /* unmanage c */ |
| 104 | void updatesizehints(Client *c); /* update the size hint variables of c */ | 106 | void updatesizehints(Client *c); /* update the size hint variables of c */ |
| @@ -132,9 +134,9 @@ void quit(const char *arg); /* quit dwm nicely */ | |||
| 132 | int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ | 134 | int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
| 133 | 135 | ||
| 134 | /* tag.c */ | 136 | /* tag.c */ |
| 137 | void applyrules(Client *c); /* applies rules to c */ | ||
| 135 | void compileregs(void); /* initialize regexps of rules defined in config.h */ | 138 | void compileregs(void); /* initialize regexps of rules defined in config.h */ |
| 136 | Bool isvisible(Client *c); /* returns True if client is visible */ | 139 | Bool isvisible(Client *c); /* returns True if client is visible */ |
| 137 | void settags(Client *c, Client *trans); /* sets tags of c */ | ||
| 138 | void tag(const char *arg); /* tags sel with arg's index */ | 140 | void tag(const char *arg); /* tags sel with arg's index */ |
| 139 | void togglefloating(const char *arg); /* toggles sel between floating/tiled state */ | 141 | void togglefloating(const char *arg); /* toggles sel between floating/tiled state */ |
| 140 | void toggletag(const char *arg); /* toggles sel tags with arg's index */ | 142 | void toggletag(const char *arg); /* toggles sel tags with arg's index */ |
| @@ -10,7 +10,7 @@ typedef struct { | |||
| 10 | } Layout; | 10 | } Layout; |
| 11 | 11 | ||
| 12 | unsigned int blw = 0; | 12 | unsigned int blw = 0; |
| 13 | static unsigned int sellayout = 0; /* default */ | 13 | static unsigned int ltidx = 0; /* default */ |
| 14 | 14 | ||
| 15 | static void | 15 | static void |
| 16 | floating(void) { /* default floating layout */ | 16 | floating(void) { /* default floating layout */ |
| @@ -36,7 +36,7 @@ arrange(void) { | |||
| 36 | unban(c); | 36 | unban(c); |
| 37 | else | 37 | else |
| 38 | ban(c); | 38 | ban(c); |
| 39 | layouts[sellayout].arrange(); | 39 | layouts[ltidx].arrange(); |
| 40 | focus(NULL); | 40 | focus(NULL); |
| 41 | restack(); | 41 | restack(); |
| 42 | } | 42 | } |
| @@ -76,25 +76,25 @@ focusprev(const char *arg) { | |||
| 76 | const char * | 76 | const char * |
| 77 | getsymbol(void) | 77 | getsymbol(void) |
| 78 | { | 78 | { |
| 79 | return layouts[sellayout].symbol; | 79 | return layouts[ltidx].symbol; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | Bool | 82 | Bool |
| 83 | isfloating(void) { | 83 | isfloating(void) { |
| 84 | return layouts[sellayout].arrange == floating; | 84 | return layouts[ltidx].arrange == floating; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | Bool | 87 | Bool |
| 88 | isarrange(void (*func)()) | 88 | isarrange(void (*func)()) |
| 89 | { | 89 | { |
| 90 | return func == layouts[sellayout].arrange; | 90 | return func == layouts[ltidx].arrange; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void | 93 | void |
| 94 | initlayouts(void) { | 94 | initlayouts(void) { |
| 95 | unsigned int i, w; | 95 | unsigned int i, w; |
| 96 | 96 | ||
| 97 | /* TODO deserialize sellayout if present */ | 97 | /* TODO deserialize ltidx if present */ |
| 98 | nlayouts = sizeof layouts / sizeof layouts[0]; | 98 | nlayouts = sizeof layouts / sizeof layouts[0]; |
| 99 | for(blw = i = 0; i < nlayouts; i++) { | 99 | for(blw = i = 0; i < nlayouts; i++) { |
| 100 | w = textw(layouts[i].symbol); | 100 | w = textw(layouts[i].symbol); |
| @@ -143,14 +143,14 @@ setlayout(const char *arg) { | |||
| 143 | int i; | 143 | int i; |
| 144 | 144 | ||
| 145 | if(!arg) { | 145 | if(!arg) { |
| 146 | if(++sellayout == nlayouts) | 146 | if(++ltidx == nlayouts) |
| 147 | sellayout = 0;; | 147 | ltidx = 0;; |
| 148 | } | 148 | } |
| 149 | else { | 149 | else { |
| 150 | i = atoi(arg); | 150 | i = atoi(arg); |
| 151 | if(i < 0 || i >= nlayouts) | 151 | if(i < 0 || i >= nlayouts) |
| 152 | return; | 152 | return; |
| 153 | sellayout = i; | 153 | ltidx = i; |
| 154 | } | 154 | } |
| 155 | if(sel) | 155 | if(sel) |
| 156 | arrange(); | 156 | arrange(); |
| @@ -27,19 +27,6 @@ static Regs *regs = NULL; | |||
| 27 | static unsigned int nrules = 0; | 27 | static unsigned int nrules = 0; |
| 28 | static char prop[512]; | 28 | static char prop[512]; |
| 29 | 29 | ||
| 30 | static void | ||
| 31 | persistconfig(Client *c) { | ||
| 32 | unsigned int i; | ||
| 33 | |||
| 34 | for(i = 0; i < ntags && i < sizeof prop - 1; i++) | ||
| 35 | prop[i] = c->tags[i] ? '1' : '0'; | ||
| 36 | if(i < sizeof prop - 1) | ||
| 37 | prop[i++] = c->isfloating ? '1' : '0'; | ||
| 38 | prop[i] = '\0'; | ||
| 39 | XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8, | ||
| 40 | PropModeReplace, (unsigned char *)prop, i); | ||
| 41 | } | ||
| 42 | |||
| 43 | static unsigned int | 30 | static unsigned int |
| 44 | idxoftag(const char *tag) { | 31 | idxoftag(const char *tag) { |
| 45 | unsigned int i; | 32 | unsigned int i; |
| @@ -53,6 +40,37 @@ idxoftag(const char *tag) { | |||
| 53 | /* extern */ | 40 | /* extern */ |
| 54 | 41 | ||
| 55 | void | 42 | void |
| 43 | applyrules(Client *c) { | ||
| 44 | unsigned int i, j; | ||
| 45 | regmatch_t tmp; | ||
| 46 | Bool matched = False; | ||
| 47 | XClassHint ch = { 0 }; | ||
| 48 | |||
| 49 | /* rule matching */ | ||
| 50 | XGetClassHint(dpy, c->win, &ch); | ||
| 51 | snprintf(prop, sizeof prop, "%s:%s:%s", | ||
| 52 | ch.res_class ? ch.res_class : "", | ||
| 53 | ch.res_name ? ch.res_name : "", c->name); | ||
| 54 | for(i = 0; i < nrules; i++) | ||
| 55 | if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) { | ||
| 56 | c->isfloating = rules[i].isfloating; | ||
| 57 | for(j = 0; regs[i].tagregex && j < ntags; j++) { | ||
| 58 | if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { | ||
| 59 | matched = True; | ||
| 60 | c->tags[j] = True; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | if(ch.res_class) | ||
| 65 | XFree(ch.res_class); | ||
| 66 | if(ch.res_name) | ||
| 67 | XFree(ch.res_name); | ||
| 68 | if(!matched) | ||
| 69 | for(i = 0; i < ntags; i++) | ||
| 70 | c->tags[i] = seltags[i]; | ||
| 71 | } | ||
| 72 | |||
| 73 | void | ||
| 56 | compileregs(void) { | 74 | compileregs(void) { |
| 57 | unsigned int i; | 75 | unsigned int i; |
| 58 | regex_t *reg; | 76 | regex_t *reg; |
| @@ -90,60 +108,6 @@ isvisible(Client *c) { | |||
| 90 | } | 108 | } |
| 91 | 109 | ||
| 92 | void | 110 | void |
| 93 | settags(Client *c, Client *trans) { | ||
| 94 | unsigned int i, j; | ||
| 95 | regmatch_t tmp; | ||
| 96 | Bool matched = trans != NULL; | ||
| 97 | XClassHint ch = { 0 }; | ||
| 98 | XTextProperty name; | ||
| 99 | |||
| 100 | if(matched) { | ||
| 101 | for(i = 0; i < ntags; i++) | ||
| 102 | c->tags[i] = trans->tags[i]; | ||
| 103 | } | ||
| 104 | else { | ||
| 105 | /* check if window has set a property */ | ||
| 106 | name.nitems = 0; | ||
| 107 | XGetTextProperty(dpy, c->win, &name, dwmconfig); | ||
| 108 | if(name.nitems && name.encoding == XA_STRING) { | ||
| 109 | strncpy(prop, (char *)name.value, sizeof prop - 1); | ||
| 110 | prop[sizeof prop - 1] = '\0'; | ||
| 111 | XFree(name.value); | ||
| 112 | for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++) | ||
| 113 | if((c->tags[i] = prop[i] == '1')) | ||
| 114 | matched = True; | ||
| 115 | if(i < sizeof prop - 1 && prop[i] != '\0') | ||
| 116 | c->isfloating = prop[i] == '1'; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | if(!matched) { | ||
| 120 | /* rule matching */ | ||
| 121 | XGetClassHint(dpy, c->win, &ch); | ||
| 122 | snprintf(prop, sizeof prop, "%s:%s:%s", | ||
| 123 | ch.res_class ? ch.res_class : "", | ||
| 124 | ch.res_name ? ch.res_name : "", c->name); | ||
| 125 | for(i = 0; i < nrules; i++) | ||
| 126 | if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) { | ||
| 127 | c->isfloating = rules[i].isfloating; | ||
| 128 | for(j = 0; regs[i].tagregex && j < ntags; j++) { | ||
| 129 | if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { | ||
| 130 | matched = True; | ||
| 131 | c->tags[j] = True; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | if(ch.res_class) | ||
| 136 | XFree(ch.res_class); | ||
| 137 | if(ch.res_name) | ||
| 138 | XFree(ch.res_name); | ||
| 139 | } | ||
| 140 | if(!matched) | ||
| 141 | for(i = 0; i < ntags; i++) | ||
| 142 | c->tags[i] = seltags[i]; | ||
| 143 | persistconfig(c); | ||
| 144 | } | ||
| 145 | |||
| 146 | void | ||
| 147 | tag(const char *arg) { | 111 | tag(const char *arg) { |
| 148 | unsigned int i; | 112 | unsigned int i; |
| 149 | 113 | ||
| @@ -154,7 +118,7 @@ tag(const char *arg) { | |||
| 154 | i = idxoftag(arg); | 118 | i = idxoftag(arg); |
| 155 | if(i >= 0 && i < ntags) | 119 | if(i >= 0 && i < ntags) |
| 156 | sel->tags[i] = True; | 120 | sel->tags[i] = True; |
| 157 | persistconfig(sel); | 121 | saveconfig(sel); |
| 158 | arrange(); | 122 | arrange(); |
| 159 | } | 123 | } |
| 160 | 124 | ||
| @@ -165,7 +129,7 @@ togglefloating(const char *arg) { | |||
| 165 | sel->isfloating = !sel->isfloating; | 129 | sel->isfloating = !sel->isfloating; |
| 166 | if(sel->isfloating) { | 130 | if(sel->isfloating) { |
| 167 | resize(sel, sel->x, sel->y, sel->w, sel->h, True); | 131 | resize(sel, sel->x, sel->y, sel->w, sel->h, True); |
| 168 | persistconfig(sel); | 132 | saveconfig(sel); |
| 169 | } | 133 | } |
| 170 | arrange(); | 134 | arrange(); |
| 171 | } | 135 | } |
| @@ -181,7 +145,7 @@ toggletag(const char *arg) { | |||
| 181 | for(j = 0; j < ntags && !sel->tags[j]; j++); | 145 | for(j = 0; j < ntags && !sel->tags[j]; j++); |
| 182 | if(j == ntags) | 146 | if(j == ntags) |
| 183 | sel->tags[i] = True; | 147 | sel->tags[i] = True; |
| 184 | persistconfig(sel); | 148 | saveconfig(sel); |
| 185 | arrange(); | 149 | arrange(); |
| 186 | } | 150 | } |
| 187 | 151 | ||
