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 #####################################################################
21 # Verify that using scratchpad show with criteria works as expected:
22 # - When matching a scratchpad window which is visible,
24 # - When matching a scratchpad window which is on __i3_scratch,
26 # - When matching a non-scratchpad window, it should be a no-op.
27 # - When matching a scratchpad window,
28 # non-matching windows shouldn't appear
29 ######################################################################
31 my $tmp = fresh_workspace;
33 my $third_window = open_window(name => 'scratch-match');
34 cmd 'move scratchpad';
36 #####################################################################
37 # Verify that using 'scratchpad show' without any matching windows is
39 #####################################################################
40 my $old_focus = get_focused($tmp);
42 cmd '[title="nomatch"] scratchpad show';
44 is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
46 #####################################################################
47 # Verify that we can use criteria to show a scratchpad window.
48 #####################################################################
49 cmd '[title="scratch-match"] scratchpad show';
51 my $scratch_focus = get_focused($tmp);
52 isnt($scratch_focus, $old_focus, 'matching criteria works');
54 cmd '[title="scratch-match"] scratchpad show';
56 isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
57 is(get_focused($tmp), $old_focus, 'focus restored');
60 #####################################################################
61 # Verify that we cannot use criteria to show a non-scratchpad window.
62 #####################################################################
63 my $tmp2 = fresh_workspace;
64 my $non_scratch_window = open_window(name => 'non-scratch');
66 is(get_focused($tmp), $old_focus, 'focus still ok');
67 cmd '[title="non-scratch"] scratchpad show';
68 is(get_focused($tmp), $old_focus, 'focus unchanged');
70 #####################################################################
71 # Verify that non-matching windows doesn't appear
72 #####################################################################
73 # Subroutine to clear scratchpad
74 sub clear_scratchpad {
75 while (scalar @{get_ws('__i3_scratch')->{floating_nodes}}) {
76 cmd 'scratchpad show';
81 #Start from an empty fresh workspace
82 my $empty_ws = fresh_workspace;
83 cmd "workspace $empty_ws";
85 my $no_focused = get_focused($empty_ws);
86 cmd '[title="nothingmatchthistitle"] scratchpad show';
88 is(get_focused($empty_ws), $no_focused, "no window to focus on");
92 open_window(name => "my-scratch-window");
93 my $w1_focus = get_focused($empty_ws);
94 cmd 'move scratchpad';
95 cmd '[title="my-scratch-window"] scratchpad show';
96 #Check we created and shown a scratchpad window
97 is(get_focused($empty_ws), $w1_focus, "focus on scratchpad window");
100 my $empty_ws2 = fresh_workspace;
101 cmd "workspace $empty_ws2";
102 open_window(name => "my-second-scratch-window");
104 my $w2_focus = get_focused($empty_ws2);
105 cmd 'move scratchpad';
106 cmd '[title="my-second-scratch-window"] scratchpad show';
108 #Check we got the correct window
109 is(get_focused($empty_ws2), $w2_focus, "focus is on second window");
111 #####################################################################
112 # Verify that 'scratchpad show' correctly hide multiple scratchpad
114 #####################################################################
119 my $ws = get_ws($rws);
120 is(scalar @{$ws->{nodes}}, 0, 'no windows on ws');
121 is(scalar @{$ws->{floating_nodes}}, $n, "$n floating windows on ws");
124 my $empty_ws3 = fresh_workspace;
125 cmd "workspace $empty_ws3";
127 check_floating($empty_ws3, 0);
129 #Creating two scratchpad windows
130 open_window(name => "toggle-1");
131 cmd 'move scratchpad';
132 open_window(name => "toggle-2");
133 cmd 'move scratchpad';
134 check_floating($empty_ws3, 0);
136 cmd '[title="toggle-"] scratchpad show';
138 check_floating($empty_ws3, 2);
141 cmd '[title="toggle-"] scratchpad show';
142 check_floating($empty_ws3, 0);
145 cmd '[title="toggle-"] scratchpad show';
146 check_floating($empty_ws3, 2);
150 cmd 'scratchpad show';
151 check_floating($empty_ws3, 1);
154 cmd 'scratchpad show';
155 check_floating($empty_ws3, 0);