aewl
changeset 731:29c9b557ed95
implemented aspect ratio support of windows
author | Anselm R. Garbe <arg@suckless.org> |
---|---|
date | Tue, 06 Feb 2007 15:22:13 +0100 |
parents | 8997e28553a8 |
children | a642068c4834 |
files | client.c dwm.h |
diffstat | 2 files changed, 41 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/client.c Mon Feb 05 11:19:46 2007 +0100 1.2 +++ b/client.c Tue Feb 06 15:22:13 2007 +0100 1.3 @@ -10,6 +10,13 @@ 1.4 /* static */ 1.5 1.6 static void 1.7 +closestpt(float *rx, float *ry, float x, float y, float grad) { 1.8 + float u = (x * grad + y) / (grad * grad + 1); 1.9 + *rx = u * grad; 1.10 + *ry = u; 1.11 +} 1.12 + 1.13 +static void 1.14 detachstack(Client *c) { 1.15 Client **tc; 1.16 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); 1.17 @@ -184,15 +191,12 @@ 1.18 1.19 void 1.20 resize(Client *c, Bool sizehints) { 1.21 + float dx, dy, min, max, actual; 1.22 XWindowChanges wc; 1.23 1.24 if(c->w <= 0 || c->h <= 0) 1.25 return; 1.26 if(sizehints) { 1.27 - if(c->incw) 1.28 - c->w -= (c->w - c->basew) % c->incw; 1.29 - if(c->inch) 1.30 - c->h -= (c->h - c->baseh) % c->inch; 1.31 if(c->minw && c->w < c->minw) 1.32 c->w = c->minw; 1.33 if(c->minh && c->h < c->minh) 1.34 @@ -201,6 +205,30 @@ 1.35 c->w = c->maxw; 1.36 if(c->maxh && c->h > c->maxh) 1.37 c->h = c->maxh; 1.38 + /* inspired by algorithm from fluxbox */ 1.39 + if(c->minay > 0 && c->maxay && (c->h - c->baseh) > 0) { 1.40 + dx = (float)(c->w - c->basew); 1.41 + dy = (float)(c->h - c->baseh); 1.42 + min = (float)(c->minax) / (float)(c->minay); 1.43 + max = (float)(c->maxax) / (float)(c->maxay); 1.44 + actual = dx / dy; 1.45 + if(max > 0 && min > 0 && actual > 0) { 1.46 + if(actual < min) { 1.47 + closestpt(&dx, &dy, dx, dy, min); 1.48 + c->w = (int)dx + c->basew; 1.49 + c->h = (int)dy + c->baseh; 1.50 + } 1.51 + else if(actual > max) { 1.52 + closestpt(&dx, &dy, dx, dy, max); 1.53 + c->w = (int)dx + c->basew; 1.54 + c->h = (int)dy + c->baseh; 1.55 + } 1.56 + } 1.57 + } 1.58 + if(c->incw) 1.59 + c->w -= (c->w - c->basew) % c->incw; 1.60 + if(c->inch) 1.61 + c->h -= (c->h - c->baseh) % c->inch; 1.62 } 1.63 if(c->w == sw && c->h == sh) 1.64 c->border = 0; 1.65 @@ -257,6 +285,14 @@ 1.66 } 1.67 else 1.68 c->minw = c->minh = 0; 1.69 + if(c->flags & PAspect) { 1.70 + c->minax = size.min_aspect.x; 1.71 + c->minay = size.min_aspect.y; 1.72 + c->maxax = size.max_aspect.x; 1.73 + c->maxay = size.max_aspect.y; 1.74 + } 1.75 + else 1.76 + c->minax = c->minay = c->maxax = c->maxay = 0; 1.77 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh && 1.78 c->maxw == c->minw && c->maxh == c->minh); 1.79 }
2.1 --- a/dwm.h Mon Feb 05 11:19:46 2007 +0100 2.2 +++ b/dwm.h Tue Feb 06 15:22:13 2007 +0100 2.3 @@ -73,6 +73,7 @@ 2.4 int x, y, w, h; 2.5 int rx, ry, rw, rh; /* revert geometry */ 2.6 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 2.7 + int minax, minay, maxax, maxay; 2.8 long flags; 2.9 unsigned int border; 2.10 Bool isfloat, isfixed, ismax;