Store aspect_ratio instead of weird proportional_{width,height} (Thanks phillip)
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
This commit is contained in:
parent
c4d4418745
commit
f55b7977e8
|
@ -507,10 +507,8 @@ struct Con {
|
||||||
|
|
||||||
double percent;
|
double percent;
|
||||||
|
|
||||||
/* proportional width/height, calculated from WM_NORMAL_HINTS, used to
|
/* aspect ratio from WM_NORMAL_HINTS (MPlayer uses this for example) */
|
||||||
* apply an aspect ratio to windows (think of MPlayer) */
|
double aspect_ratio;
|
||||||
int proportional_width;
|
|
||||||
int proportional_height;
|
|
||||||
/* the wanted size of the window, used in combination with size
|
/* the wanted size of the window, used in combination with size
|
||||||
* increments (see below). */
|
* increments (see below). */
|
||||||
int base_width;
|
int base_width;
|
||||||
|
|
|
@ -51,6 +51,7 @@ Con *con_new_skeleton(Con *parent, i3Window *window) {
|
||||||
Con *new = scalloc(sizeof(Con));
|
Con *new = scalloc(sizeof(Con));
|
||||||
new->on_remove_child = con_on_remove_child;
|
new->on_remove_child = con_on_remove_child;
|
||||||
TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
|
TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
|
||||||
|
new->aspect_ratio = 0.0;
|
||||||
new->type = CT_CON;
|
new->type = CT_CON;
|
||||||
new->window = window;
|
new->window = window;
|
||||||
new->border_style = config.default_border;
|
new->border_style = config.default_border;
|
||||||
|
|
|
@ -799,21 +799,17 @@ static bool handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t stat
|
||||||
goto render_and_return;
|
goto render_and_return;
|
||||||
|
|
||||||
/* Check if we need to set proportional_* variables using the correct ratio */
|
/* Check if we need to set proportional_* variables using the correct ratio */
|
||||||
|
double aspect_ratio = 0.0;
|
||||||
if ((width / height) < min_aspect) {
|
if ((width / height) < min_aspect) {
|
||||||
if (con->proportional_width != width ||
|
aspect_ratio = min_aspect;
|
||||||
con->proportional_height != (width / min_aspect)) {
|
|
||||||
con->proportional_width = width;
|
|
||||||
con->proportional_height = width / min_aspect;
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
} else if ((width / height) > max_aspect) {
|
} else if ((width / height) > max_aspect) {
|
||||||
if (con->proportional_width != width ||
|
aspect_ratio = max_aspect;
|
||||||
con->proportional_height != (width / max_aspect)) {
|
} else goto render_and_return;
|
||||||
con->proportional_width = width;
|
|
||||||
con->proportional_height = width / max_aspect;
|
if (fabs(con->aspect_ratio - aspect_ratio) > DBL_EPSILON) {
|
||||||
|
con->aspect_ratio = aspect_ratio;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
} else goto render_and_return;
|
|
||||||
|
|
||||||
render_and_return:
|
render_and_return:
|
||||||
if (changed)
|
if (changed)
|
||||||
|
|
|
@ -172,13 +172,14 @@ void render_con(Con *con, bool render_fullscreen) {
|
||||||
* Ignoring aspect ratio during fullscreen was necessary to fix MPlayer
|
* Ignoring aspect ratio during fullscreen was necessary to fix MPlayer
|
||||||
* subtitle rendering, see http://bugs.i3wm.org/594 */
|
* subtitle rendering, see http://bugs.i3wm.org/594 */
|
||||||
if (!render_fullscreen &&
|
if (!render_fullscreen &&
|
||||||
con->proportional_height != 0 &&
|
con->aspect_ratio > 0.0) {
|
||||||
con->proportional_width != 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;
|
double new_height = inset->height + 1;
|
||||||
int new_width = inset->width;
|
int new_width = inset->width;
|
||||||
|
|
||||||
while (new_height > inset->height) {
|
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)
|
if (new_height > inset->height)
|
||||||
new_width--;
|
new_width--;
|
||||||
|
|
Loading…
Reference in New Issue