dwm-meillo

annotate view.c @ 548:3d23384eb5ab

applied sanders max size fix
author arg@mig29
date Fri, 27 Oct 2006 12:05:47 +0200
parents 13ef0d218c67
children fd1061442711
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@548 48 if (x->maxw && x->minw && x->maxh && x->minh &&
arg@548 49 x->maxw == x->minw && x->maxh == x->minh)
arg@548 50 return;
arg@532 51
arg@480 52 if((c->ismax = !c->ismax)) {
arg@480 53 c->rx = c->x; c->x = sx;
arg@480 54 c->ry = c->y; c->y = bh;
arg@502 55 c->rw = c->w; c->w = sw - 2 * BORDERPX;
arg@502 56 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
arg@480 57 }
arg@480 58 else {
arg@480 59 c->x = c->rx;
arg@480 60 c->y = c->ry;
arg@481 61 c->w = c->rw;
arg@481 62 c->h = c->rh;
arg@480 63 }
arg@480 64 resize(c, True, TopLeft);
arg@480 65 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 66 }
arg@430 67
arg@327 68 /* extern */
arg@327 69
arg@533 70 void (*arrange)(void) = DEFMODE;
arg@327 71
arg@327 72 void
arg@461 73 detach(Client *c) {
arg@378 74 if(c->prev)
arg@378 75 c->prev->next = c->next;
arg@378 76 if(c->next)
arg@378 77 c->next->prev = c->prev;
arg@378 78 if(c == clients)
arg@378 79 clients = c->next;
arg@378 80 c->next = c->prev = NULL;
arg@378 81 }
arg@378 82
arg@378 83 void
arg@533 84 dofloat(void) {
arg@402 85 Client *c;
arg@400 86
arg@327 87 for(c = clients; c; c = c->next) {
arg@327 88 if(isvisible(c)) {
arg@327 89 resize(c, True, TopLeft);
arg@327 90 }
arg@327 91 else
arg@327 92 ban(c);
arg@327 93 }
arg@446 94 if(!sel || !isvisible(sel)) {
arg@450 95 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 96 focus(c);
arg@446 97 }
arg@327 98 restack();
arg@327 99 }
arg@327 100
arg@327 101 void
arg@533 102 dotile(void) {
arg@531 103 unsigned int i, n, mpx, stackw, stackh, th;
arg@402 104 Client *c;
arg@400 105
arg@488 106 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 107 n++;
arg@531 108 mpx = (sw * master) / 1000;
arg@531 109 stackw = sw - mpx;
arg@530 110 stackh = sh - bh;
arg@530 111 th = stackh;
arg@511 112 if(n > 1)
arg@530 113 th /= (n - 1);
arg@327 114
arg@535 115 for(i = 0, c = clients; c; c = c->next)
arg@327 116 if(isvisible(c)) {
arg@327 117 if(c->isfloat) {
arg@327 118 resize(c, True, TopLeft);
arg@327 119 continue;
arg@327 120 }
arg@488 121 c->ismax = False;
arg@523 122 c->x = sx;
arg@523 123 c->y = sy + bh;
arg@507 124 if(n == 1) { /* only 1 window */
arg@502 125 c->w = sw - 2 * BORDERPX;
arg@502 126 c->h = sh - 2 * BORDERPX - bh;
arg@327 127 }
arg@507 128 else if(i == 0) { /* master window */
arg@531 129 c->w = mpx - 2 * BORDERPX;
arg@530 130 c->h = sh - bh - 2 * BORDERPX;
arg@507 131 }
arg@523 132 else { /* tile window */
arg@531 133 c->x += mpx;
arg@531 134 c->w = stackw - 2 * BORDERPX;
arg@523 135 if(th > bh) {
arg@530 136 c->y = sy + (i - 1) * th + bh;
arg@530 137 if(i + 1 == n)
arg@530 138 c->h = sh - c->y - 2 * BORDERPX;
arg@531 139 else
arg@531 140 c->h = th - 2 * BORDERPX;
arg@507 141 }
arg@531 142 else /* fallback if th < bh */
arg@523 143 c->h = stackh - 2 * BORDERPX;
arg@327 144 }
arg@327 145 resize(c, False, TopLeft);
arg@535 146 i++;
arg@327 147 }
arg@327 148 else
arg@327 149 ban(c);
arg@532 150
arg@446 151 if(!sel || !isvisible(sel)) {
arg@450 152 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 153 focus(c);
arg@446 154 }
arg@327 155 restack();
arg@327 156 }
arg@327 157
arg@327 158 void
arg@461 159 focusnext(Arg *arg) {
arg@327 160 Client *c;
arg@327 161
arg@327 162 if(!sel)
arg@327 163 return;
arg@327 164 if(!(c = getnext(sel->next)))
arg@327 165 c = getnext(clients);
arg@327 166 if(c) {
arg@327 167 focus(c);
arg@327 168 restack();
arg@327 169 }
arg@327 170 }
arg@327 171
arg@327 172 void
arg@461 173 focusprev(Arg *arg) {
arg@327 174 Client *c;
arg@327 175
arg@327 176 if(!sel)
arg@327 177 return;
arg@327 178 if(!(c = getprev(sel->prev))) {
arg@327 179 for(c = clients; c && c->next; c = c->next);
arg@327 180 c = getprev(c);
arg@327 181 }
arg@327 182 if(c) {
arg@327 183 focus(c);
arg@327 184 restack();
arg@327 185 }
arg@327 186 }
arg@327 187
arg@420 188 Bool
arg@461 189 isvisible(Client *c) {
arg@420 190 unsigned int i;
arg@420 191
arg@420 192 for(i = 0; i < ntags; i++)
arg@420 193 if(c->tags[i] && seltag[i])
arg@420 194 return True;
arg@420 195 return False;
arg@420 196 }
arg@420 197
arg@415 198 void
arg@461 199 resizecol(Arg *arg) {
arg@423 200 unsigned int n;
arg@423 201 Client *c;
arg@418 202
arg@430 203 for(n = 0, c = clients; c; c = c->next)
arg@430 204 if(isvisible(c) && !c->isfloat)
arg@423 205 n++;
arg@486 206 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
arg@415 207 return;
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@533 218 arrange();
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@533 255 arrange();
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@533 269 arrange();
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@533 280 arrange();
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@533 290 arrange();
arg@395 291 }
arg@395 292
arg@395 293 void
arg@461 294 zoom(Arg *arg) {
arg@423 295 unsigned int n;
arg@423 296 Client *c;
arg@473 297
arg@473 298 if(!sel)
arg@473 299 return;
arg@473 300 if(sel->isfloat || (arrange == dofloat)) {
arg@480 301 togglemax(sel);
arg@473 302 return;
arg@473 303 }
arg@430 304 for(n = 0, c = clients; c; c = c->next)
arg@430 305 if(isvisible(c) && !c->isfloat)
arg@423 306 n++;
arg@486 307 if(n < 2 || (arrange == dofloat))
arg@327 308 return;
arg@430 309 if((c = sel) == nexttiled(clients))
arg@433 310 if(!(c = nexttiled(c->next)))
arg@429 311 return;
arg@443 312 detach(c);
arg@443 313 if(clients)
arg@443 314 clients->prev = c;
arg@443 315 c->next = clients;
arg@443 316 clients = c;
arg@378 317 focus(c);
arg@533 318 arrange();
arg@327 319 }