aewl

annotate view.c @ 461:9d23330a5268

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