]> git.sur5r.net Git - i3/i3/blob - testcases/t/200-urgency-timer.t
tests: fix setting the urgency hint
[i3/i3] / testcases / t / 200-urgency-timer.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 #
18 # Tests whether the urgency timer works as expected and does not break
19 # urgency handling.
20 #
21
22 use List::Util qw(first);
23 use i3test i3_autostart => 0;
24 use Time::HiRes qw(sleep);
25
26 # Ensure the pointer is at (0, 0) so that we really start on the first
27 # (the left) workspace.
28 $x->root->warp_pointer(0, 0);
29
30 my $config = <<EOT;
31 # i3 config file (v4)
32 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
33
34 force_display_urgency_hint 150ms
35 EOT
36 my $pid = launch_with_config($config);
37
38 #####################################################################
39 # Initial setup: one window on ws1, empty ws2
40 #####################################################################
41
42 my $tmp1 = fresh_workspace;
43 my $w = open_window;
44
45 my $tmp2 = fresh_workspace;
46 cmd "workspace $tmp2";
47
48 $w->add_hint('urgency');
49 sync_with_i3;
50
51 #######################################################################
52 # Create a window on ws1, then switch to ws2, set urgency, switch back
53 #######################################################################
54
55 isnt($x->input_focus, $w->id, 'window not focused');
56
57 my @content = @{get_ws_content($tmp1)};
58 my @urgent = grep { $_->{urgent} } @content;
59 is(@urgent, 1, "window marked as urgent");
60
61 # switch to ws1
62 cmd "workspace $tmp1";
63
64 # this will start the timer
65 sleep(0.1);
66 @content = @{get_ws_content($tmp1)};
67 @urgent = grep { $_->{urgent} } @content;
68 is(@urgent, 1, 'window still marked as urgent');
69
70 # now check if the timer was triggered
71 cmd "workspace $tmp2";
72
73 sleep(0.1);
74 @content = @{get_ws_content($tmp1)};
75 @urgent = grep { $_->{urgent} } @content;
76 is(@urgent, 0, 'window not marked as urgent anymore');
77
78 #######################################################################
79 # Create another window on ws1, focus it, switch to ws2, make the other
80 # window urgent, and switch back. This should not trigger the timer.
81 #######################################################################
82
83 cmd "workspace $tmp1";
84 my $w2 = open_window;
85 is($x->input_focus, $w2->id, 'window 2 focused');
86
87 cmd "workspace $tmp2";
88 $w->delete_hint('urgency');
89 $w->add_hint('urgency');
90 sync_with_i3;
91
92 @content = @{get_ws_content($tmp1)};
93 @urgent = grep { $_->{urgent} } @content;
94 is(@urgent, 1, 'window 1 marked as urgent');
95
96 # Switch back to ws1. This should focus w2.
97 cmd "workspace $tmp1";
98 is($x->input_focus, $w2->id, 'window 2 focused');
99
100 @content = @{get_ws_content($tmp1)};
101 @urgent = grep { $_->{urgent} } @content;
102 is(@urgent, 1, 'window 1 still marked as urgent');
103
104 # explicitly focusing the window should result in immediate urgency reset
105 cmd '[id="' . $w->id . '"] focus';
106 @content = @{get_ws_content($tmp1)};
107 @urgent = grep { $_->{urgent} } @content;
108 is(@urgent, 0, 'window 1 not marked as urgent anymore');
109
110 ################################################################################
111 # open a stack, mark one window as urgent, switch to that workspace and verify
112 # it’s cleared correctly.
113 ################################################################################
114
115 sub count_total_urgent {
116     my ($con) = @_;
117
118     my $urgent = ($con->{urgent} ? 1 : 0);
119     $urgent += count_total_urgent($_) for (@{$con->{nodes}}, @{$con->{floating_nodes}});
120     return $urgent;
121 }
122
123 my $tmp3 = fresh_workspace;
124 open_window;
125 open_window;
126 cmd 'split v';
127 my $split_left = open_window;
128 cmd 'layout stacked';
129
130 cmd "workspace $tmp2";
131
132 is(count_total_urgent(get_ws($tmp3)), 0, "no urgent windows on workspace $tmp3");
133
134 $split_left->add_hint('urgency');
135 sync_with_i3;
136
137 cmp_ok(count_total_urgent(get_ws($tmp3)), '>=', 0, "more than one urgent window on workspace $tmp3");
138
139 cmd "workspace $tmp3";
140
141 # Remove the urgency hint.
142 $split_left->delete_hint('urgency');
143 sync_with_i3;
144
145 sleep(0.2);
146 is(count_total_urgent(get_ws($tmp3)), 0, "no more urgent windows on workspace $tmp3");
147
148 exit_gracefully($pid);
149
150 done_testing;