]> git.sur5r.net Git - i3/i3/blob - testcases/t/200-urgency-timer.t
Merge branch 'fix-urgent-crash'
[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->add_hint('urgency');
89 sync_with_i3;
90
91 @content = @{get_ws_content($tmp1)};
92 @urgent = grep { $_->{urgent} } @content;
93 is(@urgent, 1, 'window 1 marked as urgent');
94
95 # Switch back to ws1. This should focus w2.
96 cmd "workspace $tmp1";
97 is($x->input_focus, $w2->id, 'window 2 focused');
98
99 @content = @{get_ws_content($tmp1)};
100 @urgent = grep { $_->{urgent} } @content;
101 is(@urgent, 1, 'window 1 still marked as urgent');
102
103 # explicitly focusing the window should result in immediate urgency reset
104 cmd '[id="' . $w->id . '"] focus';
105 @content = @{get_ws_content($tmp1)};
106 @urgent = grep { $_->{urgent} } @content;
107 is(@urgent, 0, 'window 1 not marked as urgent anymore');
108
109 ################################################################################
110 # open a stack, mark one window as urgent, switch to that workspace and verify
111 # it’s cleared correctly.
112 ################################################################################
113
114 sub count_total_urgent {
115     my ($con) = @_;
116
117     my $urgent = ($con->{urgent} ? 1 : 0);
118     $urgent += count_total_urgent($_) for (@{$con->{nodes}}, @{$con->{floating_nodes}});
119     return $urgent;
120 }
121
122 my $tmp3 = fresh_workspace;
123 open_window;
124 open_window;
125 cmd 'split v';
126 my $split_left = open_window;
127 cmd 'layout stacked';
128
129 cmd "workspace $tmp2";
130
131 is(count_total_urgent(get_ws($tmp3)), 0, "no urgent windows on workspace $tmp3");
132
133 $split_left->add_hint('urgency');
134 sync_with_i3;
135
136 cmp_ok(count_total_urgent(get_ws($tmp3)), '>=', 0, "more than one urgent window on workspace $tmp3");
137
138 cmd "workspace $tmp3";
139
140 # Remove the urgency hint.
141 $split_left->delete_hint('urgency');
142 sync_with_i3;
143
144 sleep(0.2);
145 is(count_total_urgent(get_ws($tmp3)), 0, "no more urgent windows on workspace $tmp3");
146
147 exit_gracefully($pid);
148
149 done_testing;