dwm-meillo

annotate view.c @ 667:70f19af50393

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