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 # 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 # one on the first call of sync_with_i3. It will be re-used in all
# subsequent calls. # 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( $_sync_window = open_window(
rect => [ -15, -15, 10, 10 ], rect => [ -15, -15, 10, 10 ],
override_redirect => 1, override_redirect => 1,
); );
} }
my $window_id = delete $args{window_id};
$window_id //= $_sync_window->id;
my $root = $x->get_root_window(); my $root = $x->get_root_window();
# Generate a random number to identify this particular ClientMessage. # Generate a random number to identify this particular ClientMessage.
my $myrnd = int(rand(255)) + 1; my $myrnd = int(rand(255)) + 1;
@ -433,7 +437,7 @@ sub sync_with_i3 {
$root, # destination window $root, # destination window
$x->atom(name => 'I3_SYNC')->id, $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 $myrnd, # data[1]: a random value to identify the request
0, 0,
0, 0,

View File

@ -9,8 +9,10 @@ subtest 'Window without WM_TAKE_FOCUS', sub {
fresh_workspace; fresh_workspace;
my $window = open_window; my $window = open_window;
# sync_with_i3 will send a ClientMessage to i3 and receive one targeted to
ok(!wait_for_event(1, sub { $_[0]->{response_type} == 161 }), 'did not receive ClientMessage'); # $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; done_testing;
}; };