dwm-meillo
diff view.c @ 327:96d09fd98e89
separated several functions into view.c
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Tue, 22 Aug 2006 16:50:21 +0200 |
parents | |
children | 827f8f6c9e97 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/view.c Tue Aug 22 16:50:21 2006 +0200 1.3 @@ -0,0 +1,253 @@ 1.4 +/* 1.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 1.6 + * See LICENSE file for license details. 1.7 + */ 1.8 +#include "dwm.h" 1.9 + 1.10 +/* extern */ 1.11 + 1.12 +void (*arrange)(Arg *) = DEFMODE; 1.13 + 1.14 +void 1.15 +dofloat(Arg *arg) 1.16 +{ 1.17 + Client *c; 1.18 + 1.19 + for(c = clients; c; c = c->next) { 1.20 + c->ismax = False; 1.21 + if(isvisible(c)) { 1.22 + resize(c, True, TopLeft); 1.23 + } 1.24 + else 1.25 + ban(c); 1.26 + } 1.27 + if(!sel || !isvisible(sel)) 1.28 + sel = getnext(clients); 1.29 + if(sel) 1.30 + focus(sel); 1.31 + else 1.32 + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 1.33 + restack(); 1.34 +} 1.35 + 1.36 +void 1.37 +dotile(Arg *arg) 1.38 +{ 1.39 + int h, i, n, w; 1.40 + Client *c; 1.41 + 1.42 + w = sw - mw; 1.43 + for(n = 0, c = clients; c; c = c->next) 1.44 + if(isvisible(c) && !c->isfloat) 1.45 + n++; 1.46 + 1.47 + if(n > 1) 1.48 + h = (sh - bh) / (n - 1); 1.49 + else 1.50 + h = sh - bh; 1.51 + 1.52 + for(i = 0, c = clients; c; c = c->next) { 1.53 + c->ismax = False; 1.54 + if(isvisible(c)) { 1.55 + if(c->isfloat) { 1.56 + resize(c, True, TopLeft); 1.57 + continue; 1.58 + } 1.59 + if(n == 1) { 1.60 + c->x = sx; 1.61 + c->y = sy + bh; 1.62 + c->w = sw - 2; 1.63 + c->h = sh - 2 - bh; 1.64 + } 1.65 + else if(i == 0) { 1.66 + c->x = sx; 1.67 + c->y = sy + bh; 1.68 + c->w = mw - 2; 1.69 + c->h = sh - 2 - bh; 1.70 + } 1.71 + else if(h > bh) { 1.72 + c->x = sx + mw; 1.73 + c->y = sy + (i - 1) * h + bh; 1.74 + c->w = w - 2; 1.75 + if(i + 1 == n) 1.76 + c->h = sh - c->y - 2; 1.77 + else 1.78 + c->h = h - 2; 1.79 + } 1.80 + else { /* fallback if h < bh */ 1.81 + c->x = sx + mw; 1.82 + c->y = sy + bh; 1.83 + c->w = w - 2; 1.84 + c->h = sh - 2 - bh; 1.85 + } 1.86 + resize(c, False, TopLeft); 1.87 + i++; 1.88 + } 1.89 + else 1.90 + ban(c); 1.91 + } 1.92 + if(!sel || !isvisible(sel)) 1.93 + sel = getnext(clients); 1.94 + if(sel) 1.95 + focus(sel); 1.96 + else 1.97 + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 1.98 + restack(); 1.99 +} 1.100 + 1.101 +void 1.102 +focusnext(Arg *arg) 1.103 +{ 1.104 + Client *c; 1.105 + 1.106 + if(!sel) 1.107 + return; 1.108 + 1.109 + if(!(c = getnext(sel->next))) 1.110 + c = getnext(clients); 1.111 + if(c) { 1.112 + focus(c); 1.113 + restack(); 1.114 + } 1.115 +} 1.116 + 1.117 +void 1.118 +focusprev(Arg *arg) 1.119 +{ 1.120 + Client *c; 1.121 + 1.122 + if(!sel) 1.123 + return; 1.124 + 1.125 + if(!(c = getprev(sel->prev))) { 1.126 + for(c = clients; c && c->next; c = c->next); 1.127 + c = getprev(c); 1.128 + } 1.129 + if(c) { 1.130 + focus(c); 1.131 + restack(); 1.132 + } 1.133 +} 1.134 + 1.135 +Bool 1.136 +isvisible(Client *c) 1.137 +{ 1.138 + unsigned int i; 1.139 + 1.140 + for(i = 0; i < ntags; i++) 1.141 + if(c->tags[i] && seltag[i]) 1.142 + return True; 1.143 + return False; 1.144 +} 1.145 + 1.146 +void 1.147 +restack() 1.148 +{ 1.149 + static unsigned int nwins = 0; 1.150 + static Window *wins = NULL; 1.151 + unsigned int f, fi, m, mi, n; 1.152 + Client *c; 1.153 + XEvent ev; 1.154 + 1.155 + for(f = 0, m = 0, c = clients; c; c = c->next) 1.156 + if(isvisible(c)) { 1.157 + if(c->isfloat || arrange == dofloat) 1.158 + f++; 1.159 + else 1.160 + m++; 1.161 + } 1.162 + if(!(n = 2 * (f + m))) { 1.163 + drawstatus(); 1.164 + return; 1.165 + } 1.166 + if(nwins < n) { 1.167 + nwins = n; 1.168 + wins = erealloc(wins, nwins * sizeof(Window)); 1.169 + } 1.170 + 1.171 + fi = 0; 1.172 + mi = 2 * f; 1.173 + if(sel->isfloat || arrange == dofloat) { 1.174 + wins[fi++] = sel->title; 1.175 + wins[fi++] = sel->win; 1.176 + } 1.177 + else { 1.178 + wins[mi++] = sel->title; 1.179 + wins[mi++] = sel->win; 1.180 + } 1.181 + for(c = clients; c; c = c->next) 1.182 + if(isvisible(c) && c != sel) { 1.183 + if(c->isfloat || arrange == dofloat) { 1.184 + wins[fi++] = c->title; 1.185 + wins[fi++] = c->win; 1.186 + } 1.187 + else { 1.188 + wins[mi++] = c->title; 1.189 + wins[mi++] = c->win; 1.190 + } 1.191 + } 1.192 + XRestackWindows(dpy, wins, n); 1.193 + drawall(); 1.194 + XSync(dpy, False); 1.195 + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 1.196 +} 1.197 + 1.198 +void 1.199 +togglemode(Arg *arg) 1.200 +{ 1.201 + arrange = arrange == dofloat ? dotile : dofloat; 1.202 + if(sel) 1.203 + arrange(NULL); 1.204 + else 1.205 + drawstatus(); 1.206 +} 1.207 + 1.208 +void 1.209 +toggleview(Arg *arg) 1.210 +{ 1.211 + unsigned int i; 1.212 + 1.213 + seltag[arg->i] = !seltag[arg->i]; 1.214 + for(i = 0; i < ntags && !seltag[i]; i++); 1.215 + if(i == ntags) 1.216 + seltag[arg->i] = True; /* cannot toggle last view */ 1.217 + arrange(NULL); 1.218 +} 1.219 + 1.220 +void 1.221 +view(Arg *arg) 1.222 +{ 1.223 + unsigned int i; 1.224 + 1.225 + for(i = 0; i < ntags; i++) 1.226 + seltag[i] = False; 1.227 + seltag[arg->i] = True; 1.228 + arrange(NULL); 1.229 +} 1.230 + 1.231 +void 1.232 +zoom(Arg *arg) 1.233 +{ 1.234 + Client *c; 1.235 + 1.236 + if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax) 1.237 + return; 1.238 + 1.239 + if(sel == getnext(clients)) { 1.240 + if((c = getnext(sel->next))) 1.241 + sel = c; 1.242 + else 1.243 + return; 1.244 + } 1.245 + 1.246 + /* pop */ 1.247 + sel->prev->next = sel->next; 1.248 + if(sel->next) 1.249 + sel->next->prev = sel->prev; 1.250 + sel->prev = NULL; 1.251 + clients->prev = sel; 1.252 + sel->next = clients; 1.253 + clients = sel; 1.254 + focus(sel); 1.255 + arrange(NULL); 1.256 +}