From 2e4a2d4f303d38909e59501cc54a708b82406f8d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 13 Jun 2014 22:18:36 +0200 Subject: [PATCH] =?UTF-8?q?Bugfix:=20don=E2=80=99t=20overwrite=20the=20ori?= =?UTF-8?q?ginal=20size=20of=20floating=20windows=20when=20changing=20bord?= =?UTF-8?q?er=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #1263 --- include/util.h | 1 + src/con.c | 34 ++++++++++++-------------- src/util.c | 7 ++++++ testcases/t/181-regress-float-border.t | 22 +++++++++++++++-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/util.h b/include/util.h index ac21b870..514a47c2 100644 --- a/include/util.h +++ b/include/util.h @@ -57,6 +57,7 @@ int min(int a, int b); int max(int a, int b); bool rect_contains(Rect rect, uint32_t x, uint32_t y); Rect rect_add(Rect a, Rect b); +Rect rect_sub(Rect a, Rect b); /** * Returns true if the name consists of only digits. diff --git a/src/con.c b/src/con.c index 4b47b182..14948cc6 100644 --- a/src/con.c +++ b/src/con.c @@ -1194,34 +1194,30 @@ void con_set_border_style(Con *con, int border_style, int border_width) { /* For floating containers, we want to keep the position/size of the * *window* itself. We first add the border pixels to con->rect to make - * con->rect represent the absolute position of the window. Then, we change - * the border and subtract the new border pixels. Afterwards, we update - * parent->rect to contain con. */ + * con->rect represent the absolute position of the window (same for + * parent). Then, we change the border style and subtract the new border + * pixels. For the parent, we do the same also for the decoration. */ DLOG("This is a floating container\n"); + Con *parent = con->parent; Rect bsr = con_border_style_rect(con); - con->rect.x += bsr.x; - con->rect.y += bsr.y; - con->rect.width += bsr.width; - con->rect.height += bsr.height; + int deco_height = (con->border_style == BS_NORMAL ? render_deco_height() : 0); + + con->rect = rect_add(con->rect, bsr); + parent->rect = rect_add(parent->rect, bsr); + parent->rect.y += deco_height; + parent->rect.height -= deco_height; /* Change the border style, get new border/decoration values. */ con->border_style = border_style; con->current_border_width = border_width; bsr = con_border_style_rect(con); - int deco_height = - (con->border_style == BS_NORMAL ? render_deco_height() : 0); + deco_height = (con->border_style == BS_NORMAL ? render_deco_height() : 0); - con->rect.x -= bsr.x; - con->rect.y -= bsr.y; - con->rect.width -= bsr.width; - con->rect.height -= bsr.height; - - Con *parent = con->parent; - parent->rect.x = con->rect.x; - parent->rect.y = con->rect.y - deco_height; - parent->rect.width = con->rect.width; - parent->rect.height = con->rect.height + deco_height; + con->rect = rect_sub(con->rect, bsr); + parent->rect = rect_sub(parent->rect, bsr); + parent->rect.y -= deco_height; + parent->rect.height += deco_height; } /* diff --git a/src/util.c b/src/util.c index de36d4aa..d8fb30fe 100644 --- a/src/util.c +++ b/src/util.c @@ -48,6 +48,13 @@ Rect rect_add(Rect a, Rect b) { a.height + b.height}; } +Rect rect_sub(Rect a, Rect b) { + return (Rect){a.x - b.x, + a.y - b.y, + a.width - b.width, + a.height - b.height}; +} + /* * Returns true if the name consists of only digits. * diff --git a/testcases/t/181-regress-float-border.t b/testcases/t/181-regress-float-border.t index c6a05424..57622c59 100644 --- a/testcases/t/181-regress-float-border.t +++ b/testcases/t/181-regress-float-border.t @@ -20,9 +20,8 @@ # d805d1bbeaf89e11f67c981f94c9f55bbb4b89d9 # use i3test; -use Data::Dumper; -fresh_workspace; +my $tmp = fresh_workspace; my $win = open_floating_window(rect => [10, 10, 200, 100]); @@ -36,4 +35,23 @@ $geometry = $win->rect; is($geometry->{width}, 200, 'width correct'); is($geometry->{height}, 100, 'height correct'); +################################################################################ +# When in fullscreen mode, the original position must not be overwritten. +################################################################################ + +sub get_floating_con_rect { + my ($nodes, $focus) = get_ws($tmp); + my $floating_con = $nodes->{floating_nodes}->[0]; + return $floating_con->{rect}; +} +my $old_rect = get_floating_con_rect(); + +cmd 'fullscreen'; + +is_deeply(get_floating_con_rect(), $old_rect, 'Rect the same after going into fullscreen'); + +cmd 'border pixel 2'; + +is_deeply(get_floating_con_rect(), $old_rect, 'Rect the same after changing border style'); + done_testing;