dwm-meillo

annotate view.c @ 558:e249e2952a32

applied Gottox patch to simplify the resizing of col, instead of resizing the current area, it only resizes the master area in the future (seems more predictable)
author arg@mig29
date Tue, 31 Oct 2006 12:06:38 +0100
parents fd1061442711
children a2c465098a3b
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@487 9 minclient(void) {
arg@382 10 Client *c, *min;
arg@382 11
arg@443 12 if((clients && clients->isfloat) || arrange == dofloat)
arg@443 13 return clients; /* don't touch floating order */
arg@382 14 for(min = c = clients; c; c = c->next)
arg@382 15 if(c->weight < min->weight)
arg@382 16 min = c;
arg@382 17 return min;
arg@382 18 }
arg@382 19
arg@480 20 static Client *
arg@480 21 nexttiled(Client *c) {
arg@480 22 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
arg@480 23 return c;
arg@480 24 }
arg@480 25
arg@442 26 static void
arg@487 27 reorder(void) {
arg@382 28 Client *c, *newclients, *tail;
arg@380 29
arg@382 30 newclients = tail = NULL;
arg@382 31 while((c = minclient())) {
arg@381 32 detach(c);
arg@382 33 if(tail) {
arg@382 34 c->prev = tail;
arg@382 35 tail->next = c;
arg@382 36 tail = c;
arg@381 37 }
arg@381 38 else
arg@382 39 tail = newclients = c;
arg@380 40 }
arg@382 41 clients = newclients;
arg@380 42 }
arg@380 43
arg@480 44 static void
arg@532 45 togglemax(Client *c) {
arg@481 46 XEvent ev;
arg@548 47
arg@549 48 if(c->isfixed)
arg@548 49 return;
arg@532 50
arg@480 51 if((c->ismax = !c->ismax)) {
arg@480 52 c->rx = c->x; c->x = sx;
arg@480 53 c->ry = c->y; c->y = bh;
arg@502 54 c->rw = c->w; c->w = sw - 2 * BORDERPX;
arg@502 55 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
arg@480 56 }
arg@480 57 else {
arg@480 58 c->x = c->rx;
arg@480 59 c->y = c->ry;
arg@481 60 c->w = c->rw;
arg@481 61 c->h = c->rh;
arg@480 62 }
arg@480 63 resize(c, True, TopLeft);
arg@480 64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 65 }
arg@430 66
arg@327 67 /* extern */
arg@327 68
arg@533 69 void (*arrange)(void) = DEFMODE;
arg@327 70
arg@327 71 void
arg@461 72 detach(Client *c) {
arg@378 73 if(c->prev)
arg@378 74 c->prev->next = c->next;
arg@378 75 if(c->next)
arg@378 76 c->next->prev = c->prev;
arg@378 77 if(c == clients)
arg@378 78 clients = c->next;
arg@378 79 c->next = c->prev = NULL;
arg@378 80 }
arg@378 81
arg@378 82 void
arg@533 83 dofloat(void) {
arg@402 84 Client *c;
arg@400 85
arg@327 86 for(c = clients; c; c = c->next) {
arg@327 87 if(isvisible(c)) {
arg@327 88 resize(c, True, TopLeft);
arg@327 89 }
arg@327 90 else
arg@327 91 ban(c);
arg@327 92 }
arg@446 93 if(!sel || !isvisible(sel)) {
arg@450 94 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 95 focus(c);
arg@446 96 }
arg@327 97 restack();
arg@327 98 }
arg@327 99
arg@327 100 void
arg@533 101 dotile(void) {
arg@531 102 unsigned int i, n, mpx, stackw, stackh, th;
arg@402 103 Client *c;
arg@400 104
arg@488 105 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 106 n++;
arg@531 107 mpx = (sw * master) / 1000;
arg@531 108 stackw = sw - mpx;
arg@530 109 stackh = sh - bh;
arg@530 110 th = stackh;
arg@511 111 if(n > 1)
arg@530 112 th /= (n - 1);
arg@327 113
arg@535 114 for(i = 0, c = clients; c; c = c->next)
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@535 145 i++;
arg@327 146 }
arg@327 147 else
arg@327 148 ban(c);
arg@532 149
arg@446 150 if(!sel || !isvisible(sel)) {
arg@450 151 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 152 focus(c);
arg@446 153 }
arg@327 154 restack();
arg@327 155 }
arg@327 156
arg@327 157 void
arg@461 158 focusnext(Arg *arg) {
arg@327 159 Client *c;
arg@327 160
arg@327 161 if(!sel)
arg@327 162 return;
arg@327 163 if(!(c = getnext(sel->next)))
arg@327 164 c = getnext(clients);
arg@327 165 if(c) {
arg@327 166 focus(c);
arg@327 167 restack();
arg@327 168 }
arg@327 169 }
arg@327 170
arg@327 171 void
arg@461 172 focusprev(Arg *arg) {
arg@327 173 Client *c;
arg@327 174
arg@327 175 if(!sel)
arg@327 176 return;
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@558 199 if(master + arg->i > 950 || master + arg->i < 50)
arg@415 200 return;
arg@558 201 master += arg->i;
arg@533 202 arrange();
arg@415 203 }
arg@415 204
arg@327 205 void
arg@487 206 restack(void) {
arg@327 207 Client *c;
arg@327 208 XEvent ev;
arg@481 209
arg@437 210 if(!sel) {
arg@437 211 drawstatus();
arg@436 212 return;
arg@437 213 }
arg@436 214 if(sel->isfloat || arrange == dofloat) {
arg@436 215 XRaiseWindow(dpy, sel->win);
arg@436 216 XRaiseWindow(dpy, sel->twin);
arg@436 217 }
arg@512 218 if(arrange != dofloat) {
arg@512 219 if(!sel->isfloat) {
arg@512 220 XLowerWindow(dpy, sel->twin);
arg@512 221 XLowerWindow(dpy, sel->win);
arg@512 222 }
arg@436 223 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 224 if(c == sel)
arg@512 225 continue;
arg@436 226 XLowerWindow(dpy, c->twin);
arg@436 227 XLowerWindow(dpy, c->win);
arg@327 228 }
arg@512 229 }
arg@327 230 drawall();
arg@327 231 XSync(dpy, False);
arg@327 232 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 233 }
arg@327 234
arg@327 235 void
arg@461 236 togglemode(Arg *arg) {
arg@333 237 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 238 if(sel)
arg@533 239 arrange();
arg@327 240 else
arg@327 241 drawstatus();
arg@327 242 }
arg@327 243
arg@327 244 void
arg@461 245 toggleview(Arg *arg) {
arg@327 246 unsigned int i;
arg@327 247
arg@327 248 seltag[arg->i] = !seltag[arg->i];
arg@327 249 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 250 if(i == ntags)
arg@327 251 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 252 reorder();
arg@533 253 arrange();
arg@327 254 }
arg@327 255
arg@327 256 void
arg@461 257 view(Arg *arg) {
arg@327 258 unsigned int i;
arg@327 259
arg@327 260 for(i = 0; i < ntags; i++)
arg@327 261 seltag[i] = False;
arg@327 262 seltag[arg->i] = True;
arg@381 263 reorder();
arg@533 264 arrange();
arg@327 265 }
arg@327 266
arg@327 267 void
arg@461 268 viewall(Arg *arg) {
arg@395 269 unsigned int i;
arg@395 270
arg@395 271 for(i = 0; i < ntags; i++)
arg@395 272 seltag[i] = True;
arg@397 273 reorder();
arg@533 274 arrange();
arg@395 275 }
arg@395 276
arg@395 277 void
arg@461 278 zoom(Arg *arg) {
arg@423 279 unsigned int n;
arg@423 280 Client *c;
arg@473 281
arg@473 282 if(!sel)
arg@473 283 return;
arg@473 284 if(sel->isfloat || (arrange == dofloat)) {
arg@480 285 togglemax(sel);
arg@473 286 return;
arg@473 287 }
arg@430 288 for(n = 0, c = clients; c; c = c->next)
arg@430 289 if(isvisible(c) && !c->isfloat)
arg@423 290 n++;
arg@486 291 if(n < 2 || (arrange == dofloat))
arg@327 292 return;
arg@430 293 if((c = sel) == nexttiled(clients))
arg@433 294 if(!(c = nexttiled(c->next)))
arg@429 295 return;
arg@443 296 detach(c);
arg@443 297 if(clients)
arg@443 298 clients->prev = c;
arg@443 299 c->next = clients;
arg@443 300 clients = c;
arg@378 301 focus(c);
arg@533 302 arrange();
arg@327 303 }