aewl

annotate tag.c @ 82:3954fc13b2e8

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