aewl

annotate view.c @ 480:680aca428830

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