t/158-wm_take_focus: use sync_with_i3 instead of a timeout

This commit is contained in:
Michael Stapelberg 2012-02-21 14:37:55 +01:00
parent 41400d8a16
commit d085e88d02
2 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -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;
};