From 7a672a9d41b60201534c17bc706f9c46dd20ad66 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 3 Oct 2017 10:02:41 +0200 Subject: [PATCH] i3test: blockingly wait for events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit …as polling the xcb file descriptor directly is not reliable. --- testcases/lib/i3test.pm.in | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/testcases/lib/i3test.pm.in b/testcases/lib/i3test.pm.in index 429e51d4..ed239241 100644 --- a/testcases/lib/i3test.pm.in +++ b/testcases/lib/i3test.pm.in @@ -193,29 +193,11 @@ received, etc. sub wait_for_event { my ($timeout, $cb) = @_; - my $cv = AE::cv; - $x->flush; - # unfortunately, there is no constant for this - my $ae_read = 0; - - my $guard = AE::io $x->get_file_descriptor, $ae_read, sub { - while (defined(my $event = $x->poll_for_event)) { - if ($cb->($event)) { - $cv->send(1); - last; - } - } - }; - - # Trigger timeout after $timeout seconds (can be fractional) - my $t = AE::timer $timeout, 0, sub { warn "timeout ($timeout secs)"; $cv->send(0) }; - - my $result = $cv->recv; - undef $t; - undef $guard; - return $result; + while (defined(my $event = $x->wait_for_event)) { + return 1 if $cb->($event); + } } =head2 wait_for_map($window) -- 2.39.5