aewl

annotate view.c @ 630:264f02dd2ad0

removed gravitate for the moment
author arg@mig29
date Mon, 11 Dec 2006 16:45:02 +0100
parents f7dcd3ac8d6f
children 276238ad9516
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@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@565 72 unsigned int i, n, mpx, stackw, 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@565 77 mpx = (waw * master) / 1000;
arg@565 78 stackw = waw - mpx;
arg@327 79
arg@535 80 for(i = 0, c = clients; c; c = c->next)
arg@327 81 if(isvisible(c)) {
arg@327 82 if(c->isfloat) {
arg@327 83 resize(c, True, TopLeft);
arg@327 84 continue;
arg@327 85 }
arg@488 86 c->ismax = False;
arg@565 87 c->x = wax;
arg@565 88 c->y = way;
arg@507 89 if(n == 1) { /* only 1 window */
arg@565 90 c->w = waw - 2 * BORDERPX;
arg@565 91 c->h = wah - 2 * BORDERPX;
arg@327 92 }
arg@507 93 else if(i == 0) { /* master window */
arg@587 94 c->w = mpx - 2 * BORDERPX;
arg@565 95 c->h = wah - 2 * BORDERPX;
arg@565 96 th = wah / (n - 1);
arg@507 97 }
arg@523 98 else { /* tile window */
arg@531 99 c->x += mpx;
arg@531 100 c->w = stackw - 2 * BORDERPX;
arg@523 101 if(th > bh) {
arg@588 102 c->y += (i - 1) * th;
arg@565 103 c->h = th - 2 * BORDERPX;
arg@507 104 }
arg@531 105 else /* fallback if th < bh */
arg@565 106 c->h = wah - 2 * BORDERPX;
arg@327 107 }
arg@327 108 resize(c, False, TopLeft);
arg@535 109 i++;
arg@327 110 }
arg@327 111 else
arg@327 112 ban(c);
arg@532 113
arg@446 114 if(!sel || !isvisible(sel)) {
arg@450 115 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 116 focus(c);
arg@446 117 }
arg@327 118 restack();
arg@327 119 }
arg@327 120
arg@327 121 void
arg@461 122 focusnext(Arg *arg) {
arg@327 123 Client *c;
arg@327 124
arg@327 125 if(!sel)
arg@327 126 return;
arg@327 127 if(!(c = getnext(sel->next)))
arg@327 128 c = getnext(clients);
arg@327 129 if(c) {
arg@327 130 focus(c);
arg@327 131 restack();
arg@327 132 }
arg@327 133 }
arg@327 134
arg@327 135 void
arg@461 136 focusprev(Arg *arg) {
arg@327 137 Client *c;
arg@327 138
arg@327 139 if(!sel)
arg@327 140 return;
arg@327 141 if(!(c = getprev(sel->prev))) {
arg@327 142 for(c = clients; c && c->next; c = c->next);
arg@327 143 c = getprev(c);
arg@327 144 }
arg@327 145 if(c) {
arg@327 146 focus(c);
arg@327 147 restack();
arg@327 148 }
arg@327 149 }
arg@327 150
arg@420 151 Bool
arg@461 152 isvisible(Client *c) {
arg@420 153 unsigned int i;
arg@420 154
arg@420 155 for(i = 0; i < ntags; i++)
arg@420 156 if(c->tags[i] && seltag[i])
arg@420 157 return True;
arg@420 158 return False;
arg@420 159 }
arg@420 160
arg@415 161 void
arg@559 162 resizemaster(Arg *arg) {
arg@561 163 if(arg->i == 0)
arg@561 164 master = MASTER;
arg@561 165 else {
arg@561 166 if(master + arg->i > 950 || master + arg->i < 50)
arg@561 167 return;
arg@561 168 master += arg->i;
arg@561 169 }
arg@533 170 arrange();
arg@415 171 }
arg@415 172
arg@327 173 void
arg@487 174 restack(void) {
arg@327 175 Client *c;
arg@327 176 XEvent ev;
arg@481 177
arg@437 178 if(!sel) {
arg@437 179 drawstatus();
arg@436 180 return;
arg@437 181 }
arg@436 182 if(sel->isfloat || arrange == dofloat) {
arg@436 183 XRaiseWindow(dpy, sel->win);
arg@436 184 XRaiseWindow(dpy, sel->twin);
arg@436 185 }
arg@512 186 if(arrange != dofloat) {
arg@512 187 if(!sel->isfloat) {
arg@512 188 XLowerWindow(dpy, sel->twin);
arg@512 189 XLowerWindow(dpy, sel->win);
arg@512 190 }
arg@436 191 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 192 if(c == sel)
arg@512 193 continue;
arg@436 194 XLowerWindow(dpy, c->twin);
arg@436 195 XLowerWindow(dpy, c->win);
arg@327 196 }
arg@512 197 }
arg@327 198 drawall();
arg@327 199 XSync(dpy, False);
arg@327 200 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 201 }
arg@327 202
arg@327 203 void
arg@584 204 togglefloat(Arg *arg) {
arg@591 205 if (!sel || arrange == dofloat)
arg@584 206 return;
arg@584 207 sel->isfloat = !sel->isfloat;
arg@584 208 arrange();
arg@584 209 }
arg@584 210
arg@584 211 void
arg@461 212 togglemode(Arg *arg) {
arg@333 213 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 214 if(sel)
arg@533 215 arrange();
arg@327 216 else
arg@327 217 drawstatus();
arg@327 218 }
arg@327 219
arg@327 220 void
arg@461 221 toggleview(Arg *arg) {
arg@327 222 unsigned int i;
arg@327 223
arg@327 224 seltag[arg->i] = !seltag[arg->i];
arg@327 225 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 226 if(i == ntags)
arg@327 227 seltag[arg->i] = True; /* cannot toggle last view */
arg@533 228 arrange();
arg@327 229 }
arg@327 230
arg@327 231 void
arg@461 232 view(Arg *arg) {
arg@327 233 unsigned int i;
arg@327 234
arg@327 235 for(i = 0; i < ntags; i++)
arg@594 236 seltag[i] = (arg->i == -1) ? True : False;
arg@611 237 if(arg->i >= 0 && arg->i < ntags)
arg@611 238 seltag[arg->i] = True;
arg@533 239 arrange();
arg@327 240 }
arg@327 241
arg@327 242 void
arg@461 243 zoom(Arg *arg) {
arg@423 244 unsigned int n;
arg@423 245 Client *c;
arg@473 246
arg@473 247 if(!sel)
arg@473 248 return;
arg@473 249 if(sel->isfloat || (arrange == dofloat)) {
arg@480 250 togglemax(sel);
arg@473 251 return;
arg@473 252 }
arg@430 253 for(n = 0, c = clients; c; c = c->next)
arg@430 254 if(isvisible(c) && !c->isfloat)
arg@423 255 n++;
arg@486 256 if(n < 2 || (arrange == dofloat))
arg@327 257 return;
arg@430 258 if((c = sel) == nexttiled(clients))
arg@433 259 if(!(c = nexttiled(c->next)))
arg@429 260 return;
arg@443 261 detach(c);
arg@443 262 if(clients)
arg@443 263 clients->prev = c;
arg@443 264 c->next = clients;
arg@443 265 clients = c;
arg@378 266 focus(c);
arg@533 267 arrange();
arg@327 268 }