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;