]> git.sur5r.net Git - i3/i3/blob - testcases/t/202-scratchpad-criteria.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 202-scratchpad-criteria.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 # Verifies that using criteria to address scratchpad windows works.
18 use i3test;
19
20 #####################################################################
21 # Verify that using scratchpad show with criteria works as expected:
22 # - When matching a scratchpad window which is visible,
23 #   it should hide it.
24 # - When matching a scratchpad window which is on __i3_scratch,
25 #   it should show it.
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 ######################################################################
30
31 my $tmp = fresh_workspace;
32
33 my $third_window = open_window(name => 'scratch-match');
34 cmd 'move scratchpad';
35
36 #####################################################################
37 # Verify that using 'scratchpad show' without any matching windows is
38 # a no-op.
39 #####################################################################
40 my $old_focus = get_focused($tmp);
41
42 cmd '[title="nomatch"] scratchpad show';
43
44 is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
45
46 #####################################################################
47 # Verify that we can use criteria to show a scratchpad window.
48 #####################################################################
49 cmd '[title="scratch-match"] scratchpad show';
50
51 my $scratch_focus = get_focused($tmp);
52 isnt($scratch_focus, $old_focus, 'matching criteria works');
53
54 cmd '[title="scratch-match"] scratchpad show';
55
56 isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
57 is(get_focused($tmp), $old_focus, 'focus restored');
58
59
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');
65 cmd "workspace $tmp";
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');
69
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';
77         cmd 'kill';
78     }
79 }
80
81 #Start from an empty fresh workspace
82 my $empty_ws = fresh_workspace;
83 cmd "workspace $empty_ws";
84
85 my $no_focused = get_focused($empty_ws);
86 cmd '[title="nothingmatchthistitle"] scratchpad show';
87 #Check nothing match
88 is(get_focused($empty_ws), $no_focused, "no window to focus on");
89
90 clear_scratchpad;
91
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");
98
99 #Switching workspace
100 my $empty_ws2 = fresh_workspace;
101 cmd "workspace $empty_ws2";
102 open_window(name => "my-second-scratch-window");
103
104 my $w2_focus = get_focused($empty_ws2);
105 cmd 'move scratchpad';
106 cmd '[title="my-second-scratch-window"] scratchpad show';
107
108 #Check we got the correct window
109 is(get_focused($empty_ws2), $w2_focus, "focus is on second window");
110
111 #####################################################################
112 # Verify that 'scratchpad show' correctly hide multiple scratchpad
113 # windows
114 #####################################################################
115 clear_scratchpad;
116
117 sub check_floating {
118     my($rws, $n) = @_;
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");
122 }
123
124 my $empty_ws3 = fresh_workspace;
125 cmd "workspace $empty_ws3";
126
127 check_floating($empty_ws3, 0);
128
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);
135 #Showing both
136 cmd '[title="toggle-"] scratchpad show';
137
138 check_floating($empty_ws3, 2);
139
140 #Hiding both
141 cmd '[title="toggle-"] scratchpad show';
142 check_floating($empty_ws3, 0);
143
144 #Showing both again
145 cmd '[title="toggle-"] scratchpad show';
146 check_floating($empty_ws3, 2);
147
148
149 #Hiding one
150 cmd 'scratchpad show';
151 check_floating($empty_ws3, 1);
152
153 #Hiding the last
154 cmd 'scratchpad show';
155 check_floating($empty_ws3, 0);
156
157 done_testing;