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;
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;
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();
* 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--;