2 # vim:ts=4:sw=4:expandtab
4 # Check if the focus is correctly restored after closing windows.
7 use List::Util qw(first);
9 my $i3 = i3(get_socket_path());
11 my $tmp = fresh_workspace;
13 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
15 my $first = open_empty_con($i3);
16 my $second = open_empty_con($i3);
20 my ($nodes, $focus) = get_ws_content($tmp);
22 ok(!$nodes->[1]->{focused}, 'split container not focused');
24 ($nodes, $focus) = get_ws_content($tmp);
25 ok($nodes->[1]->{focused}, 'split container focused after focus parent');
27 my $third = open_empty_con($i3);
29 isnt(get_focused($tmp), $second, 'different container focused');
31 # We have the following layout now (con is focused):
39 ##############################################################
40 # see if the focus goes down to $first (not to its split parent)
41 # when closing $second
42 ##############################################################
45 # TODO: this testcase sometimes has different outcomes when the
46 # sleep is missing. why?
48 ($nodes, $focus) = get_ws_content($tmp);
49 is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
50 ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused');
52 ##############################################################
53 # another case, using a slightly different layout (regression)
54 ##############################################################
56 $tmp = fresh_workspace;
58 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
61 $first = open_empty_con($i3);
62 my $bottom = open_empty_con($i3);
66 my $middle = open_empty_con($i3);
67 my $right = open_empty_con($i3);
70 # We have the following layout now (second is focused):
71 # .----------------------------.
72 # | .------------------------. |
73 # | | first | middle | right | |
74 # | `------------------------' |
75 # |----------------------------|
79 # `----------------------------'
81 # Check if the focus is restored to $right when we close $second
84 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
86 ($nodes, $focus) = get_ws_content($tmp);
87 my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
88 is($tr->{focused}, 1, 'top right container really has focus');
90 ##############################################################
91 # check if focus is correct after closing an unfocused window
92 ##############################################################
94 $tmp = fresh_workspace;
96 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
98 $first = open_empty_con($i3);
99 $middle = open_empty_con($i3);
100 # XXX: the $right empty con will be filled with the x11 window we are creating afterwards
101 $right = open_empty_con($i3);
102 my $win = open_window($x, { background_color => '#00ff00' });
104 cmd qq|[con_id="$middle"] focus|;
109 is(get_focused($tmp), $middle, 'middle container focused');
111 ##############################################################
112 # and now for something completely different:
113 # check if the pointer position is relevant when restoring focus
114 # (it should not be relevant, of course)
115 ##############################################################
117 # TODO: add test code as soon as I can reproduce it