From 359d75cd3c48fbf2e3b26b2814475f6373555edb Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 16 Oct 2019 01:14:39 +0300 Subject: [PATCH] Fix crash with moving container that is to be flattened Same can happen with move_to_output_directed but it is not so easy to write a test about it. Fixes #3831 --- src/commands.c | 6 ++-- src/move.c | 4 +-- testcases/t/309-crash-move-parent.t | 43 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 testcases/t/309-crash-move-parent.t diff --git a/src/commands.c b/src/commands.c index 5527860c..cb2db32f 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1508,9 +1508,11 @@ void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) { } } - /* the move command should not disturb focus */ - if (focused != initially_focused) + /* The move command should not disturb focus. con_exists is called because + * tree_move calls tree_flatten. */ + if (focused != initially_focused && con_exists(initially_focused)) { con_activate(initially_focused); + } // XXX: default reply for now, make this a better reply ysuccess(true); diff --git a/src/move.c b/src/move.c index 12277fce..77007c6b 100644 --- a/src/move.c +++ b/src/move.c @@ -237,8 +237,8 @@ static void move_to_output_directed(Con *con, direction_t direction) { /* force re-painting the indicators */ FREE(con->deco_render_params); - tree_flatten(croot); ipc_send_window_event("move", con); + tree_flatten(croot); ewmh_update_wm_desktop(); } @@ -384,7 +384,7 @@ end: /* force re-painting the indicators */ FREE(con->deco_render_params); - tree_flatten(croot); ipc_send_window_event("move", con); + tree_flatten(croot); ewmh_update_wm_desktop(); } diff --git a/testcases/t/309-crash-move-parent.t b/testcases/t/309-crash-move-parent.t new file mode 100644 index 00000000..eb58251b --- /dev/null +++ b/testcases/t/309-crash-move-parent.t @@ -0,0 +1,43 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • https://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • https://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • https://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Test that moving a container that is to be flattened does not crash i3 +# Ticket: #3831 +# Bug still in: 4.17-199-ga638e0408 +use i3test; + +cmp_tree( + msg => 'Moving a redundant container that is to be flattened does not crash i3', + layout_before => 'a H[V[b* c]]', # Not very attached to this result but + layout_after => 'H[a] b* c', # mainly checking if the crash happens. + cb => sub { + cmd 'focus parent, focus parent, move down'; + does_i3_live; + is(get_ws(focused_ws)->{layout}, 'splitv', 'Workspace changed to splitv'); + }); + +cmp_tree( + msg => "Same but create the redundant container with a 'split h' command", + layout_before => 'a V[b* c]', + layout_after => 'H[a] b* c', + cb => sub { + cmd 'focus parent, split h, focus parent, move down'; + does_i3_live; + is(get_ws(focused_ws)->{layout}, 'splitv', 'Workspace changed to splitv'); + }); + + +done_testing;