aewl

annotate tag.c @ 102:ed2d4eb65f02

yet another typo fix
author arg@10ksloc.org
date Wed, 19 Jul 2006 13:29:45 +0200
parents 1d125cf2925b
children 3a708f113f55
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
garbeam@75 7 #include <string.h>
garbeam@75 8 #include <X11/Xutil.h>
garbeam@75 9
garbeam@84 10 /* static */
garbeam@76 11
garbeam@84 12 /* CUSTOMIZE */
garbeam@84 13 static Rule rule[] = {
garbeam@84 14 /* class instance tags isfloat */
arg@97 15 { "Firefox-bin", "firefox-bin", { [Twww] = "www" }, False },
garbeam@84 16 };
garbeam@84 17
garbeam@84 18 /* extern */
garbeam@84 19
garbeam@84 20 /* CUSTOMIZE */
garbeam@76 21 char *tags[TLast] = {
garbeam@76 22 [Tscratch] = "scratch",
garbeam@76 23 [Tdev] = "dev",
garbeam@76 24 [Twww] = "www",
garbeam@76 25 [Twork] = "work",
garbeam@76 26 };
garbeam@75 27 void (*arrange)(Arg *) = dotile;
garbeam@75 28
garbeam@76 29 void
garbeam@76 30 appendtag(Arg *arg)
garbeam@75 31 {
garbeam@76 32 if(!sel)
garbeam@76 33 return;
garbeam@75 34
garbeam@76 35 sel->tags[arg->i] = tags[arg->i];
garbeam@75 36 arrange(NULL);
garbeam@75 37 }
garbeam@75 38
garbeam@75 39 void
garbeam@75 40 dofloat(Arg *arg)
garbeam@75 41 {
garbeam@75 42 Client *c;
garbeam@75 43
garbeam@75 44 arrange = dofloat;
garbeam@75 45 for(c = clients; c; c = c->next) {
garbeam@95 46 setgeom(c);
garbeam@95 47 if(c->tags[tsel]) {
arg@99 48 resize(c, True, TopLeft);
garbeam@95 49 }
garbeam@75 50 else
garbeam@75 51 ban(c);
garbeam@75 52 }
garbeam@75 53 if(sel && !sel->tags[tsel]) {
garbeam@93 54 if((sel = getnext(clients, tsel))) {
garbeam@75 55 higher(sel);
garbeam@75 56 focus(sel);
garbeam@75 57 }
garbeam@75 58 }
garbeam@75 59 drawall();
garbeam@75 60 }
garbeam@75 61
garbeam@75 62 void
garbeam@75 63 dotile(Arg *arg)
garbeam@75 64 {
garbeam@75 65 Client *c;
garbeam@75 66 int n, i, w, h;
garbeam@75 67
garbeam@75 68 w = sw - mw;
garbeam@75 69 arrange = dotile;
garbeam@75 70 for(n = 0, c = clients; c; c = c->next)
garbeam@80 71 if(c->tags[tsel] && !c->isfloat)
garbeam@75 72 n++;
garbeam@75 73
garbeam@75 74 if(n > 1)
garbeam@75 75 h = (sh - bh) / (n - 1);
garbeam@75 76 else
garbeam@75 77 h = sh - bh;
garbeam@75 78
garbeam@75 79 for(i = 0, c = clients; c; c = c->next) {
garbeam@95 80 setgeom(c);
garbeam@75 81 if(c->tags[tsel]) {
garbeam@80 82 if(c->isfloat) {
garbeam@75 83 higher(c);
arg@99 84 resize(c, True, TopLeft);
garbeam@75 85 continue;
garbeam@75 86 }
garbeam@75 87 if(n == 1) {
garbeam@95 88 *c->x = sx;
garbeam@95 89 *c->y = sy + bh;
garbeam@95 90 *c->w = sw - 2 * c->border;
garbeam@95 91 *c->h = sh - 2 * c->border - bh;
garbeam@75 92 }
garbeam@75 93 else if(i == 0) {
garbeam@95 94 *c->x = sx;
garbeam@95 95 *c->y = sy + bh;
garbeam@95 96 *c->w = mw - 2 * c->border;
garbeam@95 97 *c->h = sh - 2 * c->border - bh;
garbeam@75 98 }
garbeam@75 99 else {
garbeam@95 100 *c->x = sx + mw;
garbeam@95 101 *c->y = sy + (i - 1) * h + bh;
garbeam@95 102 *c->w = w - 2 * c->border;
garbeam@95 103 *c->h = h - 2 * c->border;
garbeam@75 104 }
arg@99 105 resize(c, False, TopLeft);
garbeam@75 106 i++;
garbeam@75 107 }
garbeam@75 108 else
garbeam@75 109 ban(c);
garbeam@75 110 }
garbeam@75 111 if(!sel || (sel && !sel->tags[tsel])) {
garbeam@93 112 if((sel = getnext(clients, tsel))) {
garbeam@75 113 higher(sel);
garbeam@75 114 focus(sel);
garbeam@75 115 }
garbeam@75 116 }
garbeam@75 117 drawall();
garbeam@75 118 }
garbeam@75 119
garbeam@76 120 Client *
garbeam@93 121 getnext(Client *c, unsigned int t)
garbeam@75 122 {
garbeam@93 123 for(; c && !c->tags[t]; c = c->next);
garbeam@76 124 return c;
garbeam@75 125 }
garbeam@75 126
garbeam@75 127 void
garbeam@93 128 heretag(Arg *arg)
garbeam@93 129 {
garbeam@93 130 int i;
garbeam@93 131 Client *c;
garbeam@93 132
garbeam@93 133 if(arg->i == tsel)
garbeam@93 134 return;
garbeam@93 135
garbeam@93 136 if(!(c = getnext(clients, arg->i)))
garbeam@93 137 return;
garbeam@93 138
garbeam@93 139 for(i = 0; i < TLast; i++)
garbeam@93 140 c->tags[i] = NULL;
garbeam@93 141 c->tags[tsel] = tags[tsel];
garbeam@94 142 pop(c);
garbeam@93 143 focus(c);
garbeam@93 144 }
garbeam@93 145
garbeam@93 146 void
garbeam@75 147 replacetag(Arg *arg)
garbeam@75 148 {
garbeam@75 149 int i;
garbeam@75 150 if(!sel)
garbeam@75 151 return;
garbeam@75 152
garbeam@75 153 for(i = 0; i < TLast; i++)
garbeam@75 154 sel->tags[i] = NULL;
garbeam@75 155 appendtag(arg);
garbeam@75 156 }
garbeam@75 157
garbeam@76 158 void
garbeam@76 159 settags(Client *c)
garbeam@76 160 {
garbeam@76 161 XClassHint ch;
garbeam@76 162 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
garbeam@76 163 unsigned int i, j;
garbeam@76 164 Bool matched = False;
garbeam@76 165
garbeam@76 166 if(!len) {
garbeam@76 167 c->tags[tsel] = tags[tsel];
garbeam@76 168 return;
garbeam@76 169 }
garbeam@76 170
garbeam@76 171 if(XGetClassHint(dpy, c->win, &ch)) {
garbeam@76 172 if(ch.res_class && ch.res_name) {
garbeam@76 173 for(i = 0; i < len; i++)
garbeam@76 174 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
garbeam@76 175 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
garbeam@76 176 {
garbeam@76 177 for(j = 0; j < TLast; j++)
garbeam@76 178 c->tags[j] = rule[i].tags[j];
garbeam@80 179 c->isfloat = rule[i].isfloat;
garbeam@76 180 matched = True;
garbeam@76 181 break;
garbeam@76 182 }
garbeam@76 183 }
garbeam@76 184 if(ch.res_class)
garbeam@76 185 XFree(ch.res_class);
garbeam@76 186 if(ch.res_name)
garbeam@76 187 XFree(ch.res_name);
garbeam@76 188 }
garbeam@76 189
garbeam@76 190 if(!matched)
garbeam@76 191 c->tags[tsel] = tags[tsel];
garbeam@76 192 }
garbeam@76 193
garbeam@76 194 void
garbeam@76 195 view(Arg *arg)
garbeam@76 196 {
garbeam@76 197 tsel = arg->i;
garbeam@76 198 arrange(NULL);
garbeam@76 199 drawall();
garbeam@76 200 }