From aea445b690475b84051c9b3247cd8a5046dae4c7 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 13 May 2011 21:29:01 +0200 Subject: [PATCH] Bugfix: Attach new cons at the correct place when a floating con is focused (+test) (Thanks fernandotcl) New containers were previously attached directly to the workspace instead of to the previously focused place in the workspace (for example a stacked con). Fixes: #376 --- src/tree.c | 10 +++++--- testcases/t/38-floating-attach.t | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/tree.c b/src/tree.c index 8d55c14b..336db4fa 100644 --- a/src/tree.c +++ b/src/tree.c @@ -66,9 +66,13 @@ Con *tree_open_con(Con *con) { } /* If the currently focused container is a floating container, we - * attach the new container to the workspace */ - if (con->type == CT_FLOATING_CON) - con = con->parent; + * attach the new container to the currently focused spot in its + * workspace. */ + if (con->type == CT_FLOATING_CON) { + con = con_descend_tiling_focused(con->parent); + if (con->type != CT_WORKSPACE) + con = con->parent; + } DLOG("con = %p\n", con); } diff --git a/testcases/t/38-floating-attach.t b/testcases/t/38-floating-attach.t index a1cf4d63..9e5d7829 100644 --- a/testcases/t/38-floating-attach.t +++ b/testcases/t/38-floating-attach.t @@ -61,4 +61,48 @@ sleep 0.25; is(@{$nodes}, 1, 'one tiling node'); +############################################################################# +# 2: similar case: floating windows should be attached at the currently focused +# position in the workspace (for example a stack), not just at workspace level. +############################################################################# + +$tmp = fresh_workspace; + +my $first = open_standard_window($x); +my $second = open_standard_window($x); + +cmd 'layout stacked'; + +$ws = get_ws($tmp); +is(@{$ws->{floating_nodes}}, 0, 'no floating nodes so far'); +is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); + +# Create a floating window +my $window = $x->root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 30, 30], + background_color => '#C0C0C0', + # replace the type with 'utility' as soon as the coercion works again in X11::XCB + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), +); + +isa_ok($window, 'X11::XCB::Window'); + +$window->map; + +sleep 0.25; + +ok($window->mapped, 'Window is mapped'); + +$ws = get_ws($tmp); +is(@{$ws->{floating_nodes}}, 1, 'one floating nodes'); +is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); + +my $third = open_standard_window($x); + + +$ws = get_ws($tmp); +is(@{$ws->{floating_nodes}}, 1, 'one floating nodes'); +is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); + done_testing; -- 2.39.5