]> git.sur5r.net Git - i3/i3/blob - testcases/t/294-focus-order.t
41c0bf07009f43ed073a9b466b28526503110e0c
[i3/i3] / testcases / t / 294-focus-order.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Verify that the corrent focus stack order is preserved after various
18 # operations.
19 use i3test;
20
21 sub kill_and_confirm_focus {
22     my $focus = shift;
23     my $msg = shift;
24     cmd "kill";
25     sync_with_i3;
26     is($x->input_focus, $focus, $msg);
27 }
28
29 my @windows;
30
31 sub focus_windows {
32     for (my $i = $#windows; $i >= 0; $i--) {
33         cmd '[id=' . $windows[$i]->id . '] focus';
34     }
35 }
36
37 sub confirm_focus {
38     my $msg = shift;
39     sync_with_i3;
40     is($x->input_focus, $windows[0]->id, $msg . ': window 0 focused');
41     foreach my $i (1 .. $#windows) {
42         kill_and_confirm_focus($windows[$i]->id, "$msg: window $i focused");
43     }
44     cmd 'kill';
45     @windows = ();
46 }
47
48 #####################################################################
49 # Open 5 windows, focus them in a custom order and then change to
50 # tabbed layout. The focus order should be preserved.
51 #####################################################################
52
53 fresh_workspace;
54
55 $windows[3] = open_window;
56 $windows[1] = open_window;
57 $windows[0] = open_window;
58 $windows[2] = open_window;
59 $windows[4] = open_window;
60 focus_windows;
61
62 cmd 'layout tabbed';
63 confirm_focus('tabbed');
64
65 #####################################################################
66 # Same as above but with stacked.
67 #####################################################################
68
69 fresh_workspace;
70
71 $windows[3] = open_window;
72 $windows[1] = open_window;
73 $windows[0] = open_window;
74 $windows[2] = open_window;
75 $windows[4] = open_window;
76 focus_windows;
77
78 cmd 'layout stacked';
79 confirm_focus('stacked');
80
81 #####################################################################
82 # Open 4 windows horizontally, move the last one down. The focus
83 # order should be preserved.
84 #####################################################################
85
86 fresh_workspace;
87 $windows[3] = open_window;
88 $windows[2] = open_window;
89 $windows[1] = open_window;
90 $windows[0] = open_window;
91
92 cmd 'move down';
93 confirm_focus('split-h + move');
94
95 #####################################################################
96 # Same as above but with a vertical split.
97 #####################################################################
98
99 fresh_workspace;
100 $windows[3] = open_window;
101 cmd 'split v';
102 $windows[2] = open_window;
103 $windows[1] = open_window;
104 $windows[0] = open_window;
105
106 cmd 'move left';
107 confirm_focus('split-v + move');
108
109 done_testing;