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