dwm-meillo

annotate tag.c @ 89:bab11ff18f4c

updated html
author Anselm R. Garbe <garbeam@wmii.de>
date Mon, 17 Jul 2006 11:56:27 +0200
parents 8125f908c80c
children c498da7520c7
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@75 52 if((sel = getnext(clients))) {
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@75 109 if((sel = getnext(clients))) {
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@76 118 getnext(Client *c)
garbeam@75 119 {
garbeam@76 120 for(; c && !c->tags[tsel]; c = c->next);
garbeam@76 121 return c;
garbeam@75 122 }
garbeam@75 123
garbeam@75 124 void
garbeam@75 125 replacetag(Arg *arg)
garbeam@75 126 {
garbeam@75 127 int i;
garbeam@75 128 if(!sel)
garbeam@75 129 return;
garbeam@75 130
garbeam@75 131 for(i = 0; i < TLast; i++)
garbeam@75 132 sel->tags[i] = NULL;
garbeam@75 133 appendtag(arg);
garbeam@75 134 }
garbeam@75 135
garbeam@76 136 void
garbeam@76 137 settags(Client *c)
garbeam@76 138 {
garbeam@76 139 XClassHint ch;
garbeam@76 140 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
garbeam@76 141 unsigned int i, j;
garbeam@76 142 Bool matched = False;
garbeam@76 143
garbeam@76 144 if(!len) {
garbeam@76 145 c->tags[tsel] = tags[tsel];
garbeam@76 146 return;
garbeam@76 147 }
garbeam@76 148
garbeam@76 149 if(XGetClassHint(dpy, c->win, &ch)) {
garbeam@76 150 if(ch.res_class && ch.res_name) {
garbeam@76 151 for(i = 0; i < len; i++)
garbeam@76 152 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
garbeam@76 153 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
garbeam@76 154 {
garbeam@76 155 for(j = 0; j < TLast; j++)
garbeam@76 156 c->tags[j] = rule[i].tags[j];
garbeam@80 157 c->isfloat = rule[i].isfloat;
garbeam@76 158 matched = True;
garbeam@76 159 break;
garbeam@76 160 }
garbeam@76 161 }
garbeam@76 162 if(ch.res_class)
garbeam@76 163 XFree(ch.res_class);
garbeam@76 164 if(ch.res_name)
garbeam@76 165 XFree(ch.res_name);
garbeam@76 166 }
garbeam@76 167
garbeam@76 168 if(!matched)
garbeam@76 169 c->tags[tsel] = tags[tsel];
garbeam@76 170 }
garbeam@76 171
garbeam@76 172 void
garbeam@76 173 view(Arg *arg)
garbeam@76 174 {
garbeam@76 175 tsel = arg->i;
garbeam@76 176 arrange(NULL);
garbeam@76 177 drawall();
garbeam@76 178 }