dwm-meillo

annotate view.c @ 521:73afe7587bea

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