aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/200-urgency-timer.t
blob: 4192f5b47936df86bec82953a219a107f552d200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • https://i3wm.org/downloads/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
#
# Tests whether the urgency timer works as expected and does not break
# urgency handling.
#

use List::Util qw(first);
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

force_display_urgency_hint 500ms
EOT
use Time::HiRes qw(sleep);

#####################################################################
# Initial setup: one window on ws1, empty ws2
#####################################################################

my $tmp1 = fresh_workspace;
my $w = open_window;

my $tmp2 = fresh_workspace;
cmd "workspace $tmp2";

$w->add_hint('urgency');
sync_with_i3;

#######################################################################
# Create a window on ws1, then switch to ws2, set urgency, switch back
#######################################################################

isnt($x->input_focus, $w->id, 'window not focused');

my @content = @{get_ws_content($tmp1)};
my @urgent = grep { $_->{urgent} } @content;
is(@urgent, 1, "window marked as urgent");

# switch to ws1
cmd "workspace $tmp1";

# this will start the timer
sleep(0.1);
@content = @{get_ws_content($tmp1)};
@urgent = grep { $_->{urgent} } @content;
is(@urgent, 1, 'window still marked as urgent');

# now check if the timer was triggered
cmd "workspace $tmp2";

sleep(0.5);
@content = @{get_ws_content($tmp1)};
@urgent = grep { $_->{urgent} } @content;
is(@urgent, 0, 'window not marked as urgent anymore');

#######################################################################
# Create another window on ws1, focus it, switch to ws2, make the other
# window urgent, and switch back. This should not trigger the timer.
#######################################################################

cmd "workspace $tmp1";
my $w2 = open_window;
is($x->input_focus, $w2->id, 'window 2 focused');

cmd "workspace $tmp2";
$w->delete_hint('urgency');
$w->add_hint('urgency');
sync_with_i3;

@content = @{get_ws_content($tmp1)};
@urgent = grep { $_->{urgent} } @content;
is(@urgent, 1, 'window 1 marked as urgent');

# Switch back to ws1. This should focus w2.
cmd "workspace $tmp1";
is($x->input_focus, $w2->id, 'window 2 focused');

@content = @{get_ws_content($tmp1)};
@urgent = grep { $_->{urgent} } @content;
is(@urgent, 1, 'window 1 still marked as urgent');

# explicitly focusing the window should result in immediate urgency reset
cmd '[id="' . $w->id . '"] focus';
@content = @{get_ws_content($tmp1)};
@urgent = grep { $_->{urgent} } @content;
is(@urgent, 0, 'window 1 not marked as urgent anymore');

################################################################################
# open a stack, mark one window as urgent, switch to that workspace and verify
# it’s cleared correctly.
################################################################################

sub count_total_urgent {
    my ($con) = @_;

    my $urgent = ($con->{urgent} ? 1 : 0);
    $urgent += count_total_urgent($_) for (@{$con->{nodes}}, @{$con->{floating_nodes}});
    return $urgent;
}

my $tmp3 = fresh_workspace;
open_window;
open_window;
cmd 'split v';
my $split_left = open_window;
cmd 'layout stacked';

cmd "workspace $tmp2";

is(count_total_urgent(get_ws($tmp3)), 0, "no urgent windows on workspace $tmp3");

$split_left->add_hint('urgency');
sync_with_i3;

cmp_ok(count_total_urgent(get_ws($tmp3)), '>=', 0, "more than one urgent window on workspace $tmp3");

cmd "workspace $tmp3";

# Remove the urgency hint.
$split_left->delete_hint('urgency');
sync_with_i3;

sleep(0.6);
is(count_total_urgent(get_ws($tmp3)), 0, "no more urgent windows on workspace $tmp3");

done_testing;