dwm-meillo

annotate view.c @ 511:1599c953647b

removed the direction flipping
author Anselm R. Garbe <arg@10kloc.org>
date Fri, 29 Sep 2006 17:02:56 +0200
parents 0dfa6b752aed
children aca04c3022c1
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@508 197 c->y = sy + master;
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@423 262 unsigned int n;
arg@423 263 Client *c;
arg@418 264
arg@430 265 for(n = 0, c = clients; c; c = c->next)
arg@430 266 if(isvisible(c) && !c->isfloat)
arg@423 267 n++;
arg@486 268 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
arg@415 269 return;
arg@423 270
arg@415 271 if(sel == getnext(clients)) {
arg@507 272 if(master + arg->i > sw - MINW || master + arg->i < MINW)
arg@415 273 return;
arg@505 274 master += arg->i;
arg@415 275 }
arg@415 276 else {
arg@507 277 if(master - arg->i > sw - MINW || master - arg->i < MINW)
arg@415 278 return;
arg@505 279 master -= arg->i;
arg@415 280 }
arg@415 281 arrange(NULL);
arg@415 282 }
arg@415 283
arg@327 284 void
arg@487 285 restack(void) {
arg@327 286 Client *c;
arg@327 287 XEvent ev;
arg@481 288
arg@437 289 if(!sel) {
arg@437 290 drawstatus();
arg@436 291 return;
arg@437 292 }
arg@436 293 if(sel->isfloat || arrange == dofloat) {
arg@436 294 XRaiseWindow(dpy, sel->win);
arg@436 295 XRaiseWindow(dpy, sel->twin);
arg@436 296 }
arg@446 297 if(arrange != dofloat)
arg@436 298 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@436 299 XLowerWindow(dpy, c->twin);
arg@436 300 XLowerWindow(dpy, c->win);
arg@327 301 }
arg@327 302 drawall();
arg@327 303 XSync(dpy, False);
arg@327 304 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 305 }
arg@327 306
arg@327 307 void
arg@461 308 togglemode(Arg *arg) {
arg@333 309 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 310 if(sel)
arg@327 311 arrange(NULL);
arg@327 312 else
arg@327 313 drawstatus();
arg@327 314 }
arg@327 315
arg@327 316 void
arg@461 317 toggleview(Arg *arg) {
arg@327 318 unsigned int i;
arg@327 319
arg@327 320 seltag[arg->i] = !seltag[arg->i];
arg@327 321 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 322 if(i == ntags)
arg@327 323 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 324 reorder();
arg@327 325 arrange(NULL);
arg@327 326 }
arg@327 327
arg@327 328 void
arg@508 329 togglestackpos(Arg *arg) {
arg@508 330 if(arrange == dofloat)
arg@508 331 return;
arg@508 332 if(stackpos == StackBottom)
arg@508 333 stackpos = STACKPOS;
arg@508 334 else
arg@508 335 stackpos = StackBottom;
arg@508 336 updatemaster();
arg@508 337 arrange(NULL);
arg@508 338 }
arg@508 339
arg@508 340 void
arg@508 341 updatemaster(void) {
arg@508 342 master = ((stackpos == StackBottom ? sh - bh : sw) * MASTER) / 100;
arg@508 343 }
arg@508 344
arg@508 345 void
arg@461 346 view(Arg *arg) {
arg@327 347 unsigned int i;
arg@327 348
arg@327 349 for(i = 0; i < ntags; i++)
arg@327 350 seltag[i] = False;
arg@327 351 seltag[arg->i] = True;
arg@381 352 reorder();
arg@327 353 arrange(NULL);
arg@327 354 }
arg@327 355
arg@327 356 void
arg@461 357 viewall(Arg *arg) {
arg@395 358 unsigned int i;
arg@395 359
arg@395 360 for(i = 0; i < ntags; i++)
arg@395 361 seltag[i] = True;
arg@397 362 reorder();
arg@395 363 arrange(NULL);
arg@395 364 }
arg@395 365
arg@508 366
arg@508 367
arg@395 368 void
arg@461 369 zoom(Arg *arg) {
arg@423 370 unsigned int n;
arg@423 371 Client *c;
arg@473 372
arg@473 373 if(!sel)
arg@473 374 return;
arg@473 375
arg@473 376 if(sel->isfloat || (arrange == dofloat)) {
arg@480 377 togglemax(sel);
arg@473 378 return;
arg@473 379 }
arg@327 380
arg@430 381 for(n = 0, c = clients; c; c = c->next)
arg@430 382 if(isvisible(c) && !c->isfloat)
arg@423 383 n++;
arg@486 384 if(n < 2 || (arrange == dofloat))
arg@327 385 return;
arg@327 386
arg@430 387 if((c = sel) == nexttiled(clients))
arg@433 388 if(!(c = nexttiled(c->next)))
arg@429 389 return;
arg@443 390 detach(c);
arg@443 391 if(clients)
arg@443 392 clients->prev = c;
arg@443 393 c->next = clients;
arg@443 394 clients = c;
arg@378 395 focus(c);
arg@327 396 arrange(NULL);
arg@327 397 }