dwm-meillo

annotate view.c @ 439:baf86d388a77

Added tag 1.4 for changeset 3cff9403766bf83a9fc2a0aef230115d68de2a8e
author Anselm R. Garbe <arg@10kloc.org>
date Wed, 06 Sep 2006 12:19:07 +0200
parents b3659c3c5dab
children 056a5072c70a
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@433 44 for(c = getnext(c); 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 Client *c;
arg@327 219 XEvent ev;
arg@436 220
arg@437 221 if(!sel) {
arg@437 222 drawstatus();
arg@436 223 return;
arg@437 224 }
arg@436 225 if(sel->isfloat || arrange == dofloat) {
arg@436 226 XRaiseWindow(dpy, sel->win);
arg@436 227 XRaiseWindow(dpy, sel->twin);
arg@436 228 }
arg@436 229 if(arrange != dofloat)
arg@436 230 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
arg@436 231 XLowerWindow(dpy, c->twin);
arg@436 232 XLowerWindow(dpy, c->win);
arg@327 233 }
arg@327 234 drawall();
arg@327 235 XSync(dpy, False);
arg@327 236 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 237 }
arg@327 238
arg@327 239 void
arg@327 240 togglemode(Arg *arg)
arg@327 241 {
arg@333 242 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 243 if(sel)
arg@327 244 arrange(NULL);
arg@327 245 else
arg@327 246 drawstatus();
arg@327 247 }
arg@327 248
arg@327 249 void
arg@327 250 toggleview(Arg *arg)
arg@327 251 {
arg@327 252 unsigned int i;
arg@327 253
arg@327 254 seltag[arg->i] = !seltag[arg->i];
arg@327 255 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 256 if(i == ntags)
arg@327 257 seltag[arg->i] = True; /* cannot toggle last view */
arg@381 258 reorder();
arg@327 259 arrange(NULL);
arg@327 260 }
arg@327 261
arg@327 262 void
arg@327 263 view(Arg *arg)
arg@327 264 {
arg@327 265 unsigned int i;
arg@327 266
arg@327 267 for(i = 0; i < ntags; i++)
arg@327 268 seltag[i] = False;
arg@327 269 seltag[arg->i] = True;
arg@381 270 reorder();
arg@327 271 arrange(NULL);
arg@327 272 }
arg@327 273
arg@327 274 void
arg@395 275 viewall(Arg *arg)
arg@395 276 {
arg@395 277 unsigned int i;
arg@395 278
arg@395 279 for(i = 0; i < ntags; i++)
arg@395 280 seltag[i] = True;
arg@397 281 reorder();
arg@395 282 arrange(NULL);
arg@395 283 }
arg@395 284
arg@395 285 void
arg@327 286 zoom(Arg *arg)
arg@327 287 {
arg@423 288 unsigned int n;
arg@423 289 Client *c;
arg@327 290
arg@430 291 for(n = 0, c = clients; c; c = c->next)
arg@430 292 if(isvisible(c) && !c->isfloat)
arg@423 293 n++;
arg@423 294 if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
arg@327 295 return;
arg@327 296
arg@430 297 if((c = sel) == nexttiled(clients))
arg@433 298 if(!(c = nexttiled(c->next)))
arg@429 299 return;
arg@378 300 detach(c);
arg@381 301 c->next = clients;
arg@381 302 clients->prev = c;
arg@381 303 clients = c;
arg@378 304 focus(c);
arg@327 305 arrange(NULL);
arg@327 306 }