2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
18 # Tests whether the urgency timer works as expected and does not break
22 use List::Util qw(first);
23 use i3test i3_autostart => 0;
24 use Time::HiRes qw(sleep);
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);
32 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
34 force_display_urgency_hint 500ms
36 my $pid = launch_with_config($config);
38 #####################################################################
39 # Initial setup: one window on ws1, empty ws2
40 #####################################################################
42 my $tmp1 = fresh_workspace;
45 my $tmp2 = fresh_workspace;
46 cmd "workspace $tmp2";
48 $w->add_hint('urgency');
51 #######################################################################
52 # Create a window on ws1, then switch to ws2, set urgency, switch back
53 #######################################################################
55 isnt($x->input_focus, $w->id, 'window not focused');
57 my @content = @{get_ws_content($tmp1)};
58 my @urgent = grep { $_->{urgent} } @content;
59 is(@urgent, 1, "window marked as urgent");
62 cmd "workspace $tmp1";
64 # this will start the timer
66 @content = @{get_ws_content($tmp1)};
67 @urgent = grep { $_->{urgent} } @content;
68 is(@urgent, 1, 'window still marked as urgent');
70 # now check if the timer was triggered
71 cmd "workspace $tmp2";
74 @content = @{get_ws_content($tmp1)};
75 @urgent = grep { $_->{urgent} } @content;
76 is(@urgent, 0, 'window not marked as urgent anymore');
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 #######################################################################
83 cmd "workspace $tmp1";
85 is($x->input_focus, $w2->id, 'window 2 focused');
87 cmd "workspace $tmp2";
88 $w->delete_hint('urgency');
89 $w->add_hint('urgency');
92 @content = @{get_ws_content($tmp1)};
93 @urgent = grep { $_->{urgent} } @content;
94 is(@urgent, 1, 'window 1 marked as urgent');
96 # Switch back to ws1. This should focus w2.
97 cmd "workspace $tmp1";
98 is($x->input_focus, $w2->id, 'window 2 focused');
100 @content = @{get_ws_content($tmp1)};
101 @urgent = grep { $_->{urgent} } @content;
102 is(@urgent, 1, 'window 1 still marked as urgent');
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');
110 ################################################################################
111 # open a stack, mark one window as urgent, switch to that workspace and verify
112 # it’s cleared correctly.
113 ################################################################################
115 sub count_total_urgent {
118 my $urgent = ($con->{urgent} ? 1 : 0);
119 $urgent += count_total_urgent($_) for (@{$con->{nodes}}, @{$con->{floating_nodes}});
123 my $tmp3 = fresh_workspace;
127 my $split_left = open_window;
128 cmd 'layout stacked';
130 cmd "workspace $tmp2";
132 is(count_total_urgent(get_ws($tmp3)), 0, "no urgent windows on workspace $tmp3");
134 $split_left->add_hint('urgency');
137 cmp_ok(count_total_urgent(get_ws($tmp3)), '>=', 0, "more than one urgent window on workspace $tmp3");
139 cmd "workspace $tmp3";
141 # Remove the urgency hint.
142 $split_left->delete_hint('urgency');
146 is(count_total_urgent(get_ws($tmp3)), 0, "no more urgent windows on workspace $tmp3");
148 exit_gracefully($pid);