aewl

annotate tag.c @ 75:f08271b7cb20

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