]> git.sur5r.net Git - i3/i3/blob - testcases/t/176-workspace-baf.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 176-workspace-baf.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 # Checks if the 'workspace back_and_forth' command and the
18 # 'workspace_auto_back_and_forth' config directive work correctly.
19 #
20
21 use i3test i3_autostart => 0;
22
23 my $config = <<EOT;
24 # i3 config file (v4)
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
26 EOT
27
28 my $pid = launch_with_config($config);
29
30 my $first_ws = fresh_workspace;
31 ok(get_ws($first_ws)->{focused}, 'first workspace focused');
32
33 my $second_ws = fresh_workspace;
34 ok(get_ws($second_ws)->{focused}, 'second workspace focused');
35
36 my $third_ws = fresh_workspace;
37 ok(get_ws($third_ws)->{focused}, 'third workspace focused');
38
39 cmd 'workspace back_and_forth';
40 ok(get_ws($second_ws)->{focused}, 'second workspace focused');
41
42 #####################################################################
43 # test that without workspace_auto_back_and_forth switching to the same
44 # workspace that is currently focused is a no-op
45 #####################################################################
46
47 cmd qq|workspace "$second_ws"|;
48 ok(get_ws($second_ws)->{focused}, 'second workspace still focused');
49
50 ################################################################################
51 # verify that 'move workspace back_and_forth' works as expected
52 ################################################################################
53
54 cmd qq|workspace "$first_ws"|;
55 my $first_win = open_window;
56
57 cmd qq|workspace "$second_ws"|;
58 my $second_win = open_window;
59
60 is(@{get_ws_content($first_ws)}, 1, 'one container on ws 1 before moving');
61 cmd 'move workspace back_and_forth';
62 is(@{get_ws_content($first_ws)}, 2, 'two containers on ws 1 before moving');
63
64 my $third_win = open_window;
65
66 ################################################################################
67 # verify that moving to the current ws is a no-op without
68 # workspace_auto_back_and_forth.
69 ################################################################################
70
71 cmd qq|workspace "$first_ws"|;
72
73 is(@{get_ws_content($second_ws)}, 1, 'one container on ws 2 before moving');
74 cmd qq|move workspace "$first_ws"|;
75 is(@{get_ws_content($second_ws)}, 1, 'still one container');
76
77 exit_gracefully($pid);
78
79 #####################################################################
80 # the same test, but with workspace_auto_back_and_forth
81 #####################################################################
82
83 $config = <<EOT;
84 # i3 config file (v4)
85 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
86 workspace_auto_back_and_forth yes
87 EOT
88
89 $pid = launch_with_config($config);
90
91 $first_ws = fresh_workspace;
92 ok(get_ws($first_ws)->{focused}, 'first workspace focused');
93
94 $second_ws = fresh_workspace;
95 ok(get_ws($second_ws)->{focused}, 'second workspace focused');
96
97 $third_ws = fresh_workspace;
98 ok(get_ws($third_ws)->{focused}, 'third workspace focused');
99
100 cmd qq|workspace "$third_ws"|;
101 ok(get_ws($second_ws)->{focused}, 'second workspace focused');
102 $first_win = open_window;
103
104 ################################################################################
105 # verify that moving to the current ws moves to the previous one with
106 # workspace_auto_back_and_forth.
107 ################################################################################
108
109 cmd qq|workspace "$first_ws"|;
110 $second_win = open_window;
111
112 is(@{get_ws_content($second_ws)}, 1, 'one container on ws 2 before moving');
113 cmd qq|move workspace "$first_ws"|;
114 is(@{get_ws_content($second_ws)}, 2, 'two containers on ws 2');
115
116 ################################################################################
117 # Now see if "workspace number <number>" also works as expected with
118 # workspace_auto_back_and_forth enabled.
119 ################################################################################
120
121 cmd 'workspace number 5';
122 ok(get_ws('5')->{focused}, 'workspace 5 focused');
123 # ensure it stays open
124 cmd 'open';
125
126 cmd 'workspace number 6';
127 ok(get_ws('6')->{focused}, 'workspace 6 focused');
128 # ensure it stays open
129 cmd 'open';
130
131 cmd 'workspace number 6';
132 is(focused_ws, '5', 'workspace 5 focused again');
133
134 ################################################################################
135 # Rename the workspaces and see if workspace number still works with BAF.
136 ################################################################################
137
138 cmd 'rename workspace 5 to 5: foo';
139 cmd 'rename workspace 6 to 6: baz';
140
141 is(focused_ws, '5: foo', 'workspace 5 still focused');
142
143 cmd 'workspace number 6';
144 is(focused_ws, '6: baz', 'workspace 6 now focused');
145
146 cmd 'workspace number 6';
147 is(focused_ws, '5: foo', 'workspace 5 focused again');
148
149 ################################################################################
150 # Place a window in the scratchpad, see if BAF works after showing the
151 # scratchpad window.
152 ################################################################################
153
154 my $scratchwin = open_window;
155 cmd 'move scratchpad';
156
157 # show scratchpad window
158 cmd 'scratchpad show';
159
160 # hide scratchpad window
161 cmd 'scratchpad show';
162
163 cmd 'workspace back_and_forth';
164 is(focused_ws, '6: baz', 'workspace 6 now focused');
165
166 exit_gracefully($pid);
167
168 done_testing;