]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/13-urgent.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 13-urgent.t
index 7dee21c624979e5d3ea0a0a211cb5aa18c28b1cb..f40b72fb9c7691b9894b1da2d0d02317db9cfd85 100644 (file)
@@ -1,60 +1,75 @@
 #!perl
 # vim:ts=4:sw=4:expandtab
-# Beware that this test uses workspace 9 to perform some tests (it expects
-# the workspace to be empty).
-# TODO: skip it by default?
 
-use Test::More tests => 9;
-use Test::Deep;
-use X11::XCB qw(:all);
-use Data::Dumper;
-use Time::HiRes qw(sleep);
-use FindBin;
-use Digest::SHA1 qw(sha1_base64);
-use lib "$FindBin::Bin/lib";
 use i3test;
+use X11::XCB qw(:all);
+use List::Util qw(first);
 
 BEGIN {
-    use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX');
     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
 }
 
 my $x = X11::XCB::Connection->new;
 
-my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
-isa_ok($sock, 'IO::Socket::UNIX');
-
-# Switch to the nineth workspace
-$sock->write(i3test::format_ipc_command("9"));
-
-sleep 0.25;
+my $tmp = fresh_workspace;
 
 #####################################################################
 # Create two windows and put them in stacking mode
 #####################################################################
 
-my $top = i3test::open_standard_window($x);
-sleep 0.25;
-my $bottom = i3test::open_standard_window($x);
-sleep 0.25;
+cmd 'split v';
+
+my $top = open_standard_window($x);
+my $bottom = open_standard_window($x);
+
+my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
+is(@urgent, 0, 'no window got the urgent flag');
 
-$sock->write(i3test::format_ipc_command("s"));
-sleep 0.25;
+# cmd 'layout stacking';
 
 #####################################################################
 # Add the urgency hint, switch to a different workspace and back again
 #####################################################################
 $top->add_hint('urgency');
-sleep 1;
-
-$sock->write(i3test::format_ipc_command("1"));
-sleep 0.25;
-$sock->write(i3test::format_ipc_command("9"));
-sleep 0.25;
-$sock->write(i3test::format_ipc_command("1"));
-sleep 0.25;
-
-my $std = i3test::open_standard_window($x);
-sleep 0.25;
-$std->add_hint('urgency');
-sleep 1;
+sleep 0.5;
+
+@content = @{get_ws_content($tmp)};
+@urgent = grep { $_->{urgent} } @content;
+$top_info = first { $_->{window} == $top->id } @content;
+$bottom_info = first { $_->{window} == $bottom->id } @content;
+
+ok($top_info->{urgent}, 'top window is marked urgent');
+ok(!$bottom_info->{urgent}, 'bottom window is not marked urgent');
+is(@urgent, 1, 'exactly one window got the urgent flag');
+
+cmd '[id="' . $top->id . '"] focus';
+
+@urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
+is(@urgent, 0, 'no window got the urgent flag after focusing');
+
+$top->add_hint('urgency');
+sleep 0.5;
+
+@urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
+is(@urgent, 0, 'no window got the urgent flag after re-setting urgency hint');
+
+#####################################################################
+# Check if the workspace urgency hint gets set/cleared correctly
+#####################################################################
+my $ws = get_ws($tmp);
+ok(!$ws->{urgent}, 'urgent flag not set on workspace');
+
+my $otmp = fresh_workspace;
+
+$top->add_hint('urgency');
+sleep 0.5;
+
+$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');
+
+done_testing;