aewl

annotate view.c @ 358:64c19db8af25

s/TILED/TILE/g
author Anselm R. Garbe <arg@10kloc.org>
date Fri, 25 Aug 2006 15:16:20 +0200
parents 827f8f6c9e97
children 83576f5f0a90
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@327 7 /* extern */
arg@327 8
arg@327 9 void (*arrange)(Arg *) = DEFMODE;
arg@327 10
arg@327 11 void
arg@327 12 dofloat(Arg *arg)
arg@327 13 {
arg@327 14 Client *c;
arg@327 15
arg@327 16 for(c = clients; c; c = c->next) {
arg@327 17 c->ismax = False;
arg@327 18 if(isvisible(c)) {
arg@327 19 resize(c, True, TopLeft);
arg@327 20 }
arg@327 21 else
arg@327 22 ban(c);
arg@327 23 }
arg@327 24 if(!sel || !isvisible(sel))
arg@327 25 sel = getnext(clients);
arg@327 26 if(sel)
arg@327 27 focus(sel);
arg@327 28 else
arg@327 29 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
arg@327 30 restack();
arg@327 31 }
arg@327 32
arg@327 33 void
arg@327 34 dotile(Arg *arg)
arg@327 35 {
arg@327 36 int h, i, n, w;
arg@327 37 Client *c;
arg@327 38
arg@327 39 w = sw - mw;
arg@327 40 for(n = 0, c = clients; c; c = c->next)
arg@327 41 if(isvisible(c) && !c->isfloat)
arg@327 42 n++;
arg@327 43
arg@327 44 if(n > 1)
arg@327 45 h = (sh - bh) / (n - 1);
arg@327 46 else
arg@327 47 h = sh - bh;
arg@327 48
arg@327 49 for(i = 0, c = clients; c; c = c->next) {
arg@327 50 c->ismax = False;
arg@327 51 if(isvisible(c)) {
arg@327 52 if(c->isfloat) {
arg@327 53 resize(c, True, TopLeft);
arg@327 54 continue;
arg@327 55 }
arg@327 56 if(n == 1) {
arg@327 57 c->x = sx;
arg@327 58 c->y = sy + bh;
arg@327 59 c->w = sw - 2;
arg@327 60 c->h = sh - 2 - bh;
arg@327 61 }
arg@327 62 else if(i == 0) {
arg@327 63 c->x = sx;
arg@327 64 c->y = sy + bh;
arg@327 65 c->w = mw - 2;
arg@327 66 c->h = sh - 2 - bh;
arg@327 67 }
arg@327 68 else if(h > bh) {
arg@327 69 c->x = sx + mw;
arg@327 70 c->y = sy + (i - 1) * h + bh;
arg@327 71 c->w = w - 2;
arg@327 72 if(i + 1 == n)
arg@327 73 c->h = sh - c->y - 2;
arg@327 74 else
arg@327 75 c->h = h - 2;
arg@327 76 }
arg@327 77 else { /* fallback if h < bh */
arg@327 78 c->x = sx + mw;
arg@327 79 c->y = sy + bh;
arg@327 80 c->w = w - 2;
arg@327 81 c->h = sh - 2 - bh;
arg@327 82 }
arg@327 83 resize(c, False, TopLeft);
arg@327 84 i++;
arg@327 85 }
arg@327 86 else
arg@327 87 ban(c);
arg@327 88 }
arg@327 89 if(!sel || !isvisible(sel))
arg@327 90 sel = getnext(clients);
arg@327 91 if(sel)
arg@327 92 focus(sel);
arg@327 93 else
arg@327 94 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
arg@327 95 restack();
arg@327 96 }
arg@327 97
arg@327 98 void
arg@327 99 focusnext(Arg *arg)
arg@327 100 {
arg@327 101 Client *c;
arg@327 102
arg@327 103 if(!sel)
arg@327 104 return;
arg@327 105
arg@327 106 if(!(c = getnext(sel->next)))
arg@327 107 c = getnext(clients);
arg@327 108 if(c) {
arg@327 109 focus(c);
arg@327 110 restack();
arg@327 111 }
arg@327 112 }
arg@327 113
arg@327 114 void
arg@327 115 focusprev(Arg *arg)
arg@327 116 {
arg@327 117 Client *c;
arg@327 118
arg@327 119 if(!sel)
arg@327 120 return;
arg@327 121
arg@327 122 if(!(c = getprev(sel->prev))) {
arg@327 123 for(c = clients; c && c->next; c = c->next);
arg@327 124 c = getprev(c);
arg@327 125 }
arg@327 126 if(c) {
arg@327 127 focus(c);
arg@327 128 restack();
arg@327 129 }
arg@327 130 }
arg@327 131
arg@327 132 Bool
arg@327 133 isvisible(Client *c)
arg@327 134 {
arg@327 135 unsigned int i;
arg@327 136
arg@327 137 for(i = 0; i < ntags; i++)
arg@327 138 if(c->tags[i] && seltag[i])
arg@327 139 return True;
arg@327 140 return False;
arg@327 141 }
arg@327 142
arg@327 143 void
arg@327 144 restack()
arg@327 145 {
arg@327 146 static unsigned int nwins = 0;
arg@327 147 static Window *wins = NULL;
arg@327 148 unsigned int f, fi, m, mi, n;
arg@327 149 Client *c;
arg@327 150 XEvent ev;
arg@327 151
arg@327 152 for(f = 0, m = 0, c = clients; c; c = c->next)
arg@327 153 if(isvisible(c)) {
arg@327 154 if(c->isfloat || arrange == dofloat)
arg@327 155 f++;
arg@327 156 else
arg@327 157 m++;
arg@327 158 }
arg@327 159 if(!(n = 2 * (f + m))) {
arg@327 160 drawstatus();
arg@327 161 return;
arg@327 162 }
arg@327 163 if(nwins < n) {
arg@327 164 nwins = n;
arg@327 165 wins = erealloc(wins, nwins * sizeof(Window));
arg@327 166 }
arg@327 167
arg@327 168 fi = 0;
arg@327 169 mi = 2 * f;
arg@327 170 if(sel->isfloat || arrange == dofloat) {
arg@342 171 wins[fi++] = sel->twin;
arg@327 172 wins[fi++] = sel->win;
arg@327 173 }
arg@327 174 else {
arg@342 175 wins[mi++] = sel->twin;
arg@327 176 wins[mi++] = sel->win;
arg@327 177 }
arg@327 178 for(c = clients; c; c = c->next)
arg@327 179 if(isvisible(c) && c != sel) {
arg@327 180 if(c->isfloat || arrange == dofloat) {
arg@342 181 wins[fi++] = c->twin;
arg@327 182 wins[fi++] = c->win;
arg@327 183 }
arg@327 184 else {
arg@342 185 wins[mi++] = c->twin;
arg@327 186 wins[mi++] = c->win;
arg@327 187 }
arg@327 188 }
arg@327 189 XRestackWindows(dpy, wins, n);
arg@327 190 drawall();
arg@327 191 XSync(dpy, False);
arg@327 192 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
arg@327 193 }
arg@327 194
arg@327 195 void
arg@327 196 togglemode(Arg *arg)
arg@327 197 {
arg@333 198 arrange = (arrange == dofloat) ? dotile : dofloat;
arg@327 199 if(sel)
arg@327 200 arrange(NULL);
arg@327 201 else
arg@327 202 drawstatus();
arg@327 203 }
arg@327 204
arg@327 205 void
arg@327 206 toggleview(Arg *arg)
arg@327 207 {
arg@327 208 unsigned int i;
arg@327 209
arg@327 210 seltag[arg->i] = !seltag[arg->i];
arg@327 211 for(i = 0; i < ntags && !seltag[i]; i++);
arg@327 212 if(i == ntags)
arg@327 213 seltag[arg->i] = True; /* cannot toggle last view */
arg@327 214 arrange(NULL);
arg@327 215 }
arg@327 216
arg@327 217 void
arg@327 218 view(Arg *arg)
arg@327 219 {
arg@327 220 unsigned int i;
arg@327 221
arg@327 222 for(i = 0; i < ntags; i++)
arg@327 223 seltag[i] = False;
arg@327 224 seltag[arg->i] = True;
arg@327 225 arrange(NULL);
arg@327 226 }
arg@327 227
arg@327 228 void
arg@327 229 zoom(Arg *arg)
arg@327 230 {
arg@327 231 Client *c;
arg@327 232
arg@327 233 if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
arg@327 234 return;
arg@327 235
arg@327 236 if(sel == getnext(clients)) {
arg@327 237 if((c = getnext(sel->next)))
arg@327 238 sel = c;
arg@327 239 else
arg@327 240 return;
arg@327 241 }
arg@327 242
arg@327 243 /* pop */
arg@327 244 sel->prev->next = sel->next;
arg@327 245 if(sel->next)
arg@327 246 sel->next->prev = sel->prev;
arg@327 247 sel->prev = NULL;
arg@327 248 clients->prev = sel;
arg@327 249 sel->next = clients;
arg@327 250 clients = sel;
arg@327 251 focus(sel);
arg@327 252 arrange(NULL);
arg@327 253 }