2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Verifies that using criteria to address scratchpad windows works.
20 my $i3 = i3(get_socket_path());
22 #####################################################################
23 # Verify that using scratchpad show with criteria works as expected:
24 # - When matching a scratchpad window which is visible,
26 # - When matching a scratchpad window which is on __i3_scratch,
28 # - When matching a non-scratchpad window, it should be a no-op.
29 # - When matching a scratchpad window,
30 # non-matching windows shouldn't appear
31 ######################################################################
33 my $tmp = fresh_workspace;
35 my $third_window = open_window(name => 'scratch-match');
36 cmd 'move scratchpad';
38 #####################################################################
39 # Verify that using 'scratchpad show' without any matching windows is
41 #####################################################################
42 my $old_focus = get_focused($tmp);
44 cmd '[title="nomatch"] scratchpad show';
46 is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
48 #####################################################################
49 # Verify that we can use criteria to show a scratchpad window.
50 #####################################################################
51 cmd '[title="scratch-match"] scratchpad show';
53 my $scratch_focus = get_focused($tmp);
54 isnt($scratch_focus, $old_focus, 'matching criteria works');
56 # Check that the window was centered and resized too.
57 my $tree = $i3->get_tree->recv;
58 my $ws = get_ws($tmp);
59 my $scratchrect = $ws->{floating_nodes}->[0]->{rect};
60 my $output = $tree->{nodes}->[1];
61 my $outputrect = $output->{rect};
63 is($scratchrect->{width}, $outputrect->{width} * 0.5, 'scratch width is 50%');
64 is($scratchrect->{height}, $outputrect->{height} * 0.75, 'scratch height is 75%');
66 ($outputrect->{width} / 2) - ($scratchrect->{width} / 2),
67 'scratch window centered horizontally');
69 ($outputrect->{height} / 2 ) - ($scratchrect->{height} / 2),
70 'scratch window centered vertically');
72 cmd '[title="scratch-match"] scratchpad show';
74 isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
75 is(get_focused($tmp), $old_focus, 'focus restored');
78 #####################################################################
79 # Verify that we cannot use criteria to show a non-scratchpad window.
80 #####################################################################
81 my $tmp2 = fresh_workspace;
82 my $non_scratch_window = open_window(name => 'non-scratch');
84 is(get_focused($tmp), $old_focus, 'focus still ok');
85 cmd '[title="non-scratch"] scratchpad show';
86 is(get_focused($tmp), $old_focus, 'focus unchanged');
88 #####################################################################
89 # Verify that non-matching windows doesn't appear
90 #####################################################################
91 # Subroutine to clear scratchpad
92 sub clear_scratchpad {
93 while (scalar @{get_ws('__i3_scratch')->{floating_nodes}}) {
94 cmd 'scratchpad show';
99 #Start from an empty fresh workspace
100 my $empty_ws = fresh_workspace;
101 cmd "workspace $empty_ws";
103 my $no_focused = get_focused($empty_ws);
104 cmd '[title="nothingmatchthistitle"] scratchpad show';
106 is(get_focused($empty_ws), $no_focused, "no window to focus on");
110 open_window(name => "my-scratch-window");
111 my $w1_focus = get_focused($empty_ws);
112 cmd 'move scratchpad';
113 cmd '[title="my-scratch-window"] scratchpad show';
114 #Check we created and shown a scratchpad window
115 is(get_focused($empty_ws), $w1_focus, "focus on scratchpad window");
118 my $empty_ws2 = fresh_workspace;
119 cmd "workspace $empty_ws2";
120 open_window(name => "my-second-scratch-window");
122 my $w2_focus = get_focused($empty_ws2);
123 cmd 'move scratchpad';
124 cmd '[title="my-second-scratch-window"] scratchpad show';
126 #Check we got the correct window
127 is(get_focused($empty_ws2), $w2_focus, "focus is on second window");
129 #####################################################################
130 # Verify that 'scratchpad show' correctly hide multiple scratchpad
132 #####################################################################
137 my $ws = get_ws($rws);
138 is(scalar @{$ws->{nodes}}, 0, 'no windows on ws');
139 is(scalar @{$ws->{floating_nodes}}, $n, "$n floating windows on ws");
142 my $empty_ws3 = fresh_workspace;
143 cmd "workspace $empty_ws3";
145 check_floating($empty_ws3, 0);
147 #Creating two scratchpad windows
148 open_window(name => "toggle-1");
149 cmd 'move scratchpad';
150 open_window(name => "toggle-2");
151 cmd 'move scratchpad';
152 check_floating($empty_ws3, 0);
154 cmd '[title="toggle-"] scratchpad show';
156 check_floating($empty_ws3, 2);
159 cmd '[title="toggle-"] scratchpad show';
160 check_floating($empty_ws3, 0);
163 cmd '[title="toggle-"] scratchpad show';
164 check_floating($empty_ws3, 2);
168 cmd 'scratchpad show';
169 check_floating($empty_ws3, 1);
172 cmd 'scratchpad show';
173 check_floating($empty_ws3, 0);