]> git.sur5r.net Git - i3/i3/blob - testcases/t/129-focus-after-close.t
Merge branch 'master' into next
[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 sync_with_i3;
46
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');
50
51 ##############################################################
52 # another case, using a slightly different layout (regression)
53 ##############################################################
54
55 $tmp = fresh_workspace;
56
57 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
58
59 cmd 'split v';
60 $first = open_empty_con($i3);
61 my $bottom = open_empty_con($i3);
62
63 cmd 'focus up';
64 cmd 'split h';
65 my $middle = open_empty_con($i3);
66 my $right = open_empty_con($i3);
67 cmd 'focus down';
68
69 # We have the following layout now (second is focused):
70 # .----------------------------.
71 # | .------------------------. |
72 # | | first | middle | right | |
73 # | `------------------------' |
74 # |----------------------------|
75 # |                            |
76 # |          second            |
77 # |                            |
78 # `----------------------------'
79
80 # Check if the focus is restored to $right when we close $second
81 cmd 'kill';
82
83 is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
84
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');
88
89 ##############################################################
90 # check if focus is correct after closing an unfocused window
91 ##############################################################
92
93 $tmp = fresh_workspace;
94
95 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
96
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' });
102
103 cmd qq|[con_id="$middle"] focus|;
104 $win->destroy;
105 sync_with_i3;
106
107 is(get_focused($tmp), $middle, 'middle container focused');
108
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 ##############################################################
114
115 # TODO: add test code as soon as I can reproduce it
116
117 done_testing;