+ my $ws = get_ws($tmp);
+ ok(!$ws->{urgent}, 'urgent flag not set on workspace');
+
+ my $otmp = fresh_workspace;
+
+ set_urgency($top, 1, $type);
+ sync_with_i3;
+
+ $ws = get_ws($tmp);
+ ok($ws->{urgent}, 'urgent flag set on workspace');
+
+ cmd "workspace $tmp";
+
+ $ws = get_ws($tmp);
+ ok(!$ws->{urgent}, 'urgent flag not set on workspace after switching');
+
+################################################################################
+# Use the 'urgent' criteria to switch to windows which have the urgency hint set.
+################################################################################
+
+# Go to a new workspace, open a different window, verify focus is on it.
+ $otmp = fresh_workspace;
+ my $different_window = open_window;
+ is($x->input_focus, $different_window->id, 'new window focused');
+
+# Add the urgency hint on the other window.
+ set_urgency($top, 1, $type);
+ sync_with_i3;
+
+# Now try to switch to that window and see if focus changes.
+ cmd '[urgent=latest] focus';
+ isnt($x->input_focus, $different_window->id, 'window no longer focused');
+ is($x->input_focus, $top->id, 'urgent window focused');
+
+################################################################################
+# Same thing, but with multiple windows and using the 'urgency=latest' criteria
+# (verify that it works in the correct order).
+################################################################################
+
+ cmd "workspace $otmp";
+ is($x->input_focus, $different_window->id, 'new window focused again');
+
+ set_urgency($top, 1, $type);
+ sync_with_i3;
+
+ set_urgency($bottom, 1, $type);
+ sync_with_i3;
+
+ cmd '[urgent=latest] focus';
+ is($x->input_focus, $bottom->id, 'latest urgent window focused');
+ set_urgency($bottom, 0, $type);
+ sync_with_i3;
+
+ cmd '[urgent=latest] focus';
+ is($x->input_focus, $top->id, 'second urgent window focused');
+ set_urgency($top, 0, $type);
+ sync_with_i3;
+
+################################################################################
+# Same thing, but with multiple windows and using the 'urgency=oldest' criteria
+# (verify that it works in the correct order).
+################################################################################
+
+ cmd "workspace $otmp";
+ is($x->input_focus, $different_window->id, 'new window focused again');
+
+ set_urgency($top, 1, $type);
+ sync_with_i3;
+
+ set_urgency($bottom, 1, $type);
+ sync_with_i3;
+
+ cmd '[urgent=oldest] focus';
+ is($x->input_focus, $top->id, 'oldest urgent window focused');
+ set_urgency($top, 0, $type);
+ sync_with_i3;
+
+ cmd '[urgent=oldest] focus';
+ is($x->input_focus, $bottom->id, 'oldest urgent window focused');
+ set_urgency($bottom, 0, $type);
+ sync_with_i3;
+
+################################################################################
+# Check if urgent flag gets propagated to parent containers
+################################################################################
+
+ cmd 'split v';
+
+
+
+ sub count_urgent {
+ my ($con) = @_;
+
+ my @children = (@{$con->{nodes}}, @{$con->{floating_nodes}});
+ my $urgent = grep { $_->{urgent} } @children;
+ $urgent += count_urgent($_) for @children;
+ return $urgent;
+ }
+
+ $tmp = fresh_workspace;
+
+ my $win1 = open_window;
+ my $win2 = open_window;
+ cmd 'layout stacked';
+ cmd 'split vertical';
+ my $win3 = open_window;
+ my $win4 = open_window;
+ cmd 'split horizontal' ;
+ my $win5 = open_window;
+ my $win6 = open_window;
+
+ sync_with_i3;
+
+
+ my $urgent = count_urgent(get_ws($tmp));
+ is($urgent, 0, 'no window got the urgent flag');
+
+ cmd '[id="' . $win2->id . '"] focus';
+ sync_with_i3;
+ set_urgency($win5, 1, $type);
+ set_urgency($win6, 1, $type);
+ sync_with_i3;
+
+# we should have 5 urgent cons. win5, win6 and their 3 split parents.
+
+ $urgent = count_urgent(get_ws($tmp));
+ is($urgent, 5, '2 windows and 3 split containers got the urgent flag');
+
+ cmd '[id="' . $win5->id . '"] focus';
+ sync_with_i3;
+
+# now win5 and still the split parents should be urgent.
+ $urgent = count_urgent(get_ws($tmp));
+ is($urgent, 4, '1 window and 3 split containers got the urgent flag');
+
+ cmd '[id="' . $win6->id . '"] focus';
+ sync_with_i3;
+
+# now now window should be urgent.
+ $urgent = count_urgent(get_ws($tmp));
+ is($urgent, 0, 'All urgent flags got cleared');
+
+################################################################################
+# Regression test: Check that urgent floating containers work properly (ticket
+# #821)
+################################################################################
+
+ $tmp = fresh_workspace;
+ my $floating_win = open_floating_window;
+
+# switch away
+ fresh_workspace;
+
+ set_urgency($floating_win, 1, $type);
+ sync_with_i3;
+
+ cmd "workspace $tmp";
+
+ does_i3_live;
+
+###############################################################################
+# Check if the urgency hint is still set when the urgent window is killed
+###############################################################################
+
+ my $ws1 = fresh_workspace;
+ my $ws2 = fresh_workspace;
+ cmd "workspace $ws1";
+ my $w1 = open_window;
+ my $w2 = open_window;
+ cmd "workspace $ws2";
+ sync_with_i3;
+ set_urgency($w1, 1, $type);
+ sync_with_i3;
+ cmd '[id="' . $w1->id . '"] kill';
+ sync_with_i3;
+ my $w = get_ws($ws1);
+ is($w->{urgent}, 0, 'Urgent flag no longer set after killing the window ' .
+ 'from another workspace');
+
+##############################################################################
+# Check if urgent flag can be unset if we move the window out of the container
+##############################################################################
+ my $tmp = fresh_workspace;
+ cmd 'layout tabbed';
+ my $w1 = open_window;
+ my $w2 = open_window;
+ sync_with_i3;
+ cmd '[id="' . $w2->id . '"] focus';
+ sync_with_i3;
+ cmd 'split v';
+ cmd 'layout stacked';
+ my $w3 = open_window;
+ sync_with_i3;
+ cmd '[id="' . $w2->id . '"] focus';
+ sync_with_i3;
+ set_urgency($w3, 1, $type);
+ sync_with_i3;
+ cmd 'focus parent';
+ sync_with_i3;
+ cmd 'move right';
+ cmd '[id="' . $w3->id . '"] focus';
+ sync_with_i3;
+ my $ws = get_ws($tmp);
+ ok(!$ws->{urgent}, 'urgent flag not set on workspace');