]> git.sur5r.net Git - i3/i3/commitdiff
Store aspect_ratio instead of weird proportional_{width,height} (Thanks phillip)
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 29 Jun 2013 21:11:54 +0000 (23:11 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 29 Jun 2013 21:11:54 +0000 (23:11 +0200)
This commit only goes to “next” because I am not sure whether it
actually makes things better in all cases and want to give it some
testing first.

There was no documented reason behind using the
proportional_{width,height} variables, so I suppose that code was just
stupidity on my part (it was written merely a month after I started this
project in 2009).

fixes #1032

include/data.h
src/con.c
src/handlers.c
src/render.c

index b53e277d331aee1a9e2a7e17ac34b2d0c70b5c64..ea1d3240d4157938d017cc37195da934cc7db2a5 100644 (file)
@@ -507,10 +507,8 @@ struct Con {
 
     double percent;
 
-    /* proportional width/height, calculated from WM_NORMAL_HINTS, used to
-     * apply an aspect ratio to windows (think of MPlayer) */
-    int proportional_width;
-    int proportional_height;
+    /* aspect ratio from WM_NORMAL_HINTS (MPlayer uses this for example) */
+    double aspect_ratio;
     /* the wanted size of the window, used in combination with size
      * increments (see below). */
     int base_width;
index 7ef19477d1e59f822e18c2f71a9caf6025f6a410..5b68481a759317badf8bd65edfc8fda165b02232 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -51,6 +51,7 @@ Con *con_new_skeleton(Con *parent, i3Window *window) {
     Con *new = scalloc(sizeof(Con));
     new->on_remove_child = con_on_remove_child;
     TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
+    new->aspect_ratio = 0.0;
     new->type = CT_CON;
     new->window = window;
     new->border_style = config.default_border;
index fdc75abe604098816d16b8e36a77815d908e50f1..6be2a5b1f81ae0bfbbaab867c1a708956bc82e13 100644 (file)
@@ -799,22 +799,18 @@ static bool handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t stat
         goto render_and_return;
 
     /* Check if we need to set proportional_* variables using the correct ratio */
+    double aspect_ratio = 0.0;
     if ((width / height) < min_aspect) {
-        if (con->proportional_width != width ||
-            con->proportional_height != (width / min_aspect)) {
-            con->proportional_width = width;
-            con->proportional_height = width / min_aspect;
-            changed = true;
-        }
+        aspect_ratio = min_aspect;
     } else if ((width / height) > max_aspect) {
-        if (con->proportional_width != width ||
-            con->proportional_height != (width / max_aspect)) {
-            con->proportional_width = width;
-            con->proportional_height = width / max_aspect;
-            changed = true;
-        }
+        aspect_ratio = max_aspect;
     } else goto render_and_return;
 
+    if (fabs(con->aspect_ratio - aspect_ratio) > DBL_EPSILON) {
+        con->aspect_ratio = aspect_ratio;
+        changed = true;
+    }
+
 render_and_return:
     if (changed)
         tree_render();
index 0142ae9718f3fbd55771a222d9b08bab5d01ce42..1a7b8fd9ea3dd3aa6d68a2be46485a7febb18c9f 100644 (file)
@@ -172,13 +172,14 @@ void render_con(Con *con, bool render_fullscreen) {
          * Ignoring aspect ratio during fullscreen was necessary to fix MPlayer
          * subtitle rendering, see http://bugs.i3wm.org/594 */
         if (!render_fullscreen &&
-            con->proportional_height != 0 &&
-            con->proportional_width != 0) {
+            con->aspect_ratio > 0.0) {
+            DLOG("aspect_ratio = %f, current width/height are %d/%d\n",
+                 con->aspect_ratio, inset->width, inset->height);
             double new_height = inset->height + 1;
             int new_width = inset->width;
 
             while (new_height > inset->height) {
-                new_height = ((double)con->proportional_height / con->proportional_width) * new_width;
+                new_height = (1.0 / con->aspect_ratio) * new_width;
 
                 if (new_height > inset->height)
                     new_width--;