dwm-meillo

annotate view.c @ 562:def7247888d4

next release will be 2.2
author arg@mig29
date Fri, 03 Nov 2006 09:22:40 +0100
parents a2c465098a3b
children fe766305eed1
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@559 198 resizemaster(Arg *arg) {
arg@561 199 if(arg->i == 0)
arg@561 200 master = MASTER;
arg@561 201 else {
arg@561 202 if(master + arg->i > 950 || master + arg->i < 50)
arg@561 203 return;
arg@561 204 master += arg->i;
arg@561 205 }
arg@533 206 arrange();
arg@415 207 }
arg@415 208
arg@327 209 void
arg@487 210 restack(void) {
arg@327 211 Client *c;
arg@327 212 XEvent ev;
arg@481 213
arg@437 214 if(!sel) {
arg@437 215 drawstatus();
arg@436 216 return;
arg@437 217 }
arg@436 218 if(sel->isfloat || arrange == dofloat) {
arg@436 219 XRaiseWindow(dpy, sel->win);
arg@436 220 XRaiseWindow(dpy, sel->twin);
arg@436 221 }
arg@512 222 if(arrange != dofloat) {
arg@512 223 if(!sel->isfloat) {
arg@512 224 XLowerWindow(dpy, sel->twin);
arg@512 225 XLowerWindow(dpy, sel->win);
arg@512 226 }
arg@436 227 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 228 if(c == sel)
arg@512 229 continue;
arg@436 230 XLowerWindow(dpy, c->twin);
arg@436 231 XLowerWindow(dpy, c->win);
arg@327 232 }
arg@512 233 }
arg@327 234 drawall();
arg@327 235 XSync(dpy, False);
arg@327 236 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 237 }
arg@327 238
arg@327 239 void
arg@461 240 togglemode(Arg *arg) {
arg@333 241 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 242 if(sel)
arg@533 243 arrange();
arg@327 244 else
arg@327 245 drawstatus();
arg@327 246 }
arg@327 247
arg@327 248 void
arg@461 249 toggleview(Arg *arg) {
arg@327 250 unsigned int i;
arg@327 251
arg@327 252 seltag[arg->i] = !seltag[arg->i];
arg@327 253 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 254 if(i == ntags)
arg@327 255 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 256 reorder();
arg@533 257 arrange();
arg@327 258 }
arg@327 259
arg@327 260 void
arg@461 261 view(Arg *arg) {
arg@327 262 unsigned int i;
arg@327 263
arg@327 264 for(i = 0; i < ntags; i++)
arg@327 265 seltag[i] = False;
arg@327 266 seltag[arg->i] = True;
arg@381 267 reorder();
arg@533 268 arrange();
arg@327 269 }
arg@327 270
arg@327 271 void
arg@461 272 viewall(Arg *arg) {
arg@395 273 unsigned int i;
arg@395 274
arg@395 275 for(i = 0; i < ntags; i++)
arg@395 276 seltag[i] = True;
arg@397 277 reorder();
arg@533 278 arrange();
arg@395 279 }
arg@395 280
arg@395 281 void
arg@461 282 zoom(Arg *arg) {
arg@423 283 unsigned int n;
arg@423 284 Client *c;
arg@473 285
arg@473 286 if(!sel)
arg@473 287 return;
arg@473 288 if(sel->isfloat || (arrange == dofloat)) {
arg@480 289 togglemax(sel);
arg@473 290 return;
arg@473 291 }
arg@430 292 for(n = 0, c = clients; c; c = c->next)
arg@430 293 if(isvisible(c) && !c->isfloat)
arg@423 294 n++;
arg@486 295 if(n < 2 || (arrange == dofloat))
arg@327 296 return;
arg@430 297 if((c = sel) == nexttiled(clients))
arg@433 298 if(!(c = nexttiled(c->next)))
arg@429 299 return;
arg@443 300 detach(c);
arg@443 301 if(clients)
arg@443 302 clients->prev = c;
arg@443 303 c->next = clients;
arg@443 304 clients = c;
arg@378 305 focus(c);
arg@533 306 arrange();
arg@327 307 }