From 45468a36f09137c29dcc42448514c19c0ee35346 Mon Sep 17 00:00:00 2001 From: Heman Gandhi Date: Fri, 10 Apr 2020 10:27:40 -0400 Subject: [PATCH] Move parent nodes in scratchpad correctly (#3793) * Move parent nodes in scratchpad across workspaces Co-Authored-By: Orestis --- src/scratchpad.c | 2 +- testcases/t/185-scratchpad.t | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/scratchpad.c b/src/scratchpad.c index 261a8bfd..cce4c0bf 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -138,7 +138,7 @@ bool scratchpad_show(Con *con) { floating->scratchpad_state != SCRATCHPAD_NONE) { DLOG("Found a visible scratchpad window on another workspace,\n"); DLOG("moving it to this workspace: con = %p\n", walk_con); - con_move_to_workspace(walk_con, focused_ws, true, false, false); + con_move_to_workspace(floating, focused_ws, true, false, false); con_activate(con_descend_focused(walk_con)); return true; } diff --git a/testcases/t/185-scratchpad.t b/testcases/t/185-scratchpad.t index bffdf74a..0cd9ac3b 100644 --- a/testcases/t/185-scratchpad.t +++ b/testcases/t/185-scratchpad.t @@ -548,5 +548,31 @@ is ($x->input_focus, $second->id, 'moving scratchpad window does not show it'); cmd '[id=' . $first->id . '] move position center'; is ($x->input_focus, $second->id, 'centering scratchpad window does not show it'); +################################################################################### +# Verify that a scratchpad container with child containers that was open in +# another workspace is moved to the current workspace (with all its children) +# after a scratchpad show. +################################################################################ + +kill_all_windows; +open_window; +open_window; +# This is to dodge the edge case were the whole workspace is moved +# window-by-window into the scratchpad. +cmd 'layout tabbed'; +cmd 'focus parent'; +cmd 'move to scratchpad'; +$ws = fresh_workspace; +cmd 'scratchpad show'; +# Case 1: a parent node in the scratchpad does not lose children +# Note on the layout: there should be a floating tabbed container, which is +# represented as follows: +# [workspace object] -> [floating_nodes] -> [tabbed node container] -> [the 2 children we expect] +is(scalar @{get_ws($ws)->{floating_nodes}->[0]->{nodes}->[0]->{nodes}}, 2, 'both windows moved from scratchpad to this workspace'); + +# Case 2: a parent node in the scratchpad from another workspace does not lose children +$ws = fresh_workspace; +cmd 'scratchpad show'; +is(scalar @{get_ws($ws)->{floating_nodes}->[0]->{nodes}->[0]->{nodes}}, 2, 'both windows moved from scratchpad focused on other workspace to this workspace'); done_testing;