]> git.sur5r.net Git - i3/i3/blob - testcases/t/113-urgent.t
04f72c3d8319945422d0f455d043d08b6a8f3c8a
[i3/i3] / testcases / t / 113-urgent.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use List::Util qw(first);
6
7 my $tmp = fresh_workspace;
8
9 #####################################################################
10 # Create two windows and put them in stacking mode
11 #####################################################################
12
13 cmd 'split v';
14
15 my $top = open_window;
16 my $bottom = open_window;
17
18 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
19 is(@urgent, 0, 'no window got the urgent flag');
20
21 # cmd 'layout stacking';
22
23 #####################################################################
24 # Add the urgency hint, switch to a different workspace and back again
25 #####################################################################
26 $top->add_hint('urgency');
27 sync_with_i3;
28
29 my @content = @{get_ws_content($tmp)};
30 @urgent = grep { $_->{urgent} } @content;
31 my $top_info = first { $_->{window} == $top->id } @content;
32 my $bottom_info = first { $_->{window} == $bottom->id } @content;
33
34 ok($top_info->{urgent}, 'top window is marked urgent');
35 ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
36 is(@urgent, 1, 'exactly one window got the urgent flag');
37
38 cmd '[id="' . $top->id . '"] focus';
39
40 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
41 is(@urgent, 0, 'no window got the urgent flag after focusing');
42
43 $top->add_hint('urgency');
44 sync_with_i3;
45
46 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
47 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
48
49 #####################################################################
50 # Check if the workspace urgency hint gets set/cleared correctly
51 #####################################################################
52
53 my $ws = get_ws($tmp);
54 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
55
56 my $otmp = fresh_workspace;
57
58 $top->add_hint('urgency');
59 sync_with_i3;
60
61 $ws = get_ws($tmp);
62 ok($ws->{urgent}, 'urgent flag set on workspace');
63
64 cmd "workspace $tmp";
65
66 $ws = get_ws($tmp);
67 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
68
69 ################################################################################
70 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
71 ################################################################################
72
73 # Go to a new workspace, open a different window, verify focus is on it.
74 $otmp = fresh_workspace;
75 my $different_window = open_window;
76 is($x->input_focus, $different_window->id, 'new window focused');
77
78 # Add the urgency hint on the other window.
79 $top->add_hint('urgency');
80 sync_with_i3;
81
82 # Now try to switch to that window and see if focus changes.
83 cmd '[urgent=latest] focus';
84 isnt($x->input_focus, $different_window->id, 'window no longer focused');
85 is($x->input_focus, $top->id, 'urgent window focused');
86
87 ################################################################################
88 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
89 # (verify that it works in the correct order).
90 ################################################################################
91
92 cmd "workspace $otmp";
93 is($x->input_focus, $different_window->id, 'new window focused again');
94
95 $top->add_hint('urgency');
96 sync_with_i3;
97
98 $bottom->add_hint('urgency');
99 sync_with_i3;
100
101 cmd '[urgent=latest] focus';
102 is($x->input_focus, $bottom->id, 'latest urgent window focused');
103 $bottom->delete_hint('urgency');
104 sync_with_i3;
105
106 cmd '[urgent=latest] focus';
107 is($x->input_focus, $top->id, 'second urgent window focused');
108 $top->delete_hint('urgency');
109 sync_with_i3;
110
111 ################################################################################
112 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
113 # (verify that it works in the correct order).
114 ################################################################################
115
116 cmd "workspace $otmp";
117 is($x->input_focus, $different_window->id, 'new window focused again');
118
119 $top->add_hint('urgency');
120 sync_with_i3;
121
122 $bottom->add_hint('urgency');
123 sync_with_i3;
124
125 cmd '[urgent=oldest] focus';
126 is($x->input_focus, $top->id, 'oldest urgent window focused');
127 $top->delete_hint('urgency');
128 sync_with_i3;
129
130 cmd '[urgent=oldest] focus';
131 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
132 $bottom->delete_hint('urgency');
133 sync_with_i3;
134
135 done_testing;