dwm-meillo

annotate view.c @ 465:590575d080fe

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