aewl

annotate tag.c @ 106:c292574503dd

fixed the bug mentioned by Sander
author arg@10ksloc.org
date Wed, 19 Jul 2006 14:11:27 +0200
parents a19556fe83b5
children dfa5cd0969a6
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 }
arg@104 99 else if(h > bh) {
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@104 105 else { /* fallback if h < bh */
arg@104 106 *c->x = sx + mw;
arg@104 107 *c->y = sy + bh;
arg@104 108 *c->w = w - 2 * c->border;
arg@104 109 *c->h = sh - 2 * c->border - bh;
arg@104 110 }
arg@99 111 resize(c, False, TopLeft);
garbeam@75 112 i++;
garbeam@75 113 }
garbeam@75 114 else
garbeam@75 115 ban(c);
garbeam@75 116 }
garbeam@75 117 if(!sel || (sel && !sel->tags[tsel])) {
garbeam@93 118 if((sel = getnext(clients, tsel))) {
garbeam@75 119 higher(sel);
garbeam@75 120 focus(sel);
garbeam@75 121 }
garbeam@75 122 }
garbeam@75 123 drawall();
garbeam@75 124 }
garbeam@75 125
garbeam@76 126 Client *
garbeam@93 127 getnext(Client *c, unsigned int t)
garbeam@75 128 {
garbeam@93 129 for(; c && !c->tags[t]; c = c->next);
garbeam@76 130 return c;
garbeam@75 131 }
garbeam@75 132
garbeam@75 133 void
garbeam@93 134 heretag(Arg *arg)
garbeam@93 135 {
garbeam@93 136 int i;
garbeam@93 137 Client *c;
garbeam@93 138
garbeam@93 139 if(arg->i == tsel)
garbeam@93 140 return;
garbeam@93 141
garbeam@93 142 if(!(c = getnext(clients, arg->i)))
garbeam@93 143 return;
garbeam@93 144
garbeam@93 145 for(i = 0; i < TLast; i++)
garbeam@93 146 c->tags[i] = NULL;
garbeam@93 147 c->tags[tsel] = tags[tsel];
garbeam@94 148 pop(c);
garbeam@93 149 focus(c);
garbeam@93 150 }
garbeam@93 151
garbeam@93 152 void
garbeam@75 153 replacetag(Arg *arg)
garbeam@75 154 {
garbeam@75 155 int i;
garbeam@75 156 if(!sel)
garbeam@75 157 return;
garbeam@75 158
garbeam@75 159 for(i = 0; i < TLast; i++)
garbeam@75 160 sel->tags[i] = NULL;
garbeam@75 161 appendtag(arg);
garbeam@75 162 }
garbeam@75 163
garbeam@76 164 void
garbeam@76 165 settags(Client *c)
garbeam@76 166 {
garbeam@76 167 XClassHint ch;
garbeam@76 168 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
garbeam@76 169 unsigned int i, j;
garbeam@76 170 Bool matched = False;
garbeam@76 171
garbeam@76 172 if(!len) {
garbeam@76 173 c->tags[tsel] = tags[tsel];
garbeam@76 174 return;
garbeam@76 175 }
garbeam@76 176
garbeam@76 177 if(XGetClassHint(dpy, c->win, &ch)) {
garbeam@76 178 if(ch.res_class && ch.res_name) {
garbeam@76 179 for(i = 0; i < len; i++)
garbeam@76 180 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
garbeam@76 181 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
garbeam@76 182 {
garbeam@76 183 for(j = 0; j < TLast; j++)
garbeam@76 184 c->tags[j] = rule[i].tags[j];
garbeam@80 185 c->isfloat = rule[i].isfloat;
garbeam@76 186 matched = True;
garbeam@76 187 break;
garbeam@76 188 }
garbeam@76 189 }
garbeam@76 190 if(ch.res_class)
garbeam@76 191 XFree(ch.res_class);
garbeam@76 192 if(ch.res_name)
garbeam@76 193 XFree(ch.res_name);
garbeam@76 194 }
garbeam@76 195
garbeam@76 196 if(!matched)
garbeam@76 197 c->tags[tsel] = tags[tsel];
garbeam@76 198 }
garbeam@76 199
garbeam@76 200 void
garbeam@76 201 view(Arg *arg)
garbeam@76 202 {
garbeam@76 203 tsel = arg->i;
garbeam@76 204 arrange(NULL);
garbeam@76 205 drawall();
garbeam@76 206 }