From: Anselm R. Garbe Date: Tue, 6 Feb 2007 14:22:13 +0000 (+0100) Subject: implemented aspect ratio support of windows X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;ds=inline;h=2ddc78720aceda76e22fd3584740fc86a2e7c677;p=dwm.git implemented aspect ratio support of windows --- diff --git a/client.c b/client.c index f3c9bf2..2b194d7 100644 --- a/client.c +++ b/client.c @@ -9,6 +9,13 @@ /* static */ +static void +closestpt(float *rx, float *ry, float x, float y, float grad) { + float u = (x * grad + y) / (grad * grad + 1); + *rx = u * grad; + *ry = u; +} + static void detachstack(Client *c) { Client **tc; @@ -184,15 +191,12 @@ manage(Window w, XWindowAttributes *wa) { void resize(Client *c, Bool sizehints) { + float dx, dy, min, max, actual; XWindowChanges wc; if(c->w <= 0 || c->h <= 0) return; if(sizehints) { - if(c->incw) - c->w -= (c->w - c->basew) % c->incw; - if(c->inch) - c->h -= (c->h - c->baseh) % c->inch; if(c->minw && c->w < c->minw) c->w = c->minw; if(c->minh && c->h < c->minh) @@ -201,6 +205,30 @@ resize(Client *c, Bool sizehints) { c->w = c->maxw; if(c->maxh && c->h > c->maxh) c->h = c->maxh; + /* inspired by algorithm from fluxbox */ + if(c->minay > 0 && c->maxay && (c->h - c->baseh) > 0) { + dx = (float)(c->w - c->basew); + dy = (float)(c->h - c->baseh); + min = (float)(c->minax) / (float)(c->minay); + max = (float)(c->maxax) / (float)(c->maxay); + actual = dx / dy; + if(max > 0 && min > 0 && actual > 0) { + if(actual < min) { + closestpt(&dx, &dy, dx, dy, min); + c->w = (int)dx + c->basew; + c->h = (int)dy + c->baseh; + } + else if(actual > max) { + closestpt(&dx, &dy, dx, dy, max); + c->w = (int)dx + c->basew; + c->h = (int)dy + c->baseh; + } + } + } + if(c->incw) + c->w -= (c->w - c->basew) % c->incw; + if(c->inch) + c->h -= (c->h - c->baseh) % c->inch; } if(c->w == sw && c->h == sh) c->border = 0; @@ -257,6 +285,14 @@ updatesizehints(Client *c) { } else c->minw = c->minh = 0; + if(c->flags & PAspect) { + c->minax = size.min_aspect.x; + c->minay = size.min_aspect.y; + c->maxax = size.max_aspect.x; + c->maxay = size.max_aspect.y; + } + else + c->minax = c->minay = c->maxax = c->maxay = 0; c->isfixed = (c->maxw && c->minw && c->maxh && c->minh && c->maxw == c->minw && c->maxh == c->minh); } diff --git a/dwm.h b/dwm.h index 1021428..a7053c5 100644 --- a/dwm.h +++ b/dwm.h @@ -73,6 +73,7 @@ struct Client { int x, y, w, h; int rx, ry, rw, rh; /* revert geometry */ int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int minax, minay, maxax, maxay; long flags; unsigned int border; Bool isfloat, isfixed, ismax;