dwm-meillo

annotate tag.c @ 177:e890cee887d1

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