From: Michael Stapelberg Date: Sat, 26 Nov 2011 21:18:23 +0000 (+0000) Subject: Bugfix: Retain absolute window position and size when changing floating borders ... X-Git-Tag: 4.1.1~30^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=970d11709e99aab7db13a2fd28a758a68a4137dc;p=i3%2Fi3 Bugfix: Retain absolute window position and size when changing floating borders (Thanks binzter) Fixes: #561 --- diff --git a/include/con.h b/include/con.h index 34c6450c..b14c477e 100644 --- a/include/con.h +++ b/include/con.h @@ -233,6 +233,13 @@ Rect con_border_style_rect(Con *con); */ int con_border_style(Con *con); +/** + * Sets the given border style on con, correctly keeping the position/size of a + * floating window. + * + */ +void con_set_border_style(Con *con, int border_style); + /** * This function changes the layout of a given container. Use it to handle * special cases like changing a whole workspace to stacked/tabbed (creates a diff --git a/src/cmdparse.y b/src/cmdparse.y index e413f21b..bf181c28 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -719,10 +719,12 @@ border: TAILQ_FOREACH(current, &owindows, owindows) { printf("matching: %p / %s\n", current->con, current->con->name); + int border_style = current->con->border_style; if ($2 == TOK_TOGGLE) { - current->con->border_style++; - current->con->border_style %= 3; - } else current->con->border_style = $2; + border_style++; + border_style %= 3; + } else border_style = $2; + con_set_border_style(current->con, border_style); } tree_render(); diff --git a/src/con.c b/src/con.c index ee84467b..198f0594 100644 --- a/src/con.c +++ b/src/con.c @@ -941,6 +941,52 @@ int con_border_style(Con *con) { return con->border_style; } +/* + * Sets the given border style on con, correctly keeping the position/size of a + * floating window. + * + */ +void con_set_border_style(Con *con, int border_style) { + /* Handle the simple case: non-floating containerns */ + if (!con_is_floating(con)) { + con->border_style = border_style; + return; + } + + /* For floating containers, we want to keep the position/size of the + * *window* itself. Since the window size is rendered based on the + * container which it is in, we first remove the border/decoration specific + * amount of pixels from parent->rect, change the border, then add the new + * border/decoration specific pixels. */ + DLOG("This is a floating container\n"); + + /* Get current border/decoration pixel values. */ + int deco_height = + (con->border_style == BS_NORMAL ? config.font.height + 5 : 0); + Rect bsr = con_border_style_rect(con); + Con *parent = con->parent; + + con->rect.x += bsr.x; + con->rect.y += bsr.y; + con->rect.width += bsr.width; + con->rect.height += bsr.height; + + /* Change the border style, get new border/decoration values. */ + con->border_style = border_style; + bsr = con_border_style_rect(con); + deco_height = (con->border_style == BS_NORMAL ? config.font.height + 5 : 0); + + con->rect.x -= bsr.x; + con->rect.y -= bsr.y; + con->rect.width -= bsr.width; + con->rect.height -= bsr.height; + + 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; +} + /* * This function changes the layout of a given container. Use it to handle * special cases like changing a whole workspace to stacked/tabbed (creates a