dwm-meillo

annotate tag.c @ 94:6efe82c775c9

pop on heretag
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 18 Jul 2006 11:45:32 +0200
parents c498da7520c7
children 5d88952cbf96
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 */
garbeam@84 15 { "Firefox-bin", "Gecko", { [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@75 46 if(c->tags[tsel])
garbeam@75 47 resize(c, True);
garbeam@75 48 else
garbeam@75 49 ban(c);
garbeam@75 50 }
garbeam@75 51 if(sel && !sel->tags[tsel]) {
garbeam@93 52 if((sel = getnext(clients, tsel))) {
garbeam@75 53 higher(sel);
garbeam@75 54 focus(sel);
garbeam@75 55 }
garbeam@75 56 }
garbeam@75 57 drawall();
garbeam@75 58 }
garbeam@75 59
garbeam@75 60 void
garbeam@75 61 dotile(Arg *arg)
garbeam@75 62 {
garbeam@75 63 Client *c;
garbeam@75 64 int n, i, w, h;
garbeam@75 65
garbeam@75 66 w = sw - mw;
garbeam@75 67 arrange = dotile;
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) {
garbeam@75 78 if(c->tags[tsel]) {
garbeam@80 79 if(c->isfloat) {
garbeam@75 80 higher(c);
garbeam@75 81 resize(c, True);
garbeam@75 82 continue;
garbeam@75 83 }
garbeam@75 84 if(n == 1) {
garbeam@75 85 c->x = sx;
garbeam@75 86 c->y = sy + bh;
garbeam@75 87 c->w = sw - 2 * c->border;
garbeam@75 88 c->h = sh - 2 * c->border - bh;
garbeam@75 89 }
garbeam@75 90 else if(i == 0) {
garbeam@75 91 c->x = sx;
garbeam@75 92 c->y = sy + bh;
garbeam@75 93 c->w = mw - 2 * c->border;
garbeam@75 94 c->h = sh - 2 * c->border - bh;
garbeam@75 95 }
garbeam@75 96 else {
garbeam@75 97 c->x = sx + mw;
garbeam@75 98 c->y = sy + (i - 1) * h + bh;
garbeam@75 99 c->w = w - 2 * c->border;
garbeam@75 100 c->h = h - 2 * c->border;
garbeam@75 101 }
garbeam@75 102 resize(c, False);
garbeam@75 103 i++;
garbeam@75 104 }
garbeam@75 105 else
garbeam@75 106 ban(c);
garbeam@75 107 }
garbeam@75 108 if(!sel || (sel && !sel->tags[tsel])) {
garbeam@93 109 if((sel = getnext(clients, tsel))) {
garbeam@75 110 higher(sel);
garbeam@75 111 focus(sel);
garbeam@75 112 }
garbeam@75 113 }
garbeam@75 114 drawall();
garbeam@75 115 }
garbeam@75 116
garbeam@76 117 Client *
garbeam@93 118 getnext(Client *c, unsigned int t)
garbeam@75 119 {
garbeam@93 120 for(; c && !c->tags[t]; c = c->next);
garbeam@76 121 return c;
garbeam@75 122 }
garbeam@75 123
garbeam@75 124 void
garbeam@93 125 heretag(Arg *arg)
garbeam@93 126 {
garbeam@93 127 int i;
garbeam@93 128 Client *c;
garbeam@93 129
garbeam@93 130 if(arg->i == tsel)
garbeam@93 131 return;
garbeam@93 132
garbeam@93 133 if(!(c = getnext(clients, arg->i)))
garbeam@93 134 return;
garbeam@93 135
garbeam@93 136 for(i = 0; i < TLast; i++)
garbeam@93 137 c->tags[i] = NULL;
garbeam@93 138 c->tags[tsel] = tags[tsel];
garbeam@94 139 pop(c);
garbeam@93 140 focus(c);
garbeam@93 141 }
garbeam@93 142
garbeam@93 143 void
garbeam@75 144 replacetag(Arg *arg)
garbeam@75 145 {
garbeam@75 146 int i;
garbeam@75 147 if(!sel)
garbeam@75 148 return;
garbeam@75 149
garbeam@75 150 for(i = 0; i < TLast; i++)
garbeam@75 151 sel->tags[i] = NULL;
garbeam@75 152 appendtag(arg);
garbeam@75 153 }
garbeam@75 154
garbeam@76 155 void
garbeam@76 156 settags(Client *c)
garbeam@76 157 {
garbeam@76 158 XClassHint ch;
garbeam@76 159 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
garbeam@76 160 unsigned int i, j;
garbeam@76 161 Bool matched = False;
garbeam@76 162
garbeam@76 163 if(!len) {
garbeam@76 164 c->tags[tsel] = tags[tsel];
garbeam@76 165 return;
garbeam@76 166 }
garbeam@76 167
garbeam@76 168 if(XGetClassHint(dpy, c->win, &ch)) {
garbeam@76 169 if(ch.res_class && ch.res_name) {
garbeam@76 170 for(i = 0; i < len; i++)
garbeam@76 171 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
garbeam@76 172 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
garbeam@76 173 {
garbeam@76 174 for(j = 0; j < TLast; j++)
garbeam@76 175 c->tags[j] = rule[i].tags[j];
garbeam@80 176 c->isfloat = rule[i].isfloat;
garbeam@76 177 matched = True;
garbeam@76 178 break;
garbeam@76 179 }
garbeam@76 180 }
garbeam@76 181 if(ch.res_class)
garbeam@76 182 XFree(ch.res_class);
garbeam@76 183 if(ch.res_name)
garbeam@76 184 XFree(ch.res_name);
garbeam@76 185 }
garbeam@76 186
garbeam@76 187 if(!matched)
garbeam@76 188 c->tags[tsel] = tags[tsel];
garbeam@76 189 }
garbeam@76 190
garbeam@76 191 void
garbeam@76 192 view(Arg *arg)
garbeam@76 193 {
garbeam@76 194 tsel = arg->i;
garbeam@76 195 arrange(NULL);
garbeam@76 196 drawall();
garbeam@76 197 }