use i3test;
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;
subtest 'Window without WM_TAKE_FOCUS', sub {
+ fresh_workspace;
- my $tmp = fresh_workspace;
-
- my $window = $x->root->create_child(
- 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 $window = open_window($x);
- 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');
+ ok(!wait_for_event($x, 1, sub { $_[0]->{response_type} == 161 }), 'did not receive ClientMessage');
done_testing;
};
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(
- class => WINDOW_CLASS_INPUT_OUTPUT,
- rect => [ 0, 0, 30, 30 ],
- background_color => '#00ff00',
- event_mask => [ 'structure_notify' ],
- protocols => [ $x->atom(name => 'WM_TAKE_FOCUS') ],
- );
+ my $window = open_window($x, {
+ dont_map => 1,
+ protocols => [ $take_focus ],
+ });
- $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) {
- $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');
- }
+ ok(wait_for_event($x, 1, sub {
+ return 0 unless $_[0]->{response_type} == 161;
+ my ($data, $time) = unpack("L2", $_[0]->{data});
+ return ($data == $take_focus->id);
+ }), 'got ClientMessage with WM_TAKE_FOCUS atom');
done_testing;
};