sizehint.c (876B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "../x11.h" 5 6 Rectangle 7 sizehint(WinHints *h, Rectangle r) { 8 Point p, aspect, origin; 9 10 if(h == nil) 11 return r; 12 13 origin = r.min; 14 r = rectsubpt(r, origin); 15 16 /* Min/max */ 17 r.max.x = max(r.max.x, h->min.x); 18 r.max.y = max(r.max.y, h->min.y); 19 r.max.x = min(r.max.x, h->max.x); 20 r.max.y = min(r.max.y, h->max.y); 21 22 /* Increment */ 23 p = subpt(r.max, h->base); 24 r.max.x -= p.x % h->inc.x; 25 r.max.y -= p.y % h->inc.y; 26 27 /* Aspect */ 28 p = subpt(r.max, h->baspect); 29 p.y = max(p.y, 1); 30 31 aspect = h->aspect.min; 32 if(p.x * aspect.y / p.y < aspect.x) 33 r.max.y = h->baspect.y 34 + p.x * aspect.y / aspect.x; 35 36 aspect = h->aspect.max; 37 if(p.x * aspect.y / p.y > aspect.x) 38 r.max.x = h->baspect.x 39 + p.y * aspect.x / aspect.y; 40 41 return rectaddpt(r, origin); 42 }