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);
20 my $_NET_WM_STATE_REMOVE = 0;
21 my $_NET_WM_STATE_ADD = 1;
22 my $_NET_WM_STATE_TOGGLE = 2;
25 my ($win, $urgent_flag, $type) = @_;
27 # Because X11::XCB does not keep track of clearing the urgency hint
28 # when receiving focus, we just delete it in all cases and then re-set
30 $win->delete_hint('urgency');
31 $win->add_hint('urgency') if ($urgent_flag);
32 } elsif ($type == 2) {
33 my $msg = pack "CCSLLLLLL",
34 X11::XCB::CLIENT_MESSAGE, # response_type
38 $x->atom(name => '_NET_WM_STATE')->id, # message type
39 ($urgent_flag ? $_NET_WM_STATE_ADD : $_NET_WM_STATE_REMOVE), # data32[0]
40 $x->atom(name => '_NET_WM_STATE_DEMANDS_ATTENTION')->id, # data32[1]
45 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
51 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
53 force_display_urgency_hint 0ms
57 for ($type = 1; $type <= 2; $type++) {
58 my $pid = launch_with_config($config);
59 my $tmp = fresh_workspace;
61 #####################################################################
62 # Create two windows and put them in stacking mode
63 #####################################################################
67 my $top = open_window;
68 my $bottom = open_window;
70 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
71 is(@urgent, 0, 'no window got the urgent flag');
73 # cmd 'layout stacking';
75 #####################################################################
76 # Add the urgency hint, switch to a different workspace and back again
77 #####################################################################
78 set_urgency($top, 1, $type);
81 my @content = @{get_ws_content($tmp)};
82 @urgent = grep { $_->{urgent} } @content;
83 my $top_info = first { $_->{window} == $top->id } @content;
84 my $bottom_info = first { $_->{window} == $bottom->id } @content;
86 ok($top_info->{urgent}, 'top window is marked urgent');
87 ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
88 is(@urgent, 1, 'exactly one window got the urgent flag');
90 cmd '[id="' . $top->id . '"] focus';
92 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
93 is(@urgent, 0, 'no window got the urgent flag after focusing');
95 set_urgency($top, 1, $type);
98 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
99 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
101 #####################################################################
102 # Check if the workspace urgency hint gets set/cleared correctly
103 #####################################################################
105 my $ws = get_ws($tmp);
106 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
108 my $otmp = fresh_workspace;
110 set_urgency($top, 1, $type);
114 ok($ws->{urgent}, 'urgent flag set on workspace');
116 cmd "workspace $tmp";
119 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
121 ################################################################################
122 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
123 ################################################################################
125 # Go to a new workspace, open a different window, verify focus is on it.
126 $otmp = fresh_workspace;
127 my $different_window = open_window;
128 is($x->input_focus, $different_window->id, 'new window focused');
130 # Add the urgency hint on the other window.
131 set_urgency($top, 1, $type);
134 # Now try to switch to that window and see if focus changes.
135 cmd '[urgent=latest] focus';
136 isnt($x->input_focus, $different_window->id, 'window no longer focused');
137 is($x->input_focus, $top->id, 'urgent window focused');
139 ################################################################################
140 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
141 # (verify that it works in the correct order).
142 ################################################################################
144 cmd "workspace $otmp";
145 is($x->input_focus, $different_window->id, 'new window focused again');
147 set_urgency($top, 1, $type);
150 set_urgency($bottom, 1, $type);
153 cmd '[urgent=latest] focus';
154 is($x->input_focus, $bottom->id, 'latest urgent window focused');
155 set_urgency($bottom, 0, $type);
158 cmd '[urgent=latest] focus';
159 is($x->input_focus, $top->id, 'second urgent window focused');
160 set_urgency($top, 0, $type);
163 ################################################################################
164 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
165 # (verify that it works in the correct order).
166 ################################################################################
168 cmd "workspace $otmp";
169 is($x->input_focus, $different_window->id, 'new window focused again');
171 set_urgency($top, 1, $type);
174 set_urgency($bottom, 1, $type);
177 cmd '[urgent=oldest] focus';
178 is($x->input_focus, $top->id, 'oldest urgent window focused');
179 set_urgency($top, 0, $type);
182 cmd '[urgent=oldest] focus';
183 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
184 set_urgency($bottom, 0, $type);
187 ################################################################################
188 # Check if urgent flag gets propagated to parent containers
189 ################################################################################
198 my @children = (@{$con->{nodes}}, @{$con->{floating_nodes}});
199 my $urgent = grep { $_->{urgent} } @children;
200 $urgent += count_urgent($_) for @children;
204 $tmp = fresh_workspace;
206 my $win1 = open_window;
207 my $win2 = open_window;
208 cmd 'layout stacked';
209 cmd 'split vertical';
210 my $win3 = open_window;
211 my $win4 = open_window;
212 cmd 'split horizontal' ;
213 my $win5 = open_window;
214 my $win6 = open_window;
219 my $urgent = count_urgent(get_ws($tmp));
220 is($urgent, 0, 'no window got the urgent flag');
222 cmd '[id="' . $win2->id . '"] focus';
224 set_urgency($win5, 1, $type);
225 set_urgency($win6, 1, $type);
228 # we should have 5 urgent cons. win5, win6 and their 3 split parents.
230 $urgent = count_urgent(get_ws($tmp));
231 is($urgent, 5, '2 windows and 3 split containers got the urgent flag');
233 cmd '[id="' . $win5->id . '"] focus';
236 # now win5 and still the split parents should be urgent.
237 $urgent = count_urgent(get_ws($tmp));
238 is($urgent, 4, '1 window and 3 split containers got the urgent flag');
240 cmd '[id="' . $win6->id . '"] focus';
243 # now now window should be urgent.
244 $urgent = count_urgent(get_ws($tmp));
245 is($urgent, 0, 'All urgent flags got cleared');
247 ################################################################################
248 # Regression test: Check that urgent floating containers work properly (ticket
250 ################################################################################
252 $tmp = fresh_workspace;
253 my $floating_win = open_floating_window;
258 set_urgency($floating_win, 1, $type);
261 cmd "workspace $tmp";
265 ###############################################################################
266 # Check if the urgency hint is still set when the urgent window is killed
267 ###############################################################################
269 my $ws1 = fresh_workspace;
270 my $ws2 = fresh_workspace;
271 cmd "workspace $ws1";
272 my $w1 = open_window;
273 my $w2 = open_window;
274 cmd "workspace $ws2";
276 set_urgency($w1, 1, $type);
278 cmd '[id="' . $w1->id . '"] kill';
280 my $w = get_ws($ws1);
281 is($w->{urgent}, 0, 'Urgent flag no longer set after killing the window ' .
282 'from another workspace');
284 ##############################################################################
285 # Check if urgent flag can be unset if we move the window out of the container
286 ##############################################################################
287 my $tmp = fresh_workspace;
289 my $w1 = open_window;
290 my $w2 = open_window;
292 cmd '[id="' . $w2->id . '"] focus';
295 cmd 'layout stacked';
296 my $w3 = open_window;
298 cmd '[id="' . $w2->id . '"] focus';
300 set_urgency($w3, 1, $type);
305 cmd '[id="' . $w3->id . '"] focus';
307 my $ws = get_ws($tmp);
308 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
310 exit_gracefully($pid);