aewl

annotate view.c @ 654:04734db9a219

allowing zoom within master area as well
author Anselm R. Garbe <arg@suckless.org>
date Fri, 05 Jan 2007 15:08:25 +0100
parents b9f4efd21473
children c30805f6bb08
rev   line source
arg@644 1 /* (C)opyright MMVI-MMVII 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@480 9 nexttiled(Client *c) {
arg@480 10 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
arg@480 11 return c;
arg@480 12 }
arg@480 13
arg@651 14 static Bool
arg@651 15 ismaster(Client *c) {
arg@651 16 Client *cl;
arg@651 17 unsigned int i;
arg@651 18
arg@651 19 for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
arg@651 20 return i < nmaster;
arg@651 21 }
arg@651 22
arg@651 23 static void
arg@651 24 pop(Client *c) {
arg@651 25 detach(c);
arg@651 26 if(clients)
arg@651 27 clients->prev = c;
arg@651 28 c->next = clients;
arg@651 29 clients = c;
arg@651 30 }
arg@651 31
arg@651 32 static void
arg@651 33 swap(Client *c1, Client *c2) {
arg@651 34 Client tmp = *c1;
arg@651 35 Client *cp = c1->prev;
arg@651 36 Client *cn = c1->next;
arg@651 37
arg@651 38 *c1 = *c2;
arg@651 39 c1->prev = cp;
arg@651 40 c1->next = cn;
arg@651 41 cp = c2->prev;
arg@651 42 cn = c2->next;
arg@651 43 *c2 = tmp;
arg@651 44 c2->prev = cp;
arg@651 45 c2->next = cn;
arg@651 46 }
arg@651 47
arg@442 48 static void
arg@532 49 togglemax(Client *c) {
arg@481 50 XEvent ev;
arg@548 51
arg@549 52 if(c->isfixed)
arg@548 53 return;
arg@532 54
arg@480 55 if((c->ismax = !c->ismax)) {
arg@565 56 c->rx = c->x; c->x = wax;
arg@565 57 c->ry = c->y; c->y = way;
arg@565 58 c->rw = c->w; c->w = waw - 2 * BORDERPX;
arg@565 59 c->rh = c->h; c->h = wah - 2 * BORDERPX;
arg@480 60 }
arg@480 61 else {
arg@480 62 c->x = c->rx;
arg@480 63 c->y = c->ry;
arg@481 64 c->w = c->rw;
arg@481 65 c->h = c->rh;
arg@480 66 }
arg@480 67 resize(c, True, TopLeft);
arg@480 68 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 69 }
arg@430 70
arg@651 71 static Client *
arg@651 72 topofstack() {
arg@651 73 Client *c;
arg@651 74 unsigned int i;
arg@651 75
arg@651 76 for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
arg@651 77 return (i < nmaster) ? NULL : c;
arg@651 78 }
arg@651 79
arg@327 80 /* extern */
arg@327 81
arg@533 82 void (*arrange)(void) = DEFMODE;
arg@327 83
arg@327 84 void
arg@461 85 detach(Client *c) {
arg@378 86 if(c->prev)
arg@378 87 c->prev->next = c->next;
arg@378 88 if(c->next)
arg@378 89 c->next->prev = c->prev;
arg@378 90 if(c == clients)
arg@378 91 clients = c->next;
arg@378 92 c->next = c->prev = NULL;
arg@378 93 }
arg@378 94
arg@378 95 void
arg@533 96 dofloat(void) {
arg@402 97 Client *c;
arg@400 98
arg@327 99 for(c = clients; c; c = c->next) {
arg@327 100 if(isvisible(c)) {
arg@327 101 resize(c, True, TopLeft);
arg@327 102 }
arg@327 103 else
arg@327 104 ban(c);
arg@327 105 }
arg@446 106 if(!sel || !isvisible(sel)) {
arg@450 107 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 108 focus(c);
arg@446 109 }
arg@327 110 restack();
arg@327 111 }
arg@327 112
arg@327 113 void
arg@533 114 dotile(void) {
arg@650 115 unsigned int i, n, mw, mh, tw, th;
arg@402 116 Client *c;
arg@400 117
arg@488 118 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 119 n++;
arg@650 120 /* window geoms */
arg@650 121 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
arg@650 122 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
arg@650 123 tw = waw - mw;
arg@650 124 th = (n > nmaster) ? wah / (n - nmaster) : 0;
arg@327 125
arg@535 126 for(i = 0, c = clients; c; c = c->next)
arg@327 127 if(isvisible(c)) {
arg@327 128 if(c->isfloat) {
arg@327 129 resize(c, True, TopLeft);
arg@327 130 continue;
arg@327 131 }
arg@488 132 c->ismax = False;
arg@565 133 c->x = wax;
arg@565 134 c->y = way;
arg@650 135 if(i < nmaster) {
arg@650 136 c->y += i * mh;
arg@650 137 c->w = mw - 2 * BORDERPX;
arg@650 138 c->h = mh - 2 * BORDERPX;
arg@507 139 }
arg@523 140 else { /* tile window */
arg@650 141 c->x += mw;
arg@650 142 c->w = tw - 2 * BORDERPX;
arg@523 143 if(th > bh) {
arg@650 144 c->y += (i - nmaster) * th;
arg@565 145 c->h = th - 2 * BORDERPX;
arg@507 146 }
arg@531 147 else /* fallback if th < bh */
arg@565 148 c->h = wah - 2 * BORDERPX;
arg@327 149 }
arg@327 150 resize(c, False, TopLeft);
arg@535 151 i++;
arg@327 152 }
arg@327 153 else
arg@327 154 ban(c);
arg@532 155
arg@446 156 if(!sel || !isvisible(sel)) {
arg@450 157 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 158 focus(c);
arg@446 159 }
arg@327 160 restack();
arg@327 161 }
arg@327 162
arg@327 163 void
arg@461 164 focusnext(Arg *arg) {
arg@327 165 Client *c;
arg@327 166
arg@327 167 if(!sel)
arg@327 168 return;
arg@327 169 if(!(c = getnext(sel->next)))
arg@327 170 c = getnext(clients);
arg@327 171 if(c) {
arg@327 172 focus(c);
arg@327 173 restack();
arg@327 174 }
arg@327 175 }
arg@327 176
arg@327 177 void
arg@461 178 focusprev(Arg *arg) {
arg@327 179 Client *c;
arg@327 180
arg@327 181 if(!sel)
arg@327 182 return;
arg@327 183 if(!(c = getprev(sel->prev))) {
arg@327 184 for(c = clients; c && c->next; c = c->next);
arg@327 185 c = getprev(c);
arg@327 186 }
arg@327 187 if(c) {
arg@327 188 focus(c);
arg@327 189 restack();
arg@327 190 }
arg@327 191 }
arg@327 192
arg@650 193 void
arg@650 194 incnmaster(Arg *arg) {
arg@650 195 if(nmaster + arg->i < 1)
arg@650 196 return;
arg@650 197 nmaster += arg->i;
arg@650 198 arrange();
arg@650 199 }
arg@650 200
arg@420 201 Bool
arg@461 202 isvisible(Client *c) {
arg@420 203 unsigned int i;
arg@420 204
arg@420 205 for(i = 0; i < ntags; i++)
arg@420 206 if(c->tags[i] && seltag[i])
arg@420 207 return True;
arg@420 208 return False;
arg@420 209 }
arg@420 210
arg@415 211 void
arg@559 212 resizemaster(Arg *arg) {
arg@561 213 if(arg->i == 0)
arg@561 214 master = MASTER;
arg@561 215 else {
arg@561 216 if(master + arg->i > 950 || master + arg->i < 50)
arg@561 217 return;
arg@561 218 master += arg->i;
arg@561 219 }
arg@533 220 arrange();
arg@415 221 }
arg@415 222
arg@327 223 void
arg@487 224 restack(void) {
arg@327 225 Client *c;
arg@327 226 XEvent ev;
arg@481 227
arg@437 228 if(!sel) {
arg@437 229 drawstatus();
arg@436 230 return;
arg@437 231 }
arg@436 232 if(sel->isfloat || arrange == dofloat) {
arg@436 233 XRaiseWindow(dpy, sel->win);
arg@436 234 XRaiseWindow(dpy, sel->twin);
arg@436 235 }
arg@512 236 if(arrange != dofloat) {
arg@512 237 if(!sel->isfloat) {
arg@512 238 XLowerWindow(dpy, sel->twin);
arg@512 239 XLowerWindow(dpy, sel->win);
arg@512 240 }
arg@436 241 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 242 if(c == sel)
arg@512 243 continue;
arg@436 244 XLowerWindow(dpy, c->twin);
arg@436 245 XLowerWindow(dpy, c->win);
arg@327 246 }
arg@512 247 }
arg@327 248 drawall();
arg@327 249 XSync(dpy, False);
arg@327 250 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 251 }
arg@327 252
arg@327 253 void
arg@584 254 togglefloat(Arg *arg) {
arg@591 255 if (!sel || arrange == dofloat)
arg@584 256 return;
arg@584 257 sel->isfloat = !sel->isfloat;
arg@584 258 arrange();
arg@584 259 }
arg@584 260
arg@584 261 void
arg@461 262 togglemode(Arg *arg) {
arg@333 263 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 264 if(sel)
arg@533 265 arrange();
arg@327 266 else
arg@327 267 drawstatus();
arg@327 268 }
arg@327 269
arg@327 270 void
arg@461 271 toggleview(Arg *arg) {
arg@327 272 unsigned int i;
arg@327 273
arg@327 274 seltag[arg->i] = !seltag[arg->i];
arg@327 275 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 276 if(i == ntags)
arg@327 277 seltag[arg->i] = True; /* cannot toggle last view */
arg@533 278 arrange();
arg@327 279 }
arg@327 280
arg@327 281 void
arg@461 282 view(Arg *arg) {
arg@327 283 unsigned int i;
arg@327 284
arg@327 285 for(i = 0; i < ntags; i++)
arg@594 286 seltag[i] = (arg->i == -1) ? True : False;
arg@611 287 if(arg->i >= 0 && arg->i < ntags)
arg@611 288 seltag[arg->i] = True;
arg@533 289 arrange();
arg@327 290 }
arg@327 291
arg@327 292 void
arg@461 293 zoom(Arg *arg) {
arg@651 294 unsigned int n;
arg@423 295 Client *c;
arg@473 296
arg@473 297 if(!sel)
arg@473 298 return;
arg@473 299 if(sel->isfloat || (arrange == dofloat)) {
arg@480 300 togglemax(sel);
arg@473 301 return;
arg@473 302 }
arg@650 303 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@650 304 n++;
arg@654 305
arg@654 306 c = sel;
arg@650 307 if(n <= nmaster || (arrange == dofloat))
arg@654 308 pop(c);
arg@654 309 else if(ismaster(sel)) {
arg@651 310 if(!(c = topofstack()))
arg@651 311 return;
arg@651 312 swap(c, sel);
arg@651 313 c = sel;
arg@651 314 }
arg@651 315 else
arg@651 316 pop(c);
arg@650 317
arg@378 318 focus(c);
arg@533 319 arrange();
arg@327 320 }