aewl

annotate view.c @ 571:f0688a69f17f

returning to old bar colorization behavior, like sander proposed for consistency reasons
author arg@mig29
date Tue, 21 Nov 2006 15:03:08 +0100
parents b5435d3fb7b0
children 797e27162b43
rev   line source
arg@532 1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
arg@327 2 * See LICENSE file for license details.
arg@327 3 */
arg@327 4 #include "dwm.h"
arg@327 5
arg@380 6 /* static */
arg@380 7
arg@382 8 static Client *
arg@487 9 minclient(void) {
arg@382 10 Client *c, *min;
arg@382 11
arg@443 12 if((clients && clients->isfloat) || arrange == dofloat)
arg@443 13 return clients; /* don't touch floating order */
arg@382 14 for(min = c = clients; c; c = c->next)
arg@382 15 if(c->weight < min->weight)
arg@382 16 min = c;
arg@382 17 return min;
arg@382 18 }
arg@382 19
arg@480 20 static Client *
arg@480 21 nexttiled(Client *c) {
arg@480 22 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
arg@480 23 return c;
arg@480 24 }
arg@480 25
arg@442 26 static void
arg@487 27 reorder(void) {
arg@382 28 Client *c, *newclients, *tail;
arg@380 29
arg@382 30 newclients = tail = NULL;
arg@382 31 while((c = minclient())) {
arg@381 32 detach(c);
arg@382 33 if(tail) {
arg@382 34 c->prev = tail;
arg@382 35 tail->next = c;
arg@382 36 tail = c;
arg@381 37 }
arg@381 38 else
arg@382 39 tail = newclients = c;
arg@380 40 }
arg@382 41 clients = newclients;
arg@380 42 }
arg@380 43
arg@480 44 static void
arg@532 45 togglemax(Client *c) {
arg@481 46 XEvent ev;
arg@548 47
arg@549 48 if(c->isfixed)
arg@548 49 return;
arg@532 50
arg@480 51 if((c->ismax = !c->ismax)) {
arg@565 52 c->rx = c->x; c->x = wax;
arg@565 53 c->ry = c->y; c->y = way;
arg@565 54 c->rw = c->w; c->w = waw - 2 * BORDERPX;
arg@565 55 c->rh = c->h; c->h = wah - 2 * BORDERPX;
arg@480 56 }
arg@480 57 else {
arg@480 58 c->x = c->rx;
arg@480 59 c->y = c->ry;
arg@481 60 c->w = c->rw;
arg@481 61 c->h = c->rh;
arg@480 62 }
arg@480 63 resize(c, True, TopLeft);
arg@480 64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 65 }
arg@430 66
arg@327 67 /* extern */
arg@327 68
arg@533 69 void (*arrange)(void) = DEFMODE;
arg@327 70
arg@327 71 void
arg@461 72 detach(Client *c) {
arg@378 73 if(c->prev)
arg@378 74 c->prev->next = c->next;
arg@378 75 if(c->next)
arg@378 76 c->next->prev = c->prev;
arg@378 77 if(c == clients)
arg@378 78 clients = c->next;
arg@378 79 c->next = c->prev = NULL;
arg@378 80 }
arg@378 81
arg@378 82 void
arg@533 83 dofloat(void) {
arg@402 84 Client *c;
arg@400 85
arg@327 86 for(c = clients; c; c = c->next) {
arg@327 87 if(isvisible(c)) {
arg@327 88 resize(c, True, TopLeft);
arg@327 89 }
arg@327 90 else
arg@327 91 ban(c);
arg@327 92 }
arg@446 93 if(!sel || !isvisible(sel)) {
arg@450 94 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 95 focus(c);
arg@446 96 }
arg@327 97 restack();
arg@327 98 }
arg@327 99
arg@327 100 void
arg@533 101 dotile(void) {
arg@565 102 unsigned int i, n, mpx, stackw, th;
arg@402 103 Client *c;
arg@400 104
arg@488 105 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 106 n++;
arg@565 107 mpx = (waw * master) / 1000;
arg@565 108 stackw = waw - mpx;
arg@327 109
arg@535 110 for(i = 0, c = clients; c; c = c->next)
arg@327 111 if(isvisible(c)) {
arg@327 112 if(c->isfloat) {
arg@327 113 resize(c, True, TopLeft);
arg@327 114 continue;
arg@327 115 }
arg@488 116 c->ismax = False;
arg@565 117 c->x = wax;
arg@565 118 c->y = way;
arg@507 119 if(n == 1) { /* only 1 window */
arg@565 120 c->w = waw - 2 * BORDERPX;
arg@565 121 c->h = wah - 2 * BORDERPX;
arg@327 122 }
arg@507 123 else if(i == 0) { /* master window */
arg@565 124 c->w = waw - stackw - 2 * BORDERPX;
arg@565 125 c->h = wah - 2 * BORDERPX;
arg@565 126 th = wah / (n - 1);
arg@507 127 }
arg@523 128 else { /* tile window */
arg@531 129 c->x += mpx;
arg@531 130 c->w = stackw - 2 * BORDERPX;
arg@523 131 if(th > bh) {
arg@565 132 c->y = way + (i - 1) * th;
arg@565 133 c->h = th - 2 * BORDERPX;
arg@507 134 }
arg@531 135 else /* fallback if th < bh */
arg@565 136 c->h = wah - 2 * BORDERPX;
arg@327 137 }
arg@327 138 resize(c, False, TopLeft);
arg@535 139 i++;
arg@327 140 }
arg@327 141 else
arg@327 142 ban(c);
arg@532 143
arg@446 144 if(!sel || !isvisible(sel)) {
arg@450 145 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 146 focus(c);
arg@446 147 }
arg@327 148 restack();
arg@327 149 }
arg@327 150
arg@327 151 void
arg@461 152 focusnext(Arg *arg) {
arg@327 153 Client *c;
arg@327 154
arg@327 155 if(!sel)
arg@327 156 return;
arg@327 157 if(!(c = getnext(sel->next)))
arg@327 158 c = getnext(clients);
arg@327 159 if(c) {
arg@327 160 focus(c);
arg@327 161 restack();
arg@327 162 }
arg@327 163 }
arg@327 164
arg@327 165 void
arg@461 166 focusprev(Arg *arg) {
arg@327 167 Client *c;
arg@327 168
arg@327 169 if(!sel)
arg@327 170 return;
arg@327 171 if(!(c = getprev(sel->prev))) {
arg@327 172 for(c = clients; c && c->next; c = c->next);
arg@327 173 c = getprev(c);
arg@327 174 }
arg@327 175 if(c) {
arg@327 176 focus(c);
arg@327 177 restack();
arg@327 178 }
arg@327 179 }
arg@327 180
arg@420 181 Bool
arg@461 182 isvisible(Client *c) {
arg@420 183 unsigned int i;
arg@420 184
arg@420 185 for(i = 0; i < ntags; i++)
arg@420 186 if(c->tags[i] && seltag[i])
arg@420 187 return True;
arg@420 188 return False;
arg@420 189 }
arg@420 190
arg@415 191 void
arg@559 192 resizemaster(Arg *arg) {
arg@561 193 if(arg->i == 0)
arg@561 194 master = MASTER;
arg@561 195 else {
arg@561 196 if(master + arg->i > 950 || master + arg->i < 50)
arg@561 197 return;
arg@561 198 master += arg->i;
arg@561 199 }
arg@533 200 arrange();
arg@415 201 }
arg@415 202
arg@327 203 void
arg@487 204 restack(void) {
arg@327 205 Client *c;
arg@327 206 XEvent ev;
arg@481 207
arg@437 208 if(!sel) {
arg@437 209 drawstatus();
arg@436 210 return;
arg@437 211 }
arg@436 212 if(sel->isfloat || arrange == dofloat) {
arg@436 213 XRaiseWindow(dpy, sel->win);
arg@436 214 XRaiseWindow(dpy, sel->twin);
arg@436 215 }
arg@512 216 if(arrange != dofloat) {
arg@512 217 if(!sel->isfloat) {
arg@512 218 XLowerWindow(dpy, sel->twin);
arg@512 219 XLowerWindow(dpy, sel->win);
arg@512 220 }
arg@436 221 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 222 if(c == sel)
arg@512 223 continue;
arg@436 224 XLowerWindow(dpy, c->twin);
arg@436 225 XLowerWindow(dpy, c->win);
arg@327 226 }
arg@512 227 }
arg@327 228 drawall();
arg@327 229 XSync(dpy, False);
arg@327 230 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 231 }
arg@327 232
arg@327 233 void
arg@461 234 togglemode(Arg *arg) {
arg@333 235 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 236 if(sel)
arg@533 237 arrange();
arg@327 238 else
arg@327 239 drawstatus();
arg@327 240 }
arg@327 241
arg@327 242 void
arg@461 243 toggleview(Arg *arg) {
arg@327 244 unsigned int i;
arg@327 245
arg@327 246 seltag[arg->i] = !seltag[arg->i];
arg@327 247 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 248 if(i == ntags)
arg@327 249 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 250 reorder();
arg@533 251 arrange();
arg@327 252 }
arg@327 253
arg@327 254 void
arg@461 255 view(Arg *arg) {
arg@327 256 unsigned int i;
arg@327 257
arg@327 258 for(i = 0; i < ntags; i++)
arg@327 259 seltag[i] = False;
arg@327 260 seltag[arg->i] = True;
arg@381 261 reorder();
arg@533 262 arrange();
arg@327 263 }
arg@327 264
arg@327 265 void
arg@461 266 viewall(Arg *arg) {
arg@395 267 unsigned int i;
arg@395 268
arg@395 269 for(i = 0; i < ntags; i++)
arg@395 270 seltag[i] = True;
arg@397 271 reorder();
arg@533 272 arrange();
arg@395 273 }
arg@395 274
arg@395 275 void
arg@461 276 zoom(Arg *arg) {
arg@423 277 unsigned int n;
arg@423 278 Client *c;
arg@473 279
arg@473 280 if(!sel)
arg@473 281 return;
arg@473 282 if(sel->isfloat || (arrange == dofloat)) {
arg@480 283 togglemax(sel);
arg@473 284 return;
arg@473 285 }
arg@430 286 for(n = 0, c = clients; c; c = c->next)
arg@430 287 if(isvisible(c) && !c->isfloat)
arg@423 288 n++;
arg@486 289 if(n < 2 || (arrange == dofloat))
arg@327 290 return;
arg@430 291 if((c = sel) == nexttiled(clients))
arg@433 292 if(!(c = nexttiled(c->next)))
arg@429 293 return;
arg@443 294 detach(c);
arg@443 295 if(clients)
arg@443 296 clients->prev = c;
arg@443 297 c->next = clients;
arg@443 298 clients = c;
arg@378 299 focus(c);
arg@533 300 arrange();
arg@327 301 }