2 # vim:ts=4:sw=4:expandtab
5 use List::Util qw(first);
7 my $tmp = fresh_workspace;
9 #####################################################################
10 # Create two windows and put them in stacking mode
11 #####################################################################
15 my $top = open_window;
16 my $bottom = open_window;
18 my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
19 is(@urgent, 0, 'no window got the urgent flag');
21 # cmd 'layout stacking';
23 #####################################################################
24 # Add the urgency hint, switch to a different workspace and back again
25 #####################################################################
26 $top->add_hint('urgency');
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;
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');
38 cmd '[id="' . $top->id . '"] focus';
40 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
41 is(@urgent, 0, 'no window got the urgent flag after focusing');
43 $top->add_hint('urgency');
46 @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
47 is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
49 #####################################################################
50 # Check if the workspace urgency hint gets set/cleared correctly
51 #####################################################################
53 my $ws = get_ws($tmp);
54 ok(!$ws->{urgent}, 'urgent flag not set on workspace');
56 my $otmp = fresh_workspace;
58 $top->add_hint('urgency');
62 ok($ws->{urgent}, 'urgent flag set on workspace');
67 ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
69 ################################################################################
70 # Use the 'urgent' criteria to switch to windows which have the urgency hint set.
71 ################################################################################
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');
78 # Add the urgency hint on the other window.
79 $top->add_hint('urgency');
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');
87 ################################################################################
88 # Same thing, but with multiple windows and using the 'urgency=latest' criteria
89 # (verify that it works in the correct order).
90 ################################################################################
92 cmd "workspace $otmp";
93 is($x->input_focus, $different_window->id, 'new window focused again');
95 $top->add_hint('urgency');
98 $bottom->add_hint('urgency');
101 cmd '[urgent=latest] focus';
102 is($x->input_focus, $bottom->id, 'latest urgent window focused');
103 $bottom->delete_hint('urgency');
106 cmd '[urgent=latest] focus';
107 is($x->input_focus, $top->id, 'second urgent window focused');
108 $top->delete_hint('urgency');
111 ################################################################################
112 # Same thing, but with multiple windows and using the 'urgency=oldest' criteria
113 # (verify that it works in the correct order).
114 ################################################################################
116 cmd "workspace $otmp";
117 is($x->input_focus, $different_window->id, 'new window focused again');
119 $top->add_hint('urgency');
122 $bottom->add_hint('urgency');
125 cmd '[urgent=oldest] focus';
126 is($x->input_focus, $top->id, 'oldest urgent window focused');
127 $top->delete_hint('urgency');
130 cmd '[urgent=oldest] focus';
131 is($x->input_focus, $bottom->id, 'oldest urgent window focused');
132 $bottom->delete_hint('urgency');