dwm-meillo

annotate view.c @ 554:1734939bceba

fixed stupid bug of snap-to-screen
author arg@mig29
date Mon, 30 Oct 2006 12:26:55 +0100
parents 3d23384eb5ab
children e249e2952a32
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@487 9 minclient(void) {
arg@382 10 Client *c, *min;
arg@382 11
arg@443 12 if((clients && clients->isfloat) || arrange == dofloat)
arg@443 13 return clients; /* don't touch floating order */
arg@382 14 for(min = c = clients; c; c = c->next)
arg@382 15 if(c->weight < min->weight)
arg@382 16 min = c;
arg@382 17 return min;
arg@382 18 }
arg@382 19
arg@480 20 static Client *
arg@480 21 nexttiled(Client *c) {
arg@480 22 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
arg@480 23 return c;
arg@480 24 }
arg@480 25
arg@442 26 static void
arg@487 27 reorder(void) {
arg@382 28 Client *c, *newclients, *tail;
arg@380 29
arg@382 30 newclients = tail = NULL;
arg@382 31 while((c = minclient())) {
arg@381 32 detach(c);
arg@382 33 if(tail) {
arg@382 34 c->prev = tail;
arg@382 35 tail->next = c;
arg@382 36 tail = c;
arg@381 37 }
arg@381 38 else
arg@382 39 tail = newclients = c;
arg@380 40 }
arg@382 41 clients = newclients;
arg@380 42 }
arg@380 43
arg@480 44 static void
arg@532 45 togglemax(Client *c) {
arg@481 46 XEvent ev;
arg@548 47
arg@549 48 if(c->isfixed)
arg@548 49 return;
arg@532 50
arg@480 51 if((c->ismax = !c->ismax)) {
arg@480 52 c->rx = c->x; c->x = sx;
arg@480 53 c->ry = c->y; c->y = bh;
arg@502 54 c->rw = c->w; c->w = sw - 2 * BORDERPX;
arg@502 55 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
arg@480 56 }
arg@480 57 else {
arg@480 58 c->x = c->rx;
arg@480 59 c->y = c->ry;
arg@481 60 c->w = c->rw;
arg@481 61 c->h = c->rh;
arg@480 62 }
arg@480 63 resize(c, True, TopLeft);
arg@480 64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@430 65 }
arg@430 66
arg@327 67 /* extern */
arg@327 68
arg@533 69 void (*arrange)(void) = DEFMODE;
arg@327 70
arg@327 71 void
arg@461 72 detach(Client *c) {
arg@378 73 if(c->prev)
arg@378 74 c->prev->next = c->next;
arg@378 75 if(c->next)
arg@378 76 c->next->prev = c->prev;
arg@378 77 if(c == clients)
arg@378 78 clients = c->next;
arg@378 79 c->next = c->prev = NULL;
arg@378 80 }
arg@378 81
arg@378 82 void
arg@533 83 dofloat(void) {
arg@402 84 Client *c;
arg@400 85
arg@327 86 for(c = clients; c; c = c->next) {
arg@327 87 if(isvisible(c)) {
arg@327 88 resize(c, True, TopLeft);
arg@327 89 }
arg@327 90 else
arg@327 91 ban(c);
arg@327 92 }
arg@446 93 if(!sel || !isvisible(sel)) {
arg@450 94 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 95 focus(c);
arg@446 96 }
arg@327 97 restack();
arg@327 98 }
arg@327 99
arg@327 100 void
arg@533 101 dotile(void) {
arg@531 102 unsigned int i, n, mpx, stackw, stackh, th;
arg@402 103 Client *c;
arg@400 104
arg@488 105 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
arg@488 106 n++;
arg@531 107 mpx = (sw * master) / 1000;
arg@531 108 stackw = sw - mpx;
arg@530 109 stackh = sh - bh;
arg@530 110 th = stackh;
arg@511 111 if(n > 1)
arg@530 112 th /= (n - 1);
arg@327 113
arg@535 114 for(i = 0, c = clients; c; c = c->next)
arg@327 115 if(isvisible(c)) {
arg@327 116 if(c->isfloat) {
arg@327 117 resize(c, True, TopLeft);
arg@327 118 continue;
arg@327 119 }
arg@488 120 c->ismax = False;
arg@523 121 c->x = sx;
arg@523 122 c->y = sy + bh;
arg@507 123 if(n == 1) { /* only 1 window */
arg@502 124 c->w = sw - 2 * BORDERPX;
arg@502 125 c->h = sh - 2 * BORDERPX - bh;
arg@327 126 }
arg@507 127 else if(i == 0) { /* master window */
arg@531 128 c->w = mpx - 2 * BORDERPX;
arg@530 129 c->h = sh - bh - 2 * BORDERPX;
arg@507 130 }
arg@523 131 else { /* tile window */
arg@531 132 c->x += mpx;
arg@531 133 c->w = stackw - 2 * BORDERPX;
arg@523 134 if(th > bh) {
arg@530 135 c->y = sy + (i - 1) * th + bh;
arg@530 136 if(i + 1 == n)
arg@530 137 c->h = sh - c->y - 2 * BORDERPX;
arg@531 138 else
arg@531 139 c->h = th - 2 * BORDERPX;
arg@507 140 }
arg@531 141 else /* fallback if th < bh */
arg@523 142 c->h = stackh - 2 * BORDERPX;
arg@327 143 }
arg@327 144 resize(c, False, TopLeft);
arg@535 145 i++;
arg@327 146 }
arg@327 147 else
arg@327 148 ban(c);
arg@532 149
arg@446 150 if(!sel || !isvisible(sel)) {
arg@450 151 for(c = stack; c && !isvisible(c); c = c->snext);
arg@450 152 focus(c);
arg@446 153 }
arg@327 154 restack();
arg@327 155 }
arg@327 156
arg@327 157 void
arg@461 158 focusnext(Arg *arg) {
arg@327 159 Client *c;
arg@327 160
arg@327 161 if(!sel)
arg@327 162 return;
arg@327 163 if(!(c = getnext(sel->next)))
arg@327 164 c = getnext(clients);
arg@327 165 if(c) {
arg@327 166 focus(c);
arg@327 167 restack();
arg@327 168 }
arg@327 169 }
arg@327 170
arg@327 171 void
arg@461 172 focusprev(Arg *arg) {
arg@327 173 Client *c;
arg@327 174
arg@327 175 if(!sel)
arg@327 176 return;
arg@327 177 if(!(c = getprev(sel->prev))) {
arg@327 178 for(c = clients; c && c->next; c = c->next);
arg@327 179 c = getprev(c);
arg@327 180 }
arg@327 181 if(c) {
arg@327 182 focus(c);
arg@327 183 restack();
arg@327 184 }
arg@327 185 }
arg@327 186
arg@420 187 Bool
arg@461 188 isvisible(Client *c) {
arg@420 189 unsigned int i;
arg@420 190
arg@420 191 for(i = 0; i < ntags; i++)
arg@420 192 if(c->tags[i] && seltag[i])
arg@420 193 return True;
arg@420 194 return False;
arg@420 195 }
arg@420 196
arg@415 197 void
arg@461 198 resizecol(Arg *arg) {
arg@423 199 unsigned int n;
arg@423 200 Client *c;
arg@418 201
arg@430 202 for(n = 0, c = clients; c; c = c->next)
arg@430 203 if(isvisible(c) && !c->isfloat)
arg@423 204 n++;
arg@486 205 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
arg@415 206 return;
arg@415 207 if(sel == getnext(clients)) {
arg@529 208 if(master + arg->i > 950 || master + arg->i < 50)
arg@415 209 return;
arg@505 210 master += arg->i;
arg@415 211 }
arg@415 212 else {
arg@529 213 if(master - arg->i > 950 || master - arg->i < 50)
arg@415 214 return;
arg@505 215 master -= arg->i;
arg@415 216 }
arg@533 217 arrange();
arg@415 218 }
arg@415 219
arg@327 220 void
arg@487 221 restack(void) {
arg@327 222 Client *c;
arg@327 223 XEvent ev;
arg@481 224
arg@437 225 if(!sel) {
arg@437 226 drawstatus();
arg@436 227 return;
arg@437 228 }
arg@436 229 if(sel->isfloat || arrange == dofloat) {
arg@436 230 XRaiseWindow(dpy, sel->win);
arg@436 231 XRaiseWindow(dpy, sel->twin);
arg@436 232 }
arg@512 233 if(arrange != dofloat) {
arg@512 234 if(!sel->isfloat) {
arg@512 235 XLowerWindow(dpy, sel->twin);
arg@512 236 XLowerWindow(dpy, sel->win);
arg@512 237 }
arg@436 238 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@512 239 if(c == sel)
arg@512 240 continue;
arg@436 241 XLowerWindow(dpy, c->twin);
arg@436 242 XLowerWindow(dpy, c->win);
arg@327 243 }
arg@512 244 }
arg@327 245 drawall();
arg@327 246 XSync(dpy, False);
arg@327 247 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 248 }
arg@327 249
arg@327 250 void
arg@461 251 togglemode(Arg *arg) {
arg@333 252 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 253 if(sel)
arg@533 254 arrange();
arg@327 255 else
arg@327 256 drawstatus();
arg@327 257 }
arg@327 258
arg@327 259 void
arg@461 260 toggleview(Arg *arg) {
arg@327 261 unsigned int i;
arg@327 262
arg@327 263 seltag[arg->i] = !seltag[arg->i];
arg@327 264 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 265 if(i == ntags)
arg@327 266 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 267 reorder();
arg@533 268 arrange();
arg@327 269 }
arg@327 270
arg@327 271 void
arg@461 272 view(Arg *arg) {
arg@327 273 unsigned int i;
arg@327 274
arg@327 275 for(i = 0; i < ntags; i++)
arg@327 276 seltag[i] = False;
arg@327 277 seltag[arg->i] = True;
arg@381 278 reorder();
arg@533 279 arrange();
arg@327 280 }
arg@327 281
arg@327 282 void
arg@461 283 viewall(Arg *arg) {
arg@395 284 unsigned int i;
arg@395 285
arg@395 286 for(i = 0; i < ntags; i++)
arg@395 287 seltag[i] = True;
arg@397 288 reorder();
arg@533 289 arrange();
arg@395 290 }
arg@395 291
arg@395 292 void
arg@461 293 zoom(Arg *arg) {
arg@423 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@430 303 for(n = 0, c = clients; c; c = c->next)
arg@430 304 if(isvisible(c) && !c->isfloat)
arg@423 305 n++;
arg@486 306 if(n < 2 || (arrange == dofloat))
arg@327 307 return;
arg@430 308 if((c = sel) == nexttiled(clients))
arg@433 309 if(!(c = nexttiled(c->next)))
arg@429 310 return;
arg@443 311 detach(c);
arg@443 312 if(clients)
arg@443 313 clients->prev = c;
arg@443 314 c->next = clients;
arg@443 315 clients = c;
arg@378 316 focus(c);
arg@533 317 arrange();
arg@327 318 }