From: Michael Stapelberg Date: Tue, 21 Feb 2012 13:37:55 +0000 (+0100) Subject: t/158-wm_take_focus: use sync_with_i3 instead of a timeout X-Git-Tag: 4.2~54 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d085e88d02596ad531190ccb2b16377fba49c022;p=i3%2Fi3 t/158-wm_take_focus: use sync_with_i3 instead of a timeout --- diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index 58d9b9fa..f7be1b66 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -414,13 +414,17 @@ sub sync_with_i3 { # Since we need a (mapped) window for receiving a ClientMessage, we create # one on the first call of sync_with_i3. It will be re-used in all # subsequent calls. - if (!defined($_sync_window) || exists($args{no_cache})) { + if (!exists($args{window_id}) && + (!defined($_sync_window) || exists($args{no_cache}))) { $_sync_window = open_window( rect => [ -15, -15, 10, 10 ], override_redirect => 1, ); } + my $window_id = delete $args{window_id}; + $window_id //= $_sync_window->id; + my $root = $x->get_root_window(); # Generate a random number to identify this particular ClientMessage. my $myrnd = int(rand(255)) + 1; @@ -433,7 +437,7 @@ sub sync_with_i3 { $root, # destination window $x->atom(name => 'I3_SYNC')->id, - $_sync_window->id, # data[0]: our own window id + $window_id, # data[0]: our own window id $myrnd, # data[1]: a random value to identify the request 0, 0, diff --git a/testcases/t/158-wm_take_focus.t b/testcases/t/158-wm_take_focus.t index 94476bbd..c4d30575 100644 --- a/testcases/t/158-wm_take_focus.t +++ b/testcases/t/158-wm_take_focus.t @@ -9,8 +9,10 @@ subtest 'Window without WM_TAKE_FOCUS', sub { fresh_workspace; my $window = open_window; - - ok(!wait_for_event(1, sub { $_[0]->{response_type} == 161 }), 'did not receive ClientMessage'); + # sync_with_i3 will send a ClientMessage to i3 and receive one targeted to + # $window->id. If it receives WM_TAKE_FOCUS instead, it will return 0, thus + # the test will fail. + ok(sync_with_i3(window_id => $window->id), 'did not receive ClientMessage'); done_testing; };