aewl

annotate view.c @ 531:96563762b4ad

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