]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Ensure that the percentage is > 0.05 when using the 'resize' cmd (Thanks...
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 2 Aug 2011 20:31:45 +0000 (22:31 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 2 Aug 2011 20:31:45 +0000 (22:31 +0200)
Fixes #437

src/cmdparse.y

index d84023c3770a3fc7787bd32fa3396d89b4398d15..ec8e6c2c84e7a72e698e86827af56a17b248f4ee 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <float.h>
 
 #include "all.h"
 
@@ -106,6 +107,14 @@ char *parse_cmd(const char *new) {
     return json_output;
 }
 
+/*
+ * Returns true if a is definitely greater than b (using the given epsilon)
+ *
+ */
+bool definitelyGreaterThan(float a, float b, float epsilon) {
+    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
+}
+
 %}
 
 %error-verbose
@@ -807,10 +816,21 @@ resize:
                 focused->percent = percentage;
             if (other->percent == 0.0)
                 other->percent = percentage;
-            focused->percent += ((double)ppt / 100.0);
-            other->percent -= ((double)ppt / 100.0);
-            LOG("focused->percent after = %f\n", focused->percent);
-            LOG("other->percent after = %f\n", other->percent);
+            double new_focused_percent = focused->percent + ((double)ppt / 100.0);
+            double new_other_percent = other->percent - ((double)ppt / 100.0);
+            LOG("new_focused_percent = %f\n", new_focused_percent);
+            LOG("new_other_percent = %f\n", new_other_percent);
+            /* Ensure that the new percentages are positive and greater than
+             * 0.05 to have a reasonable minimum size. */
+            if (definitelyGreaterThan(new_focused_percent, 0.05, DBL_EPSILON) &&
+                definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
+                focused->percent += ((double)ppt / 100.0);
+                other->percent -= ((double)ppt / 100.0);
+                LOG("focused->percent after = %f\n", focused->percent);
+                LOG("other->percent after = %f\n", other->percent);
+            } else {
+                LOG("Not resizing, already at minimum size\n");
+            }
         }
 
         tree_render();