aewl

annotate view.c @ 432:0f94ee451f6c

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