]> git.sur5r.net Git - i3/i3/blob - testcases/t/198-urgency-timer.t
implement delayed urgency hint reset
[i3/i3] / testcases / t / 198-urgency-timer.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests whether the urgency timer works as expected and does not break
5 # urgency handling.
6 #
7
8 use List::Util qw(first);
9 use i3test i3_autostart => 0;
10 use Time::HiRes qw(sleep);
11
12 # Ensure the pointer is at (0, 0) so that we really start on the first
13 # (the left) workspace.
14 $x->root->warp_pointer(0, 0);
15
16 my $config = <<EOT;
17 # i3 config file (v4)
18 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
19
20 force_display_urgency_hint 150ms
21 EOT
22 my $pid = launch_with_config($config);
23
24 #####################################################################
25 # Initial setup: one window on ws1, empty ws2
26 #####################################################################
27
28 my $tmp1 = fresh_workspace;
29 my $w = open_window;
30
31 my $tmp2 = fresh_workspace;
32 cmd "workspace $tmp2";
33
34 $w->add_hint('urgency');
35 sync_with_i3;
36
37 #######################################################################
38 # Create a window on ws1, then switch to ws2, set urgency, switch back
39 #######################################################################
40
41 isnt($x->input_focus, $w->id, 'window not focused');
42
43 my @content = @{get_ws_content($tmp1)};
44 my @urgent = grep { $_->{urgent} } @content;
45 is(@urgent, 1, "window marked as urgent");
46
47 # switch to ws1
48 cmd "workspace $tmp1";
49
50 # this will start the timer
51 sleep(0.1);
52 @content = @{get_ws_content($tmp1)};
53 @urgent = grep { $_->{urgent} } @content;
54 is(@urgent, 1, 'window still marked as urgent');
55
56 # now check if the timer was triggered
57 cmd "workspace $tmp2";
58
59 sleep(0.1);
60 @content = @{get_ws_content($tmp1)};
61 @urgent = grep { $_->{urgent} } @content;
62 is(@urgent, 0, 'window not marked as urgent anymore');
63
64 #######################################################################
65 # Create another window on ws1, focus it, switch to ws2, make the other
66 # window urgent, and switch back. This should not trigger the timer.
67 #######################################################################
68
69 cmd "workspace $tmp1";
70 my $w2 = open_window;
71 is($x->input_focus, $w2->id, 'window 2 focused');
72
73 cmd "workspace $tmp2";
74 $w->add_hint('urgency');
75 sync_with_i3;
76
77 @content = @{get_ws_content($tmp1)};
78 @urgent = grep { $_->{urgent} } @content;
79 is(@urgent, 1, 'window 1 marked as urgent');
80
81 # Switch back to ws1. This should focus w2.
82 cmd "workspace $tmp1";
83 is($x->input_focus, $w2->id, 'window 2 focused');
84
85 @content = @{get_ws_content($tmp1)};
86 @urgent = grep { $_->{urgent} } @content;
87 is(@urgent, 1, 'window 1 still marked as urgent');
88
89 # explicitly focusing the window should result in immediate urgency reset
90 cmd '[id="' . $w->id . '"] focus';
91 @content = @{get_ws_content($tmp1)};
92 @urgent = grep { $_->{urgent} } @content;
93 is(@urgent, 0, 'window 1 not marked as urgent anymore');
94
95 done_testing;