dwm-meillo

annotate view.c @ 750:3d957a703ce2

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