]> git.sur5r.net Git - i3/i3/blob - testcases/t/129-focus-after-close.t
testcases: drop open_window()s $x parameter, use global one instead
[i3/i3] / testcases / t / 129-focus-after-close.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Check if the focus is correctly restored after closing windows.
5 #
6 use i3test;
7 use List::Util qw(first);
8
9 my $i3 = i3(get_socket_path());
10
11 my $tmp = fresh_workspace;
12
13 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
14
15 my $first = open_empty_con($i3);
16 my $second = open_empty_con($i3);
17
18 cmd 'split v';
19
20 my ($nodes, $focus) = get_ws_content($tmp);
21
22 ok(!$nodes->[1]->{focused}, 'split container not focused');
23 cmd 'focus parent';
24 ($nodes, $focus) = get_ws_content($tmp);
25 ok($nodes->[1]->{focused}, 'split container focused after focus parent');
26
27 my $third = open_empty_con($i3);
28
29 isnt(get_focused($tmp), $second, 'different container focused');
30
31 # We have the following layout now (con is focused):
32 # .----------------.
33 # | split  |       |
34 # | .----. |  con  |
35 # | | cn | |       |
36 # | `----' |       |
37 # `----------------'
38
39 ##############################################################
40 # see if the focus goes down to $first (not to its split parent)
41 # when closing $second
42 ##############################################################
43
44 cmd 'kill';
45 # TODO: this testcase sometimes has different outcomes when the
46 # sleep is missing. why?
47 sleep 0.25;
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');
51
52 ##############################################################
53 # another case, using a slightly different layout (regression)
54 ##############################################################
55
56 $tmp = fresh_workspace;
57
58 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
59
60 cmd 'split v';
61 $first = open_empty_con($i3);
62 my $bottom = open_empty_con($i3);
63
64 cmd 'focus up';
65 cmd 'split h';
66 my $middle = open_empty_con($i3);
67 my $right = open_empty_con($i3);
68 cmd 'focus down';
69
70 # We have the following layout now (second is focused):
71 # .----------------------------.
72 # | .------------------------. |
73 # | | first | middle | right | |
74 # | `------------------------' |
75 # |----------------------------|
76 # |                            |
77 # |          second            |
78 # |                            |
79 # `----------------------------'
80
81 # Check if the focus is restored to $right when we close $second
82 cmd 'kill';
83
84 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
85
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');
89
90 ##############################################################
91 # check if focus is correct after closing an unfocused window
92 ##############################################################
93
94 $tmp = fresh_workspace;
95
96 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
97
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({ background_color => '#00ff00' });
103
104 cmd qq|[con_id="$middle"] focus|;
105 $win->destroy;
106
107 sleep 0.25;
108
109 is(get_focused($tmp), $middle, 'middle container focused');
110
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 ##############################################################
116
117 # TODO: add test code as soon as I can reproduce it
118
119 done_testing;