From 80ce13e44e50d0940ad7ff369a8517104b96b3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Sun, 30 Aug 2015 22:48:37 +0200 Subject: [PATCH 1/3] Move base_width and base_height from Con to Window relates to #665 --- include/data.h | 9 +++++---- src/floating.c | 12 ++++++------ src/handlers.c | 8 ++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/data.h b/include/data.h index 634cca67..4f69706f 100644 --- a/include/data.h +++ b/include/data.h @@ -409,6 +409,11 @@ struct Window { /** Depth of the window */ uint16_t depth; + + /* the wanted size of the window, used in combination with size + * increments (see below). */ + int base_width; + int base_height; }; /** @@ -572,10 +577,6 @@ struct Con { /* 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; - int base_height; /* the x11 border pixel attribute */ int border_width; diff --git a/src/floating.c b/src/floating.c index a82e2525..60322c0c 100644 --- a/src/floating.c +++ b/src/floating.c @@ -55,17 +55,17 @@ void floating_check_size(Con *floating_con) { border_rect.height += render_deco_height(); if (focused_con->height_increment && - floating_con->rect.height >= focused_con->base_height + border_rect.height) { - floating_con->rect.height -= focused_con->base_height + border_rect.height; + floating_con->rect.height >= focused_con->window->base_height + border_rect.height) { + floating_con->rect.height -= focused_con->window->base_height + border_rect.height; floating_con->rect.height -= floating_con->rect.height % focused_con->height_increment; - floating_con->rect.height += focused_con->base_height + border_rect.height; + floating_con->rect.height += focused_con->window->base_height + border_rect.height; } if (focused_con->width_increment && - floating_con->rect.width >= focused_con->base_width + border_rect.width) { - floating_con->rect.width -= focused_con->base_width + border_rect.width; + floating_con->rect.width >= focused_con->window->base_width + border_rect.width) { + floating_con->rect.width -= focused_con->window->base_width + border_rect.width; floating_con->rect.width -= floating_con->rect.width % focused_con->width_increment; - floating_con->rect.width += focused_con->base_width + border_rect.width; + floating_con->rect.width += focused_con->window->base_width + border_rect.width; } } diff --git a/src/handlers.c b/src/handlers.c index 1daefbc9..8e92bec9 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -960,10 +960,10 @@ static bool handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t stat base_height = size_hints.min_height; } - if (base_width != con->base_width || - base_height != con->base_height) { - con->base_width = base_width; - con->base_height = base_height; + if (base_width != con->window->base_width || + base_height != con->window->base_height) { + con->window->base_width = base_width; + con->window->base_height = base_height; DLOG("client's base_height changed to %d\n", base_height); DLOG("client's base_width changed to %d\n", base_width); changed = true; From f43a15acdede0ce1f52c0f9fc162732754a11a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Sun, 30 Aug 2015 23:04:20 +0200 Subject: [PATCH 2/3] Move width_increment and height_increment from Con to Window. relates to #665 --- include/data.h | 8 ++++---- src/commands.c | 25 ++++++++++++++----------- src/floating.c | 10 +++++----- src/handlers.c | 8 ++++---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/data.h b/include/data.h index 4f69706f..d6b99244 100644 --- a/include/data.h +++ b/include/data.h @@ -414,6 +414,10 @@ struct Window { * increments (see below). */ int base_width; int base_height; + + /* minimum increment size specified for the window (in pixels) */ + int width_increment; + int height_increment; }; /** @@ -582,10 +586,6 @@ struct Con { int border_width; int current_border_width; - /* minimum increment size specified for the window (in pixels) */ - int width_increment; - int height_increment; - struct Window *window; /* timer used for disabling urgency */ diff --git a/src/commands.c b/src/commands.c index 62adcc65..4f726df9 100644 --- a/src/commands.c +++ b/src/commands.c @@ -599,17 +599,20 @@ static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floatin /* ensure that resize will take place even if pixel increment is smaller than * height increment or width increment. * fixes #1011 */ - if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 || - strcmp(direction, "height") == 0) { - if (px < 0) - px = (-px < focused_con->height_increment) ? -focused_con->height_increment : px; - else - px = (px < focused_con->height_increment) ? focused_con->height_increment : px; - } else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) { - if (px < 0) - px = (-px < focused_con->width_increment) ? -focused_con->width_increment : px; - else - px = (px < focused_con->width_increment) ? focused_con->width_increment : px; + const i3Window *window = focused_con->window; + if (window != NULL) { + if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 || + strcmp(direction, "height") == 0) { + if (px < 0) + px = (-px < window->height_increment) ? -window->height_increment : px; + else + px = (px < window->height_increment) ? window->height_increment : px; + } else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) { + if (px < 0) + px = (-px < window->width_increment) ? -window->width_increment : px; + else + px = (px < window->width_increment) ? window->width_increment : px; + } } if (strcmp(direction, "up") == 0) { diff --git a/src/floating.c b/src/floating.c index 60322c0c..eef02ac6 100644 --- a/src/floating.c +++ b/src/floating.c @@ -42,7 +42,7 @@ void floating_check_size(Con *floating_con) { Con *focused_con = con_descend_focused(floating_con); /* obey size increments */ - if (focused_con->height_increment || focused_con->width_increment) { + if (focused_con->window != NULL && (focused_con->window->height_increment || focused_con->window->width_increment)) { Rect border_rect = con_border_style_rect(focused_con); /* We have to do the opposite calculations that render_con() do @@ -54,17 +54,17 @@ void floating_check_size(Con *floating_con) { if (con_border_style(focused_con) == BS_NORMAL) border_rect.height += render_deco_height(); - if (focused_con->height_increment && + if (focused_con->window->height_increment && floating_con->rect.height >= focused_con->window->base_height + border_rect.height) { floating_con->rect.height -= focused_con->window->base_height + border_rect.height; - floating_con->rect.height -= floating_con->rect.height % focused_con->height_increment; + floating_con->rect.height -= floating_con->rect.height % focused_con->window->height_increment; floating_con->rect.height += focused_con->window->base_height + border_rect.height; } - if (focused_con->width_increment && + if (focused_con->window->width_increment && floating_con->rect.width >= focused_con->window->base_width + border_rect.width) { floating_con->rect.width -= focused_con->window->base_width + border_rect.width; - floating_con->rect.width -= floating_con->rect.width % focused_con->width_increment; + floating_con->rect.width -= floating_con->rect.width % focused_con->window->width_increment; floating_con->rect.width += focused_con->window->base_width + border_rect.width; } } diff --git a/src/handlers.c b/src/handlers.c index 8e92bec9..91817bad 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -932,13 +932,13 @@ static bool handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t stat bool changed = false; if ((size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)) { if (size_hints.width_inc > 0 && size_hints.width_inc < 0xFFFF) - if (con->width_increment != size_hints.width_inc) { - con->width_increment = size_hints.width_inc; + if (con->window->width_increment != size_hints.width_inc) { + con->window->width_increment = size_hints.width_inc; changed = true; } if (size_hints.height_inc > 0 && size_hints.height_inc < 0xFFFF) - if (con->height_increment != size_hints.height_inc) { - con->height_increment = size_hints.height_inc; + if (con->window->height_increment != size_hints.height_inc) { + con->window->height_increment = size_hints.height_inc; changed = true; } From 344514bca5e9fb216ba930e43369352ee56ba7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Sun, 30 Aug 2015 23:07:25 +0200 Subject: [PATCH 3/3] Move aspect_ratio from Con to Window. relates to #665 --- include/data.h | 6 +++--- src/commands.c | 2 +- src/con.c | 7 ++++--- src/handlers.c | 4 ++-- src/render.c | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/data.h b/include/data.h index d6b99244..d75622ec 100644 --- a/include/data.h +++ b/include/data.h @@ -418,6 +418,9 @@ struct Window { /* minimum increment size specified for the window (in pixels) */ int width_increment; int height_increment; + + /* aspect ratio from WM_NORMAL_HINTS (MPlayer uses this for example) */ + double aspect_ratio; }; /** @@ -579,9 +582,6 @@ struct Con { double percent; - /* aspect ratio from WM_NORMAL_HINTS (MPlayer uses this for example) */ - double aspect_ratio; - /* the x11 border pixel attribute */ int border_width; int current_border_width; diff --git a/src/commands.c b/src/commands.c index 4f726df9..1740286c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -602,7 +602,7 @@ static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floatin const i3Window *window = focused_con->window; if (window != NULL) { if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 || - strcmp(direction, "height") == 0) { + strcmp(direction, "height") == 0) { if (px < 0) px = (-px < window->height_increment) ? -window->height_increment : px; else diff --git a/src/con.c b/src/con.c index 3427013d..b1ddf2ac 100644 --- a/src/con.c +++ b/src/con.c @@ -39,15 +39,16 @@ Con *con_new_skeleton(Con *parent, i3Window *window) { Con *new = scalloc(1, 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; new->current_border_width = -1; - if (window) + if (window) { new->depth = window->depth; - else + new->window->aspect_ratio = 0.0; + } else { new->depth = XCB_COPY_FROM_PARENT; + } DLOG("opening window\n"); TAILQ_INIT(&(new->floating_head)); diff --git a/src/handlers.c b/src/handlers.c index 91817bad..1e7eef1e 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -999,8 +999,8 @@ static bool handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t stat } else goto render_and_return; - if (fabs(con->aspect_ratio - aspect_ratio) > DBL_EPSILON) { - con->aspect_ratio = aspect_ratio; + if (fabs(con->window->aspect_ratio - aspect_ratio) > DBL_EPSILON) { + con->window->aspect_ratio = aspect_ratio; changed = true; } diff --git a/src/render.c b/src/render.c index 76dfa69c..7ada19eb 100644 --- a/src/render.c +++ b/src/render.c @@ -172,14 +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->aspect_ratio > 0.0) { + con->window->aspect_ratio > 0.0) { DLOG("aspect_ratio = %f, current width/height are %d/%d\n", - con->aspect_ratio, inset->width, inset->height); + con->window->aspect_ratio, inset->width, inset->height); double new_height = inset->height + 1; int new_width = inset->width; while (new_height > inset->height) { - new_height = (1.0 / con->aspect_ratio) * new_width; + new_height = (1.0 / con->window->aspect_ratio) * new_width; if (new_height > inset->height) new_width--;