X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=ioncore%2Fsizehint.c;h=0d5d51da08da6a18c64270f8fec38c76697e1aaa;hp=b5747539ea1780401847d538d1997f6ae785b8d8;hb=e3aec18706513a87eaa7839dfdaf7e0fcd0d8d2a;hpb=803afbc1cd633f6c025bcd9537e9b7e9aedadd0d diff --git a/ioncore/sizehint.c b/ioncore/sizehint.c index b574753..0d5d51d 100644 --- a/ioncore/sizehint.c +++ b/ioncore/sizehint.c @@ -1,12 +1,9 @@ /* * ion/ioncore/sizehint.c * - * Copyright (c) Tuomo Valkonen 1999-2007. + * Copyright (c) Tuomo Valkonen 1999-2009. * - * Ion is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. + * See the included file LICENSE for details. */ #include @@ -70,11 +67,11 @@ static void correct_aspect(int max_w, int max_h, const WSizeHints *hints, void sizehints_correct(const WSizeHints *hints, int *wp, int *hp, bool min, bool override_no_constrain) { - int w=*wp; - int h=*hp; + int w=*wp, tw, bw=(hints->base_set ? hints->base_width : 0); + int h=*hp, th, bh=(hints->base_set ? hints->base_height : 0); int bs=0; - if(min){ + if(min && hints->min_set){ w=maxof(w, hints->min_width); h=maxof(h, hints->min_height); } @@ -84,24 +81,27 @@ void sizehints_correct(const WSizeHints *hints, int *wp, int *hp, *hp=h; return; } - - if(w>=hints->min_width && h>=hints->min_height) - correct_aspect(w, h, hints, &w, &h); + + tw=w-bw; + th=h-bh; + + if(tw>=0 && th>=0) + correct_aspect(tw, th, hints, &tw, &th); + + if(hints->inc_set){ + if(tw>0) + tw=(tw/hints->width_inc)*hints->width_inc; + if(th>0) + th=(th/hints->height_inc)*hints->height_inc; + } + + w=tw+bw; + h=th+bh; if(hints->max_set){ w=minof(w, hints->max_width); h=minof(h, hints->max_height); } - - if(hints->inc_set){ - /* base size should be set to 0 if none given by user program */ - bs=(hints->base_set ? hints->base_width : 0); - if(w>bs) - w=((w-bs)/hints->width_inc)*hints->width_inc+bs; - bs=(hints->base_set ? hints->base_height : 0); - if(h>bs) - h=((h-bs)/hints->height_inc)*hints->height_inc+bs; - } *wp=w; *hp=h; @@ -126,22 +126,17 @@ void xsizehints_sanity_adjust(XSizeHints *hints) } } - if(hints->min_width<0) - hints->min_width=0; - if(hints->min_height<0) - hints->min_height=0; + hints->min_width=maxof(hints->min_width, 0); + hints->min_height=maxof(hints->min_height, 0); if(!(hints->flags&PBaseSize) || hints->base_width<0) hints->base_width=hints->min_width; if(!(hints->flags&PBaseSize) || hints->base_height<0) hints->base_height=hints->min_height; - if(hints->flags&PMaxSize){ - if(hints->max_widthmin_width) - hints->max_width=hints->min_width; - if(hints->max_heightmin_height) - hints->max_height=hints->min_height; + hints->max_width=maxof(hints->max_width, hints->min_width); + hints->max_height=maxof(hints->max_height, hints->min_height); } hints->flags|=(PBaseSize|PMinSize);