aewl

annotate view.c @ 525:7433954e80af

final fix for man page
author Anselm R. Garbe <arg@10kloc.org>
date Thu, 05 Oct 2006 13:44:48 +0200
parents c1dd19da63ef
children c71952fa3c7c
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@505 68 StackPos stackpos = STACKPOS;
arg@327 69
arg@327 70 void
arg@461 71 detach(Client *c) {
arg@378 72 if(c->prev)
arg@378 73 c->prev->next = c->next;
arg@378 74 if(c->next)
arg@378 75 c->next->prev = c->prev;
arg@378 76 if(c == clients)
arg@378 77 clients = c->next;
arg@378 78 c->next = c->prev = NULL;
arg@378 79 }
arg@378 80
arg@378 81 void
arg@461 82 dofloat(Arg *arg) {
arg@402 83 Client *c;
arg@400 84
arg@327 85 for(c = clients; c; c = c->next) {
arg@327 86 if(isvisible(c)) {
arg@327 87 resize(c, True, TopLeft);
arg@327 88 }
arg@327 89 else
arg@327 90 ban(c);
arg@327 91 }
arg@446 92 if(!sel || !isvisible(sel)) {
arg@450 93 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 94 focus(c);
arg@446 95 }
arg@327 96 restack();
arg@327 97 }
arg@327 98
arg@504 99 /* This algorithm is based on a (M)aster area and a (S)tacking area.
arg@504 100 * It supports following arrangements:
arg@507 101 * SSMMM MMMMM MMMSS
arg@507 102 * SSMMM SSSSS MMMSS
arg@504 103 */
arg@327 104 void
arg@461 105 dotile(Arg *arg) {
arg@507 106 int i, n, stackw, stackh, tw, th;
arg@524 107 unsigned int md = ((stackpos == StackBottom ? sh - bh : sw) * master) / 100;
arg@402 108 Client *c;
arg@400 109
arg@488 110 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 111 n++;
arg@327 112
arg@507 113 if(stackpos == StackBottom) {
arg@507 114 stackw = sw;
arg@524 115 stackh = sh - bh - md;
arg@507 116 }
arg@507 117 else {
arg@524 118 stackw = sw - md;
arg@507 119 stackh = sh - bh;
arg@507 120 }
arg@507 121
arg@511 122 tw = stackw;
arg@511 123 if(n > 1)
arg@511 124 th = stackh / (n - 1);
arg@511 125 else
arg@507 126 th = stackh;
arg@327 127
arg@327 128 for(i = 0, c = clients; c; c = c->next) {
arg@327 129 if(isvisible(c)) {
arg@327 130 if(c->isfloat) {
arg@327 131 resize(c, True, TopLeft);
arg@327 132 continue;
arg@327 133 }
arg@488 134 c->ismax = False;
arg@523 135 c->x = sx;
arg@523 136 c->y = sy + bh;
arg@507 137 if(n == 1) { /* only 1 window */
arg@502 138 c->w = sw - 2 * BORDERPX;
arg@502 139 c->h = sh - 2 * BORDERPX - bh;
arg@327 140 }
arg@507 141 else if(i == 0) { /* master window */
arg@522 142 if(stackpos == StackLeft)
arg@522 143 c->x += stackw;
arg@508 144 switch(stackpos) {
arg@508 145 case StackLeft:
arg@522 146 case StackRight:
arg@524 147 c->w = md - 2 * BORDERPX;
arg@508 148 c->h = sh - bh - 2 * BORDERPX;
arg@508 149 break;
arg@508 150 case StackBottom:
arg@508 151 c->w = sw - 2 * BORDERPX;
arg@524 152 c->h = md - 2 * BORDERPX;
arg@508 153 break;
arg@507 154 }
arg@507 155 }
arg@523 156 else { /* tile window */
arg@522 157 if(stackpos == StackRight)
arg@524 158 c->x += md;
arg@523 159 if(th > bh) {
arg@523 160 switch(stackpos) {
arg@523 161 case StackLeft:
arg@523 162 case StackRight:
arg@523 163 c->y = sy + (i - 1) * th + bh;
arg@523 164 if(i + 1 == n)
arg@523 165 c->h = sh - c->y - 2 * BORDERPX;
arg@523 166 break;
arg@523 167 case StackBottom:
arg@524 168 c->y = sy + md + (i - 1) * th + bh;
arg@523 169 if(i + 1 == n)
arg@523 170 c->h = sh - c->y - 2 * BORDERPX;
arg@523 171 break;
arg@523 172 }
arg@523 173 c->w = tw - 2 * BORDERPX;
arg@523 174 c->h = th - 2 * BORDERPX;
arg@507 175 }
arg@523 176 else { /* fallback if th < bh */
arg@523 177 if(stackpos == StackBottom)
arg@524 178 c->y += md;
arg@523 179 c->w = stackw - 2 * BORDERPX;
arg@523 180 c->h = stackh - 2 * BORDERPX;
arg@523 181 }
arg@327 182 }
arg@327 183 resize(c, False, TopLeft);
arg@327 184 i++;
arg@327 185 }
arg@327 186 else
arg@327 187 ban(c);
arg@327 188 }
arg@446 189 if(!sel || !isvisible(sel)) {
arg@450 190 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 191 focus(c);
arg@446 192 }
arg@327 193 restack();
arg@327 194 }
arg@327 195
arg@327 196 void
arg@461 197 focusnext(Arg *arg) {
arg@327 198 Client *c;
arg@327 199
arg@327 200 if(!sel)
arg@327 201 return;
arg@327 202
arg@327 203 if(!(c = getnext(sel->next)))
arg@327 204 c = getnext(clients);
arg@327 205 if(c) {
arg@327 206 focus(c);
arg@327 207 restack();
arg@327 208 }
arg@327 209 }
arg@327 210
arg@327 211 void
arg@461 212 focusprev(Arg *arg) {
arg@327 213 Client *c;
arg@327 214
arg@327 215 if(!sel)
arg@327 216 return;
arg@327 217
arg@327 218 if(!(c = getprev(sel->prev))) {
arg@327 219 for(c = clients; c && c->next; c = c->next);
arg@327 220 c = getprev(c);
arg@327 221 }
arg@327 222 if(c) {
arg@327 223 focus(c);
arg@327 224 restack();
arg@327 225 }
arg@327 226 }
arg@327 227
arg@420 228 Bool
arg@461 229 isvisible(Client *c) {
arg@420 230 unsigned int i;
arg@420 231
arg@420 232 for(i = 0; i < ntags; i++)
arg@420 233 if(c->tags[i] && seltag[i])
arg@420 234 return True;
arg@420 235 return False;
arg@420 236 }
arg@420 237
arg@415 238 void
arg@461 239 resizecol(Arg *arg) {
arg@423 240 unsigned int n;
arg@423 241 Client *c;
arg@418 242
arg@430 243 for(n = 0, c = clients; c; c = c->next)
arg@430 244 if(isvisible(c) && !c->isfloat)
arg@423 245 n++;
arg@486 246 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
arg@415 247 return;
arg@423 248
arg@415 249 if(sel == getnext(clients)) {
arg@524 250 if(master + arg->i > 95 || master + arg->i < 5)
arg@415 251 return;
arg@505 252 master += arg->i;
arg@415 253 }
arg@415 254 else {
arg@524 255 if(master - arg->i > 95 || master - arg->i < 5)
arg@415 256 return;
arg@505 257 master -= arg->i;
arg@415 258 }
arg@415 259 arrange(NULL);
arg@415 260 }
arg@415 261
arg@327 262 void
arg@487 263 restack(void) {
arg@327 264 Client *c;
arg@327 265 XEvent ev;
arg@481 266
arg@437 267 if(!sel) {
arg@437 268 drawstatus();
arg@436 269 return;
arg@437 270 }
arg@436 271 if(sel->isfloat || arrange == dofloat) {
arg@436 272 XRaiseWindow(dpy, sel->win);
arg@436 273 XRaiseWindow(dpy, sel->twin);
arg@436 274 }
arg@512 275 if(arrange != dofloat) {
arg@512 276 if(!sel->isfloat) {
arg@512 277 XLowerWindow(dpy, sel->twin);
arg@512 278 XLowerWindow(dpy, sel->win);
arg@512 279 }
arg@436 280 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 281 if(c == sel)
arg@512 282 continue;
arg@436 283 XLowerWindow(dpy, c->twin);
arg@436 284 XLowerWindow(dpy, c->win);
arg@327 285 }
arg@512 286 }
arg@327 287 drawall();
arg@327 288 XSync(dpy, False);
arg@327 289 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 290 }
arg@327 291
arg@327 292 void
arg@461 293 togglemode(Arg *arg) {
arg@333 294 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 295 if(sel)
arg@327 296 arrange(NULL);
arg@327 297 else
arg@327 298 drawstatus();
arg@327 299 }
arg@327 300
arg@327 301 void
arg@461 302 toggleview(Arg *arg) {
arg@327 303 unsigned int i;
arg@327 304
arg@327 305 seltag[arg->i] = !seltag[arg->i];
arg@327 306 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 307 if(i == ntags)
arg@327 308 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 309 reorder();
arg@327 310 arrange(NULL);
arg@327 311 }
arg@327 312
arg@327 313 void
arg@508 314 togglestackpos(Arg *arg) {
arg@508 315 if(arrange == dofloat)
arg@508 316 return;
arg@508 317 if(stackpos == StackBottom)
arg@508 318 stackpos = STACKPOS;
arg@508 319 else
arg@508 320 stackpos = StackBottom;
arg@508 321 arrange(NULL);
arg@508 322 }
arg@508 323
arg@508 324 void
arg@461 325 view(Arg *arg) {
arg@327 326 unsigned int i;
arg@327 327
arg@327 328 for(i = 0; i < ntags; i++)
arg@327 329 seltag[i] = False;
arg@327 330 seltag[arg->i] = True;
arg@381 331 reorder();
arg@327 332 arrange(NULL);
arg@327 333 }
arg@327 334
arg@327 335 void
arg@461 336 viewall(Arg *arg) {
arg@395 337 unsigned int i;
arg@395 338
arg@395 339 for(i = 0; i < ntags; i++)
arg@395 340 seltag[i] = True;
arg@397 341 reorder();
arg@395 342 arrange(NULL);
arg@395 343 }
arg@395 344
arg@508 345
arg@508 346
arg@395 347 void
arg@461 348 zoom(Arg *arg) {
arg@423 349 unsigned int n;
arg@423 350 Client *c;
arg@473 351
arg@473 352 if(!sel)
arg@473 353 return;
arg@473 354
arg@473 355 if(sel->isfloat || (arrange == dofloat)) {
arg@480 356 togglemax(sel);
arg@473 357 return;
arg@473 358 }
arg@327 359
arg@430 360 for(n = 0, c = clients; c; c = c->next)
arg@430 361 if(isvisible(c) && !c->isfloat)
arg@423 362 n++;
arg@486 363 if(n < 2 || (arrange == dofloat))
arg@327 364 return;
arg@327 365
arg@430 366 if((c = sel) == nexttiled(clients))
arg@433 367 if(!(c = nexttiled(c->next)))
arg@429 368 return;
arg@443 369 detach(c);
arg@443 370 if(clients)
arg@443 371 clients->prev = c;
arg@443 372 c->next = clients;
arg@443 373 clients = c;
arg@378 374 focus(c);
arg@327 375 arrange(NULL);
arg@327 376 }