dwm-meillo

annotate view.c @ 741:7c5d5b1e49c9

fixed copyright notice in Makefile
author Anselm R. Garbe <arg@suckless.org>
date Thu, 08 Feb 2007 14:09:52 +0100
parents d3876aa79292
children 6692d7e7e156
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
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@721 152 if((arrange == dofloat) || (nmaster + arg->i < 1)
arg@726 153 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
arg@650 154 return;
arg@650 155 nmaster += arg->i;
arg@674 156 if(sel)
arg@674 157 arrange();
arg@674 158 else
arg@674 159 drawstatus();
arg@650 160 }
arg@650 161
arg@420 162 Bool
arg@461 163 isvisible(Client *c) {
arg@420 164 unsigned int i;
arg@420 165
arg@420 166 for(i = 0; i < ntags; i++)
arg@420 167 if(c->tags[i] && seltag[i])
arg@420 168 return True;
arg@420 169 return False;
arg@420 170 }
arg@420 171
arg@415 172 void
arg@559 173 resizemaster(Arg *arg) {
arg@561 174 if(arg->i == 0)
arg@561 175 master = MASTER;
arg@561 176 else {
arg@726 177 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
arg@726 178 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
arg@561 179 return;
arg@561 180 master += arg->i;
arg@561 181 }
arg@533 182 arrange();
arg@415 183 }
arg@415 184
arg@327 185 void
arg@487 186 restack(void) {
arg@327 187 Client *c;
arg@327 188 XEvent ev;
arg@481 189
arg@691 190 drawstatus();
arg@691 191 if(!sel)
arg@436 192 return;
arg@687 193 if(sel->isfloat || arrange == dofloat)
arg@436 194 XRaiseWindow(dpy, sel->win);
arg@512 195 if(arrange != dofloat) {
arg@687 196 if(!sel->isfloat)
arg@512 197 XLowerWindow(dpy, sel->win);
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->win);
arg@327 202 }
arg@512 203 }
arg@327 204 XSync(dpy, False);
arg@327 205 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 206 }
arg@327 207
arg@327 208 void
arg@584 209 togglefloat(Arg *arg) {
arg@591 210 if (!sel || arrange == dofloat)
arg@584 211 return;
arg@584 212 sel->isfloat = !sel->isfloat;
arg@584 213 arrange();
arg@584 214 }
arg@584 215
arg@584 216 void
arg@461 217 togglemode(Arg *arg) {
arg@333 218 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 219 if(sel)
arg@533 220 arrange();
arg@327 221 else
arg@327 222 drawstatus();
arg@327 223 }
arg@327 224
arg@327 225 void
arg@461 226 toggleview(Arg *arg) {
arg@327 227 unsigned int i;
arg@327 228
arg@327 229 seltag[arg->i] = !seltag[arg->i];
arg@327 230 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 231 if(i == ntags)
arg@327 232 seltag[arg->i] = True; /* cannot toggle last view */
arg@533 233 arrange();
arg@327 234 }
arg@327 235
arg@327 236 void
arg@461 237 view(Arg *arg) {
arg@327 238 unsigned int i;
arg@327 239
arg@327 240 for(i = 0; i < ntags; i++)
arg@594 241 seltag[i] = (arg->i == -1) ? True : False;
arg@611 242 if(arg->i >= 0 && arg->i < ntags)
arg@611 243 seltag[arg->i] = True;
arg@533 244 arrange();
arg@327 245 }
arg@327 246
arg@327 247 void
arg@461 248 zoom(Arg *arg) {
arg@651 249 unsigned int n;
arg@423 250 Client *c;
arg@473 251
arg@473 252 if(!sel)
arg@473 253 return;
arg@473 254 if(sel->isfloat || (arrange == dofloat)) {
arg@480 255 togglemax(sel);
arg@473 256 return;
arg@473 257 }
arg@650 258 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@650 259 n++;
arg@654 260
arg@662 261 if((c = sel) == nexttiled(clients))
arg@662 262 if(!(c = nexttiled(c->next)))
arg@662 263 return;
arg@662 264 detach(c);
arg@662 265 if(clients)
arg@662 266 clients->prev = c;
arg@662 267 c->next = clients;
arg@662 268 clients = c;
arg@662 269 focus(c);
arg@662 270 arrange();
arg@327 271 }