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 ##############################################################
47 ($nodes, $focus) = get_ws_content($tmp);
48 is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
49 ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused');
51 ##############################################################
52 # another case, using a slightly different layout (regression)
53 ##############################################################
55 $tmp = fresh_workspace;
57 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
60 $first = open_empty_con($i3);
61 my $bottom = open_empty_con($i3);
65 my $middle = open_empty_con($i3);
66 my $right = open_empty_con($i3);
69 # We have the following layout now (second is focused):
70 # .----------------------------.
71 # | .------------------------. |
72 # | | first | middle | right | |
73 # | `------------------------' |
74 # |----------------------------|
78 # `----------------------------'
80 # Check if the focus is restored to $right when we close $second
83 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
85 ($nodes, $focus) = get_ws_content($tmp);
86 my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
87 is($tr->{focused}, 1, 'top right container really has focus');
89 ##############################################################
90 # check if focus is correct after closing an unfocused window
91 ##############################################################
93 $tmp = fresh_workspace;
95 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
97 $first = open_empty_con($i3);
98 $middle = open_empty_con($i3);
99 # XXX: the $right empty con will be filled with the x11 window we are creating afterwards
100 $right = open_empty_con($i3);
101 my $win = open_window({ background_color => '#00ff00' });
103 cmd qq|[con_id="$middle"] focus|;
107 is(get_focused($tmp), $middle, 'middle container focused');
109 ##############################################################
110 # and now for something completely different:
111 # check if the pointer position is relevant when restoring focus
112 # (it should not be relevant, of course)
113 ##############################################################
115 # TODO: add test code as soon as I can reproduce it