From 4514146ed96b81cfa3238f686e342452fa34acb8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 6 Mar 2011 02:38:21 +0100 Subject: [PATCH] Use the combined geometry of children when setting a split container to floating (+testcase) (Thanks mseed) Fixes #332 --- src/floating.c | 12 +++++ src/x.c | 3 +- testcases/t/55-floating-split-size.t | 70 ++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 testcases/t/55-floating-split-size.t diff --git a/src/floating.c b/src/floating.c index 4a2e904f..2218da29 100644 --- a/src/floating.c +++ b/src/floating.c @@ -98,7 +98,19 @@ void floating_enable(Con *con, bool automatic) { int deco_height = font->height + 5; DLOG("Original rect: (%d, %d) with %d x %d\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height); + Rect zero = { 0, 0, 0, 0 }; nc->rect = con->geometry; + /* If the geometry was not set (split containers), we need to determine a + * sensible one by combining the geometry of all children */ + if (memcmp(&(nc->rect), &zero, sizeof(Rect)) == 0) { + DLOG("Geometry not set, combining children\n"); + Con *child; + TAILQ_FOREACH(child, &(con->nodes_head), nodes) { + DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height); + nc->rect.width += child->geometry.width; + nc->rect.height = max(nc->rect.height, child->geometry.height); + } + } /* Raise the width/height to at least 75x50 (minimum size for windows) */ nc->rect.width = max(nc->rect.width, 75); nc->rect.height = max(nc->rect.height, 50); diff --git a/src/x.c b/src/x.c index 5a13b51a..f932f9cb 100644 --- a/src/x.c +++ b/src/x.c @@ -149,8 +149,7 @@ void x_move_win(Con *src, Con *dest) { return; } - Rect zero; - memset(&zero, 0, sizeof(Rect)); + Rect zero = { 0, 0, 0, 0 }; if (memcmp(&(state_dest->window_rect), &(zero), sizeof(Rect)) == 0) { memcpy(&(state_dest->window_rect), &(state_src->window_rect), sizeof(Rect)); DLOG("COPYING RECT\n"); diff --git a/testcases/t/55-floating-split-size.t b/testcases/t/55-floating-split-size.t new file mode 100644 index 00000000..26671eb0 --- /dev/null +++ b/testcases/t/55-floating-split-size.t @@ -0,0 +1,70 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Test to see if i3 combines the geometry of all children in a split container +# when setting the split container to floating +# +use X11::XCB qw(:all); +use Time::HiRes qw(sleep); +use i3test; + +BEGIN { + use_ok('X11::XCB::Window'); +} + +my $x = X11::XCB::Connection->new; +my $i3 = i3("/tmp/nestedcons"); + +my $tmp = get_unused_workspace; +cmd "workspace $tmp"; + +##################################################################### +# open a window with 200x80 +##################################################################### + +my $first = $x->root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 200, 80], + background_color => '#FF0000', +); + +$first->map; + +sleep 0.25; + +##################################################################### +# Open a second window with 300x90 +##################################################################### + +my $second = $x->root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 300, 90], + background_color => '#00FF00', +); + +$second->map; + +sleep 0.25; + +##################################################################### +# Set the parent to floating +##################################################################### +cmd 'nop setting floating'; +cmd 'level up'; +cmd 'mode floating'; + +##################################################################### +# Get geometry of the first floating node (the split container) +##################################################################### + +my @nodes = @{get_ws($tmp)->{floating_nodes}}; +my $rect = $nodes[0]->{rect}; + +# we compare the width with ± 20 pixels for borders +cmp_ok($rect->{width}, '>', 500-20, 'width now > 480'); +cmp_ok($rect->{width}, '<', 500+20, 'width now < 520'); +# we compare the height with ± 40 pixels for decorations +cmp_ok($rect->{height}, '>', 90-40, 'width now > 50'); +cmp_ok($rect->{height}, '<', 90+40, 'width now < 130'); + +done_testing; -- 2.39.5