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 use i3test i3_autostart => 0;
18 use List::Util qw(first);
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24 force_display_urgency_hint 0ms
26 my $pid = launch_with_config($config);
28 my $tmp = fresh_workspace;
30 #####################################################################
31 # Create two windows and put them in stacking mode
32 #####################################################################
36 my $top = open_window;
37 my $bottom = open_window;
39 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
40 is(@urgent, 0, 'no window got the urgent flag');
42 # cmd 'layout stacking';
44 #####################################################################
45 # Add the urgency hint, switch to a different workspace and back again
46 #####################################################################
47 $top->add_hint('urgency');
50 my @content = @{get_ws_content($tmp)};
51 @urgent = grep { $_->{urgent} } @content;
52 my $top_info = first { $_->{window} == $top->id } @content;
53 my $bottom_info = first { $_->{window} == $bottom->id } @content;
55 ok($top_info->{urgent}, 'top window is marked urgent');
56 ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
57 is(@urgent, 1, 'exactly one window got the urgent flag');
59 cmd '[id="' . $top->id . '"] focus';
61 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
62 is(@urgent, 0, 'no window got the urgent flag after focusing');
64 $top->add_hint('urgency');
67 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
68 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
70 #####################################################################
71 # Check if the workspace urgency hint gets set/cleared correctly
72 #####################################################################
74 my $ws = get_ws($tmp);
75 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
77 my $otmp = fresh_workspace;
79 $top->add_hint('urgency');
83 ok($ws->{urgent}, 'urgent flag set on workspace');
88 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
90 ################################################################################
91 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
92 ################################################################################
94 # Go to a new workspace, open a different window, verify focus is on it.
95 $otmp = fresh_workspace;
96 my $different_window = open_window;
97 is($x->input_focus, $different_window->id, 'new window focused');
99 # Add the urgency hint on the other window.
100 $top->add_hint('urgency');
103 # Now try to switch to that window and see if focus changes.
104 cmd '[urgent=latest] focus';
105 isnt($x->input_focus, $different_window->id, 'window no longer focused');
106 is($x->input_focus, $top->id, 'urgent window focused');
108 ################################################################################
109 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
110 # (verify that it works in the correct order).
111 ################################################################################
113 cmd "workspace $otmp";
114 is($x->input_focus, $different_window->id, 'new window focused again');
116 $top->add_hint('urgency');
119 $bottom->add_hint('urgency');
122 cmd '[urgent=latest] focus';
123 is($x->input_focus, $bottom->id, 'latest urgent window focused');
124 $bottom->delete_hint('urgency');
127 cmd '[urgent=latest] focus';
128 is($x->input_focus, $top->id, 'second urgent window focused');
129 $top->delete_hint('urgency');
132 ################################################################################
133 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
134 # (verify that it works in the correct order).
135 ################################################################################
137 cmd "workspace $otmp";
138 is($x->input_focus, $different_window->id, 'new window focused again');
140 $top->add_hint('urgency');
143 $bottom->add_hint('urgency');
146 cmd '[urgent=oldest] focus';
147 is($x->input_focus, $top->id, 'oldest urgent window focused');
148 $top->delete_hint('urgency');
151 cmd '[urgent=oldest] focus';
152 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
153 $bottom->delete_hint('urgency');
156 ################################################################################
157 # Check if urgent flag gets propagated to parent containers
158 ################################################################################
167 my @children = (@{$con->{nodes}}, @{$con->{floating_nodes}});
168 my $urgent = grep { $_->{urgent} } @children;
169 $urgent += count_urgent($_) for @children;
173 $tmp = fresh_workspace;
175 my $win1 = open_window;
176 my $win2 = open_window;
177 cmd 'layout stacked';
178 cmd 'split vertical';
179 my $win3 = open_window;
180 my $win4 = open_window;
181 cmd 'split horizontal' ;
182 my $win5 = open_window;
183 my $win6 = open_window;
188 my $urgent = count_urgent(get_ws($tmp));
189 is($urgent, 0, 'no window got the urgent flag');
191 cmd '[id="' . $win2->id . '"] focus';
193 $win5->add_hint('urgency');
194 $win6->add_hint('urgency');
197 # we should have 5 urgent cons. win5, win6 and their 3 split parents.
199 $urgent = count_urgent(get_ws($tmp));
200 is($urgent, 5, '2 windows and 3 split containers got the urgent flag');
202 cmd '[id="' . $win5->id . '"] focus';
205 # now win5 and still the split parents should be urgent.
206 $urgent = count_urgent(get_ws($tmp));
207 is($urgent, 4, '1 window and 3 split containers got the urgent flag');
209 cmd '[id="' . $win6->id . '"] focus';
212 # now now window should be urgent.
213 $urgent = count_urgent(get_ws($tmp));
214 is($urgent, 0, 'All urgent flags got cleared');
216 ################################################################################
217 # Regression test: Check that urgent floating containers work properly (ticket
219 ################################################################################
221 $tmp = fresh_workspace;
222 my $floating_win = open_floating_window;
227 $floating_win->add_hint('urgency');
230 cmd "workspace $tmp";
234 ###############################################################################
235 # Check if the urgency hint is still set when the urgent window is killed
236 ###############################################################################
238 my $ws1 = fresh_workspace;
239 my $ws2 = fresh_workspace;
240 cmd "workspace $ws1";
241 my $w1 = open_window;
242 my $w2 = open_window;
243 cmd "workspace $ws2";
245 $w1->add_hint('urgency');
247 cmd '[id="' . $w1->id . '"] kill';
249 my $w = get_ws($ws1);
250 is($w->{urgent}, 0, 'Urgent flag no longer set after killing the window ' .
251 'from another workspace');
254 exit_gracefully($pid);