tests: refactor t/58-wm_take_focus to use wait_for_event

This commit is contained in:
Michael Stapelberg 2011-09-24 15:38:31 +01:00
parent de5286da59
commit 378611c11c

View File

@ -7,105 +7,35 @@ use X11::XCB qw(:all);
use i3test; use i3test;
use v5.10; use v5.10;
BEGIN {
use_ok('EV');
use_ok('AnyEvent');
use_ok('X11::XCB::Window');
use_ok('X11::XCB::Event::Generic');
use_ok('X11::XCB::Event::MapNotify');
use_ok('X11::XCB::Event::ClientMessage');
}
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
subtest 'Window without WM_TAKE_FOCUS', sub { subtest 'Window without WM_TAKE_FOCUS', sub {
fresh_workspace;
my $tmp = fresh_workspace; my $window = open_window($x);
my $window = $x->root->create_child( ok(!wait_for_event($x, 1, sub { $_[0]->{response_type} == 161 }), 'did not receive ClientMessage');
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30 ],
background_color => '#00ff00',
event_mask => [ 'structure_notify' ],
);
$window->name('Window 1');
$window->map;
my $cv = AE::cv;
my $prep = EV::prepare sub {
$x->flush;
};
my $check = EV::check sub {
while (defined(my $event = $x->poll_for_event)) {
if ($event->response_type == 161) {
# clientmessage
$cv->send(0);
}
}
};
my $w = EV::io $x->get_file_descriptor, EV::READ, sub {
# do nothing, we only need this watcher so that EV picks up the events
};
# Trigger timeout after 1 second
my $t = AE::timer 1, 0, sub {
$cv->send(1);
};
my $result = $cv->recv;
ok($result, 'cv result');
done_testing; done_testing;
}; };
subtest 'Window with WM_TAKE_FOCUS', sub { subtest 'Window with WM_TAKE_FOCUS', sub {
fresh_workspace;
my $tmp = fresh_workspace; my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
my $window = $x->root->create_child( my $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 0, 30, 30 ], protocols => [ $take_focus ],
background_color => '#00ff00', });
event_mask => [ 'structure_notify' ],
protocols => [ $x->atom(name => 'WM_TAKE_FOCUS') ],
);
$window->name('Window 1');
$window->map; $window->map;
my $cv = AE::cv; ok(wait_for_event($x, 1, sub {
return 0 unless $_[0]->{response_type} == 161;
my $prep = EV::prepare sub { my ($data, $time) = unpack("L2", $_[0]->{data});
$x->flush; return ($data == $take_focus->id);
}; }), 'got ClientMessage with WM_TAKE_FOCUS atom');
my $check = EV::check sub {
while (defined(my $event = $x->poll_for_event)) {
if ($event->response_type == 161) {
$cv->send($event->data);
}
}
};
my $w = EV::io $x->get_file_descriptor, EV::READ, sub {
# do nothing, we only need this watcher so that EV picks up the events
};
my $t = AE::timer 1, 0, sub {
say "timer!";
$cv->send(undef);
};
my $result = $cv->recv;
ok(defined($result), 'got a ClientMessage');
if (defined($result)) {
my ($data, $time) = unpack("L2", $result);
is($data, $x->atom(name => 'WM_TAKE_FOCUS')->id, 'first uint32_t contains WM_TAKE_FOCUS atom');
}
done_testing; done_testing;
}; };