aewl

annotate view.c @ 638:276238ad9516

small simplification to dotile() (thx to Ross for this hint)
author arg@mig29
date Wed, 20 Dec 2006 12:07:05 +0100
parents c7f84f23ec5a
children e90bf387bf6f
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@480 9 nexttiled(Client *c) {
arg@480 10 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
arg@480 11 return c;
arg@480 12 }
arg@480 13
arg@442 14 static void
arg@532 15 togglemax(Client *c) {
arg@481 16 XEvent ev;
arg@548 17
arg@549 18 if(c->isfixed)
arg@548 19 return;
arg@532 20
arg@480 21 if((c->ismax = !c->ismax)) {
arg@565 22 c->rx = c->x; c->x = wax;
arg@565 23 c->ry = c->y; c->y = way;
arg@565 24 c->rw = c->w; c->w = waw - 2 * BORDERPX;
arg@565 25 c->rh = c->h; c->h = wah - 2 * BORDERPX;
arg@480 26 }
arg@480 27 else {
arg@480 28 c->x = c->rx;
arg@480 29 c->y = c->ry;
arg@481 30 c->w = c->rw;
arg@481 31 c->h = c->rh;
arg@480 32 }
arg@480 33 resize(c, True, TopLeft);
arg@480 34 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 35 }
arg@430 36
arg@327 37 /* extern */
arg@327 38
arg@533 39 void (*arrange)(void) = DEFMODE;
arg@327 40
arg@327 41 void
arg@461 42 detach(Client *c) {
arg@378 43 if(c->prev)
arg@378 44 c->prev->next = c->next;
arg@378 45 if(c->next)
arg@378 46 c->next->prev = c->prev;
arg@378 47 if(c == clients)
arg@378 48 clients = c->next;
arg@378 49 c->next = c->prev = NULL;
arg@378 50 }
arg@378 51
arg@378 52 void
arg@533 53 dofloat(void) {
arg@402 54 Client *c;
arg@400 55
arg@327 56 for(c = clients; c; c = c->next) {
arg@327 57 if(isvisible(c)) {
arg@327 58 resize(c, True, TopLeft);
arg@327 59 }
arg@327 60 else
arg@327 61 ban(c);
arg@327 62 }
arg@446 63 if(!sel || !isvisible(sel)) {
arg@450 64 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 65 focus(c);
arg@446 66 }
arg@327 67 restack();
arg@327 68 }
arg@327 69
arg@327 70 void
arg@533 71 dotile(void) {
arg@638 72 unsigned int i, n, mpw, th;
arg@402 73 Client *c;
arg@400 74
arg@488 75 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 76 n++;
arg@638 77 mpw = (waw * master) / 1000;
arg@327 78
arg@535 79 for(i = 0, c = clients; c; c = c->next)
arg@327 80 if(isvisible(c)) {
arg@327 81 if(c->isfloat) {
arg@327 82 resize(c, True, TopLeft);
arg@327 83 continue;
arg@327 84 }
arg@488 85 c->ismax = False;
arg@565 86 c->x = wax;
arg@565 87 c->y = way;
arg@507 88 if(n == 1) { /* only 1 window */
arg@565 89 c->w = waw - 2 * BORDERPX;
arg@565 90 c->h = wah - 2 * BORDERPX;
arg@327 91 }
arg@507 92 else if(i == 0) { /* master window */
arg@638 93 c->w = mpw - 2 * BORDERPX;
arg@565 94 c->h = wah - 2 * BORDERPX;
arg@565 95 th = wah / (n - 1);
arg@507 96 }
arg@523 97 else { /* tile window */
arg@638 98 c->x += mpw;
arg@638 99 c->w = (waw - mpw) - 2 * BORDERPX;
arg@523 100 if(th > bh) {
arg@588 101 c->y += (i - 1) * th;
arg@565 102 c->h = th - 2 * BORDERPX;
arg@507 103 }
arg@531 104 else /* fallback if th < bh */
arg@565 105 c->h = wah - 2 * BORDERPX;
arg@327 106 }
arg@327 107 resize(c, False, TopLeft);
arg@535 108 i++;
arg@327 109 }
arg@327 110 else
arg@327 111 ban(c);
arg@532 112
arg@446 113 if(!sel || !isvisible(sel)) {
arg@450 114 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 115 focus(c);
arg@446 116 }
arg@327 117 restack();
arg@327 118 }
arg@327 119
arg@327 120 void
arg@461 121 focusnext(Arg *arg) {
arg@327 122 Client *c;
arg@327 123
arg@327 124 if(!sel)
arg@327 125 return;
arg@327 126 if(!(c = getnext(sel->next)))
arg@327 127 c = getnext(clients);
arg@327 128 if(c) {
arg@327 129 focus(c);
arg@327 130 restack();
arg@327 131 }
arg@327 132 }
arg@327 133
arg@327 134 void
arg@461 135 focusprev(Arg *arg) {
arg@327 136 Client *c;
arg@327 137
arg@327 138 if(!sel)
arg@327 139 return;
arg@327 140 if(!(c = getprev(sel->prev))) {
arg@327 141 for(c = clients; c && c->next; c = c->next);
arg@327 142 c = getprev(c);
arg@327 143 }
arg@327 144 if(c) {
arg@327 145 focus(c);
arg@327 146 restack();
arg@327 147 }
arg@327 148 }
arg@327 149
arg@420 150 Bool
arg@461 151 isvisible(Client *c) {
arg@420 152 unsigned int i;
arg@420 153
arg@420 154 for(i = 0; i < ntags; i++)
arg@420 155 if(c->tags[i] && seltag[i])
arg@420 156 return True;
arg@420 157 return False;
arg@420 158 }
arg@420 159
arg@415 160 void
arg@559 161 resizemaster(Arg *arg) {
arg@561 162 if(arg->i == 0)
arg@561 163 master = MASTER;
arg@561 164 else {
arg@561 165 if(master + arg->i > 950 || master + arg->i < 50)
arg@561 166 return;
arg@561 167 master += arg->i;
arg@561 168 }
arg@533 169 arrange();
arg@415 170 }
arg@415 171
arg@327 172 void
arg@487 173 restack(void) {
arg@327 174 Client *c;
arg@327 175 XEvent ev;
arg@481 176
arg@437 177 if(!sel) {
arg@437 178 drawstatus();
arg@436 179 return;
arg@437 180 }
arg@436 181 if(sel->isfloat || arrange == dofloat) {
arg@436 182 XRaiseWindow(dpy, sel->win);
arg@436 183 XRaiseWindow(dpy, sel->twin);
arg@436 184 }
arg@512 185 if(arrange != dofloat) {
arg@512 186 if(!sel->isfloat) {
arg@512 187 XLowerWindow(dpy, sel->twin);
arg@512 188 XLowerWindow(dpy, sel->win);
arg@512 189 }
arg@436 190 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 191 if(c == sel)
arg@512 192 continue;
arg@436 193 XLowerWindow(dpy, c->twin);
arg@436 194 XLowerWindow(dpy, c->win);
arg@327 195 }
arg@512 196 }
arg@327 197 drawall();
arg@327 198 XSync(dpy, False);
arg@327 199 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 200 }
arg@327 201
arg@327 202 void
arg@584 203 togglefloat(Arg *arg) {
arg@591 204 if (!sel || arrange == dofloat)
arg@584 205 return;
arg@584 206 sel->isfloat = !sel->isfloat;
arg@584 207 arrange();
arg@584 208 }
arg@584 209
arg@584 210 void
arg@461 211 togglemode(Arg *arg) {
arg@333 212 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 213 if(sel)
arg@533 214 arrange();
arg@327 215 else
arg@327 216 drawstatus();
arg@327 217 }
arg@327 218
arg@327 219 void
arg@461 220 toggleview(Arg *arg) {
arg@327 221 unsigned int i;
arg@327 222
arg@327 223 seltag[arg->i] = !seltag[arg->i];
arg@327 224 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 225 if(i == ntags)
arg@327 226 seltag[arg->i] = True; /* cannot toggle last view */
arg@533 227 arrange();
arg@327 228 }
arg@327 229
arg@327 230 void
arg@461 231 view(Arg *arg) {
arg@327 232 unsigned int i;
arg@327 233
arg@327 234 for(i = 0; i < ntags; i++)
arg@594 235 seltag[i] = (arg->i == -1) ? True : False;
arg@611 236 if(arg->i >= 0 && arg->i < ntags)
arg@611 237 seltag[arg->i] = True;
arg@533 238 arrange();
arg@327 239 }
arg@327 240
arg@327 241 void
arg@461 242 zoom(Arg *arg) {
arg@423 243 unsigned int n;
arg@423 244 Client *c;
arg@473 245
arg@473 246 if(!sel)
arg@473 247 return;
arg@473 248 if(sel->isfloat || (arrange == dofloat)) {
arg@480 249 togglemax(sel);
arg@473 250 return;
arg@473 251 }
arg@430 252 for(n = 0, c = clients; c; c = c->next)
arg@430 253 if(isvisible(c) && !c->isfloat)
arg@423 254 n++;
arg@486 255 if(n < 2 || (arrange == dofloat))
arg@327 256 return;
arg@430 257 if((c = sel) == nexttiled(clients))
arg@433 258 if(!(c = nexttiled(c->next)))
arg@429 259 return;
arg@443 260 detach(c);
arg@443 261 if(clients)
arg@443 262 clients->prev = c;
arg@443 263 c->next = clients;
arg@443 264 clients = c;
arg@378 265 focus(c);
arg@533 266 arrange();
arg@327 267 }