]> git.decadent.org.uk Git - ion3.git/blobdiff - ioncore/sizehint.c
Imported Upstream version 20090110
[ion3.git] / ioncore / sizehint.c
index b5747539ea1780401847d538d1997f6ae785b8d8..0d5d51da08da6a18c64270f8fec38c76697e1aaa 100644 (file)
@@ -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 <string.h>
@@ -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_width<hints->min_width)
-            hints->max_width=hints->min_width;
-        if(hints->max_height<hints->min_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);