dwm-meillo

annotate view.c @ 540:14e95221268b

changing MASTER in config.arg.h from 600 to 550 per thousand
author arg@mig29
date Thu, 26 Oct 2006 11:21:45 +0200
parents a5567a0d3011
children 3d23384eb5ab
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@532 47
arg@480 48 if((c->ismax = !c->ismax)) {
arg@480 49 c->rx = c->x; c->x = sx;
arg@480 50 c->ry = c->y; c->y = bh;
arg@502 51 c->rw = c->w; c->w = sw - 2 * BORDERPX;
arg@502 52 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
arg@480 53 }
arg@480 54 else {
arg@480 55 c->x = c->rx;
arg@480 56 c->y = c->ry;
arg@481 57 c->w = c->rw;
arg@481 58 c->h = c->rh;
arg@480 59 }
arg@480 60 resize(c, True, TopLeft);
arg@480 61 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 62 }
arg@430 63
arg@327 64 /* extern */
arg@327 65
arg@533 66 void (*arrange)(void) = DEFMODE;
arg@327 67
arg@327 68 void
arg@461 69 detach(Client *c) {
arg@378 70 if(c->prev)
arg@378 71 c->prev->next = c->next;
arg@378 72 if(c->next)
arg@378 73 c->next->prev = c->prev;
arg@378 74 if(c == clients)
arg@378 75 clients = c->next;
arg@378 76 c->next = c->prev = NULL;
arg@378 77 }
arg@378 78
arg@378 79 void
arg@533 80 dofloat(void) {
arg@402 81 Client *c;
arg@400 82
arg@327 83 for(c = clients; c; c = c->next) {
arg@327 84 if(isvisible(c)) {
arg@327 85 resize(c, True, TopLeft);
arg@327 86 }
arg@327 87 else
arg@327 88 ban(c);
arg@327 89 }
arg@446 90 if(!sel || !isvisible(sel)) {
arg@450 91 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 92 focus(c);
arg@446 93 }
arg@327 94 restack();
arg@327 95 }
arg@327 96
arg@327 97 void
arg@533 98 dotile(void) {
arg@531 99 unsigned int i, n, mpx, stackw, stackh, th;
arg@402 100 Client *c;
arg@400 101
arg@488 102 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 103 n++;
arg@531 104 mpx = (sw * master) / 1000;
arg@531 105 stackw = sw - mpx;
arg@530 106 stackh = sh - bh;
arg@530 107 th = stackh;
arg@511 108 if(n > 1)
arg@530 109 th /= (n - 1);
arg@327 110
arg@535 111 for(i = 0, c = clients; c; c = c->next)
arg@327 112 if(isvisible(c)) {
arg@327 113 if(c->isfloat) {
arg@327 114 resize(c, True, TopLeft);
arg@327 115 continue;
arg@327 116 }
arg@488 117 c->ismax = False;
arg@523 118 c->x = sx;
arg@523 119 c->y = sy + bh;
arg@507 120 if(n == 1) { /* only 1 window */
arg@502 121 c->w = sw - 2 * BORDERPX;
arg@502 122 c->h = sh - 2 * BORDERPX - bh;
arg@327 123 }
arg@507 124 else if(i == 0) { /* master window */
arg@531 125 c->w = mpx - 2 * BORDERPX;
arg@530 126 c->h = sh - bh - 2 * BORDERPX;
arg@507 127 }
arg@523 128 else { /* tile window */
arg@531 129 c->x += mpx;
arg@531 130 c->w = stackw - 2 * BORDERPX;
arg@523 131 if(th > bh) {
arg@530 132 c->y = sy + (i - 1) * th + bh;
arg@530 133 if(i + 1 == n)
arg@530 134 c->h = sh - c->y - 2 * BORDERPX;
arg@531 135 else
arg@531 136 c->h = th - 2 * BORDERPX;
arg@507 137 }
arg@531 138 else /* fallback if th < bh */
arg@523 139 c->h = stackh - 2 * BORDERPX;
arg@327 140 }
arg@327 141 resize(c, False, TopLeft);
arg@535 142 i++;
arg@327 143 }
arg@327 144 else
arg@327 145 ban(c);
arg@532 146
arg@446 147 if(!sel || !isvisible(sel)) {
arg@450 148 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 149 focus(c);
arg@446 150 }
arg@327 151 restack();
arg@327 152 }
arg@327 153
arg@327 154 void
arg@461 155 focusnext(Arg *arg) {
arg@327 156 Client *c;
arg@327 157
arg@327 158 if(!sel)
arg@327 159 return;
arg@327 160 if(!(c = getnext(sel->next)))
arg@327 161 c = getnext(clients);
arg@327 162 if(c) {
arg@327 163 focus(c);
arg@327 164 restack();
arg@327 165 }
arg@327 166 }
arg@327 167
arg@327 168 void
arg@461 169 focusprev(Arg *arg) {
arg@327 170 Client *c;
arg@327 171
arg@327 172 if(!sel)
arg@327 173 return;
arg@327 174 if(!(c = getprev(sel->prev))) {
arg@327 175 for(c = clients; c && c->next; c = c->next);
arg@327 176 c = getprev(c);
arg@327 177 }
arg@327 178 if(c) {
arg@327 179 focus(c);
arg@327 180 restack();
arg@327 181 }
arg@327 182 }
arg@327 183
arg@420 184 Bool
arg@461 185 isvisible(Client *c) {
arg@420 186 unsigned int i;
arg@420 187
arg@420 188 for(i = 0; i < ntags; i++)
arg@420 189 if(c->tags[i] && seltag[i])
arg@420 190 return True;
arg@420 191 return False;
arg@420 192 }
arg@420 193
arg@415 194 void
arg@461 195 resizecol(Arg *arg) {
arg@423 196 unsigned int n;
arg@423 197 Client *c;
arg@418 198
arg@430 199 for(n = 0, c = clients; c; c = c->next)
arg@430 200 if(isvisible(c) && !c->isfloat)
arg@423 201 n++;
arg@486 202 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
arg@415 203 return;
arg@415 204 if(sel == getnext(clients)) {
arg@529 205 if(master + arg->i > 950 || master + arg->i < 50)
arg@415 206 return;
arg@505 207 master += arg->i;
arg@415 208 }
arg@415 209 else {
arg@529 210 if(master - arg->i > 950 || master - arg->i < 50)
arg@415 211 return;
arg@505 212 master -= arg->i;
arg@415 213 }
arg@533 214 arrange();
arg@415 215 }
arg@415 216
arg@327 217 void
arg@487 218 restack(void) {
arg@327 219 Client *c;
arg@327 220 XEvent ev;
arg@481 221
arg@437 222 if(!sel) {
arg@437 223 drawstatus();
arg@436 224 return;
arg@437 225 }
arg@436 226 if(sel->isfloat || arrange == dofloat) {
arg@436 227 XRaiseWindow(dpy, sel->win);
arg@436 228 XRaiseWindow(dpy, sel->twin);
arg@436 229 }
arg@512 230 if(arrange != dofloat) {
arg@512 231 if(!sel->isfloat) {
arg@512 232 XLowerWindow(dpy, sel->twin);
arg@512 233 XLowerWindow(dpy, sel->win);
arg@512 234 }
arg@436 235 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 236 if(c == sel)
arg@512 237 continue;
arg@436 238 XLowerWindow(dpy, c->twin);
arg@436 239 XLowerWindow(dpy, c->win);
arg@327 240 }
arg@512 241 }
arg@327 242 drawall();
arg@327 243 XSync(dpy, False);
arg@327 244 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 245 }
arg@327 246
arg@327 247 void
arg@461 248 togglemode(Arg *arg) {
arg@333 249 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 250 if(sel)
arg@533 251 arrange();
arg@327 252 else
arg@327 253 drawstatus();
arg@327 254 }
arg@327 255
arg@327 256 void
arg@461 257 toggleview(Arg *arg) {
arg@327 258 unsigned int i;
arg@327 259
arg@327 260 seltag[arg->i] = !seltag[arg->i];
arg@327 261 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 262 if(i == ntags)
arg@327 263 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 264 reorder();
arg@533 265 arrange();
arg@327 266 }
arg@327 267
arg@327 268 void
arg@461 269 view(Arg *arg) {
arg@327 270 unsigned int i;
arg@327 271
arg@327 272 for(i = 0; i < ntags; i++)
arg@327 273 seltag[i] = False;
arg@327 274 seltag[arg->i] = True;
arg@381 275 reorder();
arg@533 276 arrange();
arg@327 277 }
arg@327 278
arg@327 279 void
arg@461 280 viewall(Arg *arg) {
arg@395 281 unsigned int i;
arg@395 282
arg@395 283 for(i = 0; i < ntags; i++)
arg@395 284 seltag[i] = True;
arg@397 285 reorder();
arg@533 286 arrange();
arg@395 287 }
arg@395 288
arg@395 289 void
arg@461 290 zoom(Arg *arg) {
arg@423 291 unsigned int n;
arg@423 292 Client *c;
arg@473 293
arg@473 294 if(!sel)
arg@473 295 return;
arg@473 296 if(sel->isfloat || (arrange == dofloat)) {
arg@480 297 togglemax(sel);
arg@473 298 return;
arg@473 299 }
arg@430 300 for(n = 0, c = clients; c; c = c->next)
arg@430 301 if(isvisible(c) && !c->isfloat)
arg@423 302 n++;
arg@486 303 if(n < 2 || (arrange == dofloat))
arg@327 304 return;
arg@430 305 if((c = sel) == nexttiled(clients))
arg@433 306 if(!(c = nexttiled(c->next)))
arg@429 307 return;
arg@443 308 detach(c);
arg@443 309 if(clients)
arg@443 310 clients->prev = c;
arg@443 311 c->next = clients;
arg@443 312 clients = c;
arg@378 313 focus(c);
arg@533 314 arrange();
arg@327 315 }