From 4821b13cae173c7ee598811f82c6502841a73a55 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 24 Sep 2011 13:07:05 +0100 Subject: [PATCH] tests: lib/i3test: provide wait_for_map and wait_for_unmap These functions should be used instead of calling wait_for_event directly when waiting for MAP_NOTIFY or UNMAP_NOTIFY --- testcases/t/lib/i3test.pm | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/testcases/t/lib/i3test.pm b/testcases/t/lib/i3test.pm index 2a51dad6..40e84044 100644 --- a/testcases/t/lib/i3test.pm +++ b/testcases/t/lib/i3test.pm @@ -36,6 +36,9 @@ our @EXPORT = qw( focused_ws get_socket_path launch_with_config + wait_for_event + wait_for_map + wait_for_unmap ); my $tester = Test::Builder->new(); @@ -99,12 +102,28 @@ sub wait_for_event { }; # Trigger timeout after $timeout seconds (can be fractional) - my $timeout = AE::timer $timeout, 0, sub { say STDERR "timeout"; $cv->send(0) }; + my $timeout = AE::timer $timeout, 0, sub { warn "timeout"; $cv->send(0) }; my $result = $cv->recv; return $result; } +# thin wrapper around wait_for_event which waits for MAP_NOTIFY +# make sure to include 'structure_notify' in the window’s event_mask attribute +sub wait_for_map { + my ($x) = @_; + wait_for_event $x, 1, sub { $_[0]->{response_type} == MAP_NOTIFY }; +} + +# Wrapper around wait_for_event which waits for UNMAP_NOTIFY. Also calls +# sync_with_i3 to make sure i3 also picked up and processed the UnmapNotify +# event. +sub wait_for_unmap { + my ($x) = @_; + wait_for_event $x, 1, sub { $_[0]->{response_type} == UNMAP_NOTIFY }; + sync_with_i3($x); +} + sub open_standard_window { my ($x, $color, $floating) = @_; @@ -286,7 +305,7 @@ sub sync_with_i3 { wait_for_event $x, 0.5, sub { $_[0]->{response_type} == MAP_NOTIFY }; } - my $root = $x->root->id; + my $root = $x->get_root_window(); # Generate a random number to identify this particular ClientMessage. my $myrnd = int(rand(255)) + 1; @@ -386,7 +405,7 @@ sub launch_with_config { # one test case. my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >>$ENV{LOGPATH} 2>&1"; my $process = Proc::Background->new($i3cmd); - sleep 1; + sleep 1.25; # force update of the cached socket path in lib/i3test get_socket_path(0); -- 2.39.5