2 # vim:ts=4:sw=4:expandtab
4 # Check if the focus is correctly restored after closing windows.
8 use List::Util qw(first);
10 my $x = X11::XCB::Connection->new;
12 my $i3 = i3("/tmp/nestedcons");
14 my $tmp = fresh_workspace;
16 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
18 my $first = open_empty_con($i3);
19 my $second = open_empty_con($i3);
23 my ($nodes, $focus) = get_ws_content($tmp);
25 is($nodes->[1]->{focused}, 0, 'split container not focused');
27 ($nodes, $focus) = get_ws_content($tmp);
28 is($nodes->[1]->{focused}, 1, 'split container focused after focus parent');
30 my $third = open_empty_con($i3);
32 isnt(get_focused($tmp), $second, 'different container focused');
34 # We have the following layout now (con is focused):
42 ##############################################################
43 # see if the focus goes down to $first (not to its split parent)
44 # when closing $second
45 ##############################################################
48 # TODO: this testcase sometimes has different outcomes when the
49 # sleep is missing. why?
51 ($nodes, $focus) = get_ws_content($tmp);
52 is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
53 is($nodes->[1]->{nodes}->[0]->{focused}, 1, 'second container focused');
55 ##############################################################
56 # another case, using a slightly different layout (regression)
57 ##############################################################
59 $tmp = fresh_workspace;
61 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
64 $first = open_empty_con($i3);
65 my $bottom = open_empty_con($i3);
69 my $middle = open_empty_con($i3);
70 my $right = open_empty_con($i3);
73 # We have the following layout now (second is focused):
74 # .----------------------------.
75 # | .------------------------. |
76 # | | first | middle | right | |
77 # | `------------------------' |
78 # |----------------------------|
82 # `----------------------------'
84 # Check if the focus is restored to $right when we close $second
87 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
89 ($nodes, $focus) = get_ws_content($tmp);
90 my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
91 is($tr->{focused}, 1, 'top right container really has focus');
93 ##############################################################
94 # check if focus is correct after closing an unfocused window
95 ##############################################################
97 $tmp = fresh_workspace;
99 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
101 $first = open_empty_con($i3);
102 $middle = open_empty_con($i3);
103 # XXX: the $right empty con will be filled with the x11 window we are creating afterwards
104 $right = open_empty_con($i3);
105 my $win = open_standard_window($x, '#00ff00');
107 cmd qq|[con_id="$middle"] focus|;
112 is(get_focused($tmp), $middle, 'middle container focused');
114 ##############################################################
115 # and now for something completely different:
116 # check if the pointer position is relevant when restoring focus
117 # (it should not be relevant, of course)
118 ##############################################################
120 # TODO: add test code as soon as I can reproduce it