diff --git a/include/data.h b/include/data.h index b53e277d..ea1d3240 100644 --- a/include/data.h +++ b/include/data.h @@ -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; diff --git a/src/con.c b/src/con.c index 7ef19477..5b68481a 100644 --- 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; diff --git a/src/handlers.c b/src/handlers.c index fdc75abe..6be2a5b1 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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(); diff --git a/src/render.c b/src/render.c index 0142ae97..1a7b8fd9 100644 --- a/src/render.c +++ b/src/render.c @@ -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--;