]> git.sur5r.net Git - i3/i3/blob - testcases/t/113-urgent.t
Merge branch 'fix-move-ws'
[i3/i3] / testcases / t / 113-urgent.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 use i3test i3_autostart => 0;
18 use List::Util qw(first);
19
20 my $config = <<EOT;
21 # i3 config file (v4)
22 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
23
24 force_display_urgency_hint 0ms
25 EOT
26 my $pid = launch_with_config($config);
27
28 my $tmp = fresh_workspace;
29
30 #####################################################################
31 # Create two windows and put them in stacking mode
32 #####################################################################
33
34 cmd 'split v';
35
36 my $top = open_window;
37 my $bottom = open_window;
38
39 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
40 is(@urgent, 0, 'no window got the urgent flag');
41
42 # cmd 'layout stacking';
43
44 #####################################################################
45 # Add the urgency hint, switch to a different workspace and back again
46 #####################################################################
47 $top->add_hint('urgency');
48 sync_with_i3;
49
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;
54
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');
58
59 cmd '[id="' . $top->id . '"] focus';
60
61 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
62 is(@urgent, 0, 'no window got the urgent flag after focusing');
63
64 $top->add_hint('urgency');
65 sync_with_i3;
66
67 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
68 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
69
70 #####################################################################
71 # Check if the workspace urgency hint gets set/cleared correctly
72 #####################################################################
73
74 my $ws = get_ws($tmp);
75 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
76
77 my $otmp = fresh_workspace;
78
79 $top->add_hint('urgency');
80 sync_with_i3;
81
82 $ws = get_ws($tmp);
83 ok($ws->{urgent}, 'urgent flag set on workspace');
84
85 cmd "workspace $tmp";
86
87 $ws = get_ws($tmp);
88 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
89
90 ################################################################################
91 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
92 ################################################################################
93
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');
98
99 # Add the urgency hint on the other window.
100 $top->add_hint('urgency');
101 sync_with_i3;
102
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');
107
108 ################################################################################
109 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
110 # (verify that it works in the correct order).
111 ################################################################################
112
113 cmd "workspace $otmp";
114 is($x->input_focus, $different_window->id, 'new window focused again');
115
116 $top->add_hint('urgency');
117 sync_with_i3;
118
119 $bottom->add_hint('urgency');
120 sync_with_i3;
121
122 cmd '[urgent=latest] focus';
123 is($x->input_focus, $bottom->id, 'latest urgent window focused');
124 $bottom->delete_hint('urgency');
125 sync_with_i3;
126
127 cmd '[urgent=latest] focus';
128 is($x->input_focus, $top->id, 'second urgent window focused');
129 $top->delete_hint('urgency');
130 sync_with_i3;
131
132 ################################################################################
133 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
134 # (verify that it works in the correct order).
135 ################################################################################
136
137 cmd "workspace $otmp";
138 is($x->input_focus, $different_window->id, 'new window focused again');
139
140 $top->add_hint('urgency');
141 sync_with_i3;
142
143 $bottom->add_hint('urgency');
144 sync_with_i3;
145
146 cmd '[urgent=oldest] focus';
147 is($x->input_focus, $top->id, 'oldest urgent window focused');
148 $top->delete_hint('urgency');
149 sync_with_i3;
150
151 cmd '[urgent=oldest] focus';
152 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
153 $bottom->delete_hint('urgency');
154 sync_with_i3;
155
156 ################################################################################
157 # Check if urgent flag gets propagated to parent containers
158 ################################################################################
159
160 cmd 'split v';
161
162
163
164 sub count_urgent {
165     my ($con) = @_;
166
167     my @children = (@{$con->{nodes}}, @{$con->{floating_nodes}});
168     my $urgent = grep { $_->{urgent} } @children;
169     $urgent += count_urgent($_) for @children;
170     return $urgent;
171 }
172
173 $tmp = fresh_workspace;
174
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;
184
185 sync_with_i3;
186
187
188 my $urgent = count_urgent(get_ws($tmp));
189 is($urgent, 0, 'no window got the urgent flag');
190
191 cmd '[id="' . $win2->id . '"] focus';
192 sync_with_i3;
193 $win5->add_hint('urgency');
194 $win6->add_hint('urgency');
195 sync_with_i3;
196
197 # we should have 5 urgent cons. win5, win6 and their 3 split parents.
198
199 $urgent = count_urgent(get_ws($tmp));
200 is($urgent, 5, '2 windows and 3 split containers got the urgent flag');
201
202 cmd '[id="' . $win5->id . '"] focus';
203 sync_with_i3;
204
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');
208
209 cmd '[id="' . $win6->id . '"] focus';
210 sync_with_i3;
211
212 # now now window should be urgent.
213 $urgent = count_urgent(get_ws($tmp));
214 is($urgent, 0, 'All urgent flags got cleared');
215
216 ################################################################################
217 # Regression test: Check that urgent floating containers work properly (ticket
218 # #821)
219 ################################################################################
220
221 $tmp = fresh_workspace;
222 my $floating_win = open_floating_window;
223
224 # switch away
225 fresh_workspace;
226
227 $floating_win->add_hint('urgency');
228 sync_with_i3;
229
230 cmd "workspace $tmp";
231
232 does_i3_live;
233
234 exit_gracefully($pid);
235
236 done_testing;