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 use List::Util qw(first);
20 my $tmp = fresh_workspace;
22 #####################################################################
23 # Create two windows and put them in stacking mode
24 #####################################################################
28 my $top = open_window;
29 my $bottom = open_window;
31 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
32 is(@urgent, 0, 'no window got the urgent flag');
34 # cmd 'layout stacking';
36 #####################################################################
37 # Add the urgency hint, switch to a different workspace and back again
38 #####################################################################
39 $top->add_hint('urgency');
42 my @content = @{get_ws_content($tmp)};
43 @urgent = grep { $_->{urgent} } @content;
44 my $top_info = first { $_->{window} == $top->id } @content;
45 my $bottom_info = first { $_->{window} == $bottom->id } @content;
47 ok($top_info->{urgent}, 'top window is marked urgent');
48 ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
49 is(@urgent, 1, 'exactly one window got the urgent flag');
51 cmd '[id="' . $top->id . '"] focus';
53 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
54 is(@urgent, 0, 'no window got the urgent flag after focusing');
56 $top->add_hint('urgency');
59 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
60 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
62 #####################################################################
63 # Check if the workspace urgency hint gets set/cleared correctly
64 #####################################################################
66 my $ws = get_ws($tmp);
67 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
69 my $otmp = fresh_workspace;
71 $top->add_hint('urgency');
75 ok($ws->{urgent}, 'urgent flag set on workspace');
80 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
82 ################################################################################
83 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
84 ################################################################################
86 # Go to a new workspace, open a different window, verify focus is on it.
87 $otmp = fresh_workspace;
88 my $different_window = open_window;
89 is($x->input_focus, $different_window->id, 'new window focused');
91 # Add the urgency hint on the other window.
92 $top->add_hint('urgency');
95 # Now try to switch to that window and see if focus changes.
96 cmd '[urgent=latest] focus';
97 isnt($x->input_focus, $different_window->id, 'window no longer focused');
98 is($x->input_focus, $top->id, 'urgent window focused');
100 ################################################################################
101 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
102 # (verify that it works in the correct order).
103 ################################################################################
105 cmd "workspace $otmp";
106 is($x->input_focus, $different_window->id, 'new window focused again');
108 $top->add_hint('urgency');
111 $bottom->add_hint('urgency');
114 cmd '[urgent=latest] focus';
115 is($x->input_focus, $bottom->id, 'latest urgent window focused');
116 $bottom->delete_hint('urgency');
119 cmd '[urgent=latest] focus';
120 is($x->input_focus, $top->id, 'second urgent window focused');
121 $top->delete_hint('urgency');
124 ################################################################################
125 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
126 # (verify that it works in the correct order).
127 ################################################################################
129 cmd "workspace $otmp";
130 is($x->input_focus, $different_window->id, 'new window focused again');
132 $top->add_hint('urgency');
135 $bottom->add_hint('urgency');
138 cmd '[urgent=oldest] focus';
139 is($x->input_focus, $top->id, 'oldest urgent window focused');
140 $top->delete_hint('urgency');
143 cmd '[urgent=oldest] focus';
144 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
145 $bottom->delete_hint('urgency');