dwm-meillo

annotate view.c @ 451:d358f2daa8ba

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