dwm-meillo

annotate tag.c @ 143:36cabfe408cd

applied Sanders patches
author arg@10ksloc.org
date Tue, 01 Aug 2006 12:32:33 +0200
parents 9b9deafa0508
children e61447a7f249
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"
garbeam@75 6
arg@114 7 #include <regex.h>
arg@114 8 #include <stdio.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@84 13 /* static */
garbeam@76 14
arg@114 15 typedef struct {
arg@114 16 const char *pattern;
arg@114 17 char *tags[TLast];
arg@114 18 Bool isfloat;
arg@114 19 } Rule;
arg@114 20
garbeam@84 21 /* CUSTOMIZE */
garbeam@84 22 static Rule rule[] = {
arg@123 23 /* class:instance tags isfloat */
arg@130 24 { "Firefox.*", { [Tnet] = "net" }, False },
arg@123 25 { "Gimp.*", { 0 }, True},
garbeam@84 26 };
garbeam@84 27
garbeam@76 28 char *tags[TLast] = {
arg@130 29 [Tfnord] = "fnord",
garbeam@76 30 [Tdev] = "dev",
arg@130 31 [Tnet] = "net",
garbeam@76 32 [Twork] = "work",
arg@130 33 [Tmisc] = "misc",
garbeam@76 34 };
arg@125 35
garbeam@75 36 void (*arrange)(Arg *) = dotile;
garbeam@75 37
arg@125 38 /* END CUSTOMIZE */
arg@125 39
arg@125 40 /* extern */
arg@125 41
garbeam@76 42 void
garbeam@76 43 appendtag(Arg *arg)
garbeam@75 44 {
garbeam@76 45 if(!sel)
garbeam@76 46 return;
garbeam@75 47
garbeam@76 48 sel->tags[arg->i] = tags[arg->i];
garbeam@75 49 arrange(NULL);
garbeam@75 50 }
garbeam@75 51
garbeam@75 52 void
garbeam@75 53 dofloat(Arg *arg)
garbeam@75 54 {
garbeam@75 55 Client *c;
garbeam@75 56
garbeam@75 57 for(c = clients; c; c = c->next) {
arg@124 58 c->ismax = False;
garbeam@95 59 if(c->tags[tsel]) {
arg@99 60 resize(c, True, TopLeft);
garbeam@95 61 }
garbeam@75 62 else
garbeam@75 63 ban(c);
garbeam@75 64 }
garbeam@75 65 if(sel && !sel->tags[tsel]) {
arg@142 66 if((sel = getnext(clients))) {
garbeam@75 67 higher(sel);
garbeam@75 68 focus(sel);
garbeam@75 69 }
arg@143 70 else
arg@143 71 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
garbeam@75 72 }
garbeam@75 73 drawall();
garbeam@75 74 }
garbeam@75 75
garbeam@75 76 void
garbeam@75 77 dotile(Arg *arg)
garbeam@75 78 {
arg@123 79 int n, i, w, h;
garbeam@75 80 Client *c;
garbeam@75 81
garbeam@75 82 w = sw - mw;
garbeam@75 83 for(n = 0, c = clients; c; c = c->next)
garbeam@80 84 if(c->tags[tsel] && !c->isfloat)
garbeam@75 85 n++;
garbeam@75 86
garbeam@75 87 if(n > 1)
garbeam@75 88 h = (sh - bh) / (n - 1);
garbeam@75 89 else
garbeam@75 90 h = sh - bh;
garbeam@75 91
garbeam@75 92 for(i = 0, c = clients; c; c = c->next) {
arg@124 93 c->ismax = False;
garbeam@75 94 if(c->tags[tsel]) {
garbeam@80 95 if(c->isfloat) {
garbeam@75 96 higher(c);
arg@99 97 resize(c, True, TopLeft);
garbeam@75 98 continue;
garbeam@75 99 }
garbeam@75 100 if(n == 1) {
arg@115 101 c->x = sx;
arg@115 102 c->y = sy + bh;
arg@115 103 c->w = sw - 2 * c->border;
arg@115 104 c->h = sh - 2 * c->border - bh;
garbeam@75 105 }
garbeam@75 106 else if(i == 0) {
arg@115 107 c->x = sx;
arg@115 108 c->y = sy + bh;
arg@115 109 c->w = mw - 2 * c->border;
arg@115 110 c->h = sh - 2 * c->border - bh;
garbeam@75 111 }
arg@104 112 else if(h > bh) {
arg@115 113 c->x = sx + mw;
arg@115 114 c->y = sy + (i - 1) * h + bh;
arg@115 115 c->w = w - 2 * c->border;
arg@115 116 c->h = h - 2 * c->border;
garbeam@75 117 }
arg@104 118 else { /* fallback if h < bh */
arg@115 119 c->x = sx + mw;
arg@115 120 c->y = sy + bh;
arg@115 121 c->w = w - 2 * c->border;
arg@115 122 c->h = sh - 2 * c->border - bh;
arg@104 123 }
arg@99 124 resize(c, False, TopLeft);
garbeam@75 125 i++;
garbeam@75 126 }
garbeam@75 127 else
garbeam@75 128 ban(c);
garbeam@75 129 }
garbeam@75 130 if(!sel || (sel && !sel->tags[tsel])) {
arg@142 131 if((sel = getnext(clients))) {
garbeam@75 132 higher(sel);
garbeam@75 133 focus(sel);
garbeam@75 134 }
arg@143 135 else
arg@143 136 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
garbeam@75 137 }
garbeam@75 138 drawall();
garbeam@75 139 }
garbeam@75 140
garbeam@76 141 Client *
arg@142 142 getnext(Client *c)
garbeam@75 143 {
arg@142 144 for(; c && !c->tags[tsel]; c = c->next);
garbeam@76 145 return c;
garbeam@75 146 }
garbeam@75 147
arg@127 148 Client *
arg@127 149 getprev(Client *c)
arg@127 150 {
arg@127 151 for(; c && !c->tags[tsel]; c = c->prev);
arg@127 152 return c;
arg@127 153 }
arg@127 154
garbeam@75 155 void
garbeam@75 156 replacetag(Arg *arg)
garbeam@75 157 {
garbeam@75 158 int i;
arg@123 159
garbeam@75 160 if(!sel)
garbeam@75 161 return;
garbeam@75 162
garbeam@75 163 for(i = 0; i < TLast; i++)
garbeam@75 164 sel->tags[i] = NULL;
garbeam@75 165 appendtag(arg);
garbeam@75 166 }
garbeam@75 167
garbeam@76 168 void
garbeam@76 169 settags(Client *c)
garbeam@76 170 {
arg@114 171 char classinst[256];
arg@138 172 static unsigned int len = sizeof(rule) / sizeof(rule[0]);
garbeam@76 173 unsigned int i, j;
arg@114 174 regex_t regex;
arg@114 175 regmatch_t tmp;
garbeam@76 176 Bool matched = False;
arg@114 177 XClassHint ch;
garbeam@76 178
garbeam@76 179 if(XGetClassHint(dpy, c->win, &ch)) {
arg@114 180 snprintf(classinst, sizeof(classinst), "%s:%s",
arg@114 181 ch.res_class ? ch.res_class : "",
arg@114 182 ch.res_name ? ch.res_name : "");
arg@114 183 for(i = 0; !matched && i < len; i++) {
arg@114 184 if(!regcomp(&regex, rule[i].pattern, 0)) {
arg@114 185 if(!regexec(&regex, classinst, 1, &tmp, 0)) {
arg@114 186 for(j = 0; j < TLast; j++) {
arg@114 187 if(rule[i].tags[j])
arg@114 188 matched = True;
garbeam@76 189 c->tags[j] = rule[i].tags[j];
arg@114 190 }
garbeam@80 191 c->isfloat = rule[i].isfloat;
garbeam@76 192 }
arg@114 193 regfree(&regex);
arg@114 194 }
garbeam@76 195 }
garbeam@76 196 if(ch.res_class)
garbeam@76 197 XFree(ch.res_class);
garbeam@76 198 if(ch.res_name)
garbeam@76 199 XFree(ch.res_name);
garbeam@76 200 }
garbeam@76 201 if(!matched)
garbeam@76 202 c->tags[tsel] = tags[tsel];
garbeam@76 203 }
garbeam@76 204
garbeam@76 205 void
arg@124 206 togglemode(Arg *arg)
arg@124 207 {
arg@124 208 arrange = arrange == dofloat ? dotile : dofloat;
arg@124 209 arrange(NULL);
arg@124 210 }
arg@124 211
arg@124 212 void
garbeam@76 213 view(Arg *arg)
garbeam@76 214 {
garbeam@76 215 tsel = arg->i;
garbeam@76 216 arrange(NULL);
garbeam@76 217 drawall();
garbeam@76 218 }