From f70c3b168d6af594fc02fd257bf9dd810bdca894 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 14 Dec 2018 23:35:58 +0200 Subject: [PATCH 1/3] Update tree_close_internal documentation in tree.h After f90840337 --- include/tree.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/tree.h b/include/tree.h index 41a63036..12170f94 100644 --- a/include/tree.h +++ b/include/tree.h @@ -73,10 +73,6 @@ void tree_next(char way, orientation_t orientation); * The dont_kill_parent flag is specified when the function calls itself * recursively while deleting a containers children. * - * The force_set_focus flag is specified in the case of killing a floating - * window: tree_close_internal() will be invoked for the CT_FLOATINGCON (the parent - * container) and focus should be set there. - * */ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent); From dd708199ea2782b6ee05a7fb0ec041424a7c3a7b Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 14 Dec 2018 20:37:29 +0200 Subject: [PATCH 2/3] Fix: killing unfocused window shouldn't produce focus event --- src/x.c | 7 ++++++- testcases/t/219-ipc-window-focus.t | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/x.c b/src/x.c index 82c19d30..a2f2c39f 100644 --- a/src/x.c +++ b/src/x.c @@ -276,7 +276,12 @@ static void _x_con_kill(Con *con) { free(state); /* Invalidate focused_id to correctly focus new windows with the same ID */ - focused_id = last_focused = XCB_NONE; + if (con->frame.id == focused_id) { + focused_id = XCB_NONE; + } + if (con->frame.id == last_focused) { + last_focused = XCB_NONE; + } } /* diff --git a/testcases/t/219-ipc-window-focus.t b/testcases/t/219-ipc-window-focus.t index b1c8ba18..afb1bfbc 100644 --- a/testcases/t/219-ipc-window-focus.t +++ b/testcases/t/219-ipc-window-focus.t @@ -44,11 +44,26 @@ sub focus_subtest { is($events[0]->{container}->{name}, $name, "$name focused"); } +sub kill_subtest { + my ($cmd, $name) = @_; + + my $focus = AnyEvent->condvar; + + my @events = events_for( + sub { cmd $cmd }, + 'window'); + + is(scalar @events, 1, 'Received 1 event'); + is($events[0]->{change}, 'close', 'Close event received'); + is($events[0]->{container}->{name}, $name, "$name closed"); +} + subtest 'focus left (1)', \&focus_subtest, 'focus left', $win1->name; subtest 'focus left (2)', \&focus_subtest, 'focus left', $win0->name; subtest 'focus right (1)', \&focus_subtest, 'focus right', $win1->name; subtest 'focus right (2)', \&focus_subtest, 'focus right', $win2->name; subtest 'focus right (3)', \&focus_subtest, 'focus right', $win0->name; subtest 'focus left', \&focus_subtest, 'focus left', $win2->name; +subtest 'kill doesn\'t produce focus event', \&kill_subtest, '[id=' . $win1->id . '] kill', $win1->name; done_testing; From fb1ae61d1c25e0f61c23cac82f2af511c336c6bf Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 14 Dec 2018 20:39:34 +0200 Subject: [PATCH 3/3] Invalidate last_focused when focusing the EWMH support window Fixes #3562 --- src/x.c | 1 + testcases/t/219-ipc-window-focus.t | 38 +++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/x.c b/src/x.c index a2f2c39f..f643a9b3 100644 --- a/src/x.c +++ b/src/x.c @@ -1325,6 +1325,7 @@ void x_push_changes(Con *con) { change_ewmh_focus(XCB_WINDOW_NONE, last_focused); focused_id = ewmh_window; + last_focused = XCB_NONE; } xcb_flush(conn); diff --git a/testcases/t/219-ipc-window-focus.t b/testcases/t/219-ipc-window-focus.t index afb1bfbc..696fc7b2 100644 --- a/testcases/t/219-ipc-window-focus.t +++ b/testcases/t/219-ipc-window-focus.t @@ -14,14 +14,20 @@ # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf # (unless you are already familiar with Perl) -use i3test; +use i3test i3_config => < 0); my $win0 = open_window; my $win1 = open_window; my $win2 = open_window; @@ -66,4 +72,30 @@ subtest 'focus right (3)', \&focus_subtest, 'focus right', $win0->name; subtest 'focus left', \&focus_subtest, 'focus left', $win2->name; subtest 'kill doesn\'t produce focus event', \&kill_subtest, '[id=' . $win1->id . '] kill', $win1->name; +# See issue #3562. We need to switch to an existing workspace on the second +# output to trigger the bug. +cmd 'workspace X'; +subtest 'workspace focus', \&focus_subtest, "workspace $ws", $win2->name; + +sub scratchpad_subtest { + my ($cmd, $name) = @_; + + my $focus = AnyEvent->condvar; + + my @events = events_for( + sub { cmd $cmd }, + 'window'); + + is(scalar @events, 2, 'Received 2 events'); + is($events[0]->{change}, 'move', 'Move event received'); + is($events[0]->{container}->{nodes}->[0]->{name}, $name, "$name moved"); + is($events[1]->{change}, 'focus', 'Focus event received'); + is($events[1]->{container}->{name}, $name, "$name focused"); +} + +fresh_workspace; +my $win = open_window; +cmd 'move scratchpad'; +subtest 'scratchpad', \&scratchpad_subtest, '[id=' . $win->id . '] scratchpad show', $win->name; + done_testing;