2 # vim:ts=4:sw=4:expandtab
4 # Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
13 use_ok('X11::XCB::Window');
14 use_ok('X11::XCB::Event::Generic');
15 use_ok('X11::XCB::Event::MapNotify');
16 use_ok('X11::XCB::Event::ClientMessage');
19 my $x = X11::XCB::Connection->new;
20 my $i3 = i3(get_socket_path());
22 subtest 'Window without WM_TAKE_FOCUS', sub {
24 my $tmp = fresh_workspace;
26 my $window = $x->root->create_child(
27 class => WINDOW_CLASS_INPUT_OUTPUT,
28 rect => [ 0, 0, 30, 30 ],
29 background_color => '#00ff00',
30 event_mask => [ 'structure_notify' ],
33 $window->name('Window 1');
38 my $prep = EV::prepare sub {
42 my $check = EV::check sub {
43 while (defined(my $event = $x->poll_for_event)) {
44 if ($event->response_type == 161) {
51 my $w = EV::io $x->get_file_descriptor, EV::READ, sub {
52 # do nothing, we only need this watcher so that EV picks up the events
55 # Trigger timeout after 1 second
56 my $t = AE::timer 1, 0, sub {
60 my $result = $cv->recv;
61 ok($result, 'cv result');
66 subtest 'Window with WM_TAKE_FOCUS', sub {
68 my $tmp = fresh_workspace;
70 my $window = $x->root->create_child(
71 class => WINDOW_CLASS_INPUT_OUTPUT,
72 rect => [ 0, 0, 30, 30 ],
73 background_color => '#00ff00',
74 event_mask => [ 'structure_notify' ],
75 protocols => [ $x->atom(name => 'WM_TAKE_FOCUS') ],
78 $window->name('Window 1');
83 my $prep = EV::prepare sub {
87 my $check = EV::check sub {
88 while (defined(my $event = $x->poll_for_event)) {
89 if ($event->response_type == 161) {
90 $cv->send($event->data);
95 my $w = EV::io $x->get_file_descriptor, EV::READ, sub {
96 # do nothing, we only need this watcher so that EV picks up the events
99 my $t = AE::timer 1, 0, sub {
104 my $result = $cv->recv;
105 ok(defined($result), 'got a ClientMessage');
106 if (defined($result)) {
107 my ($data, $time) = unpack("L2", $result);
108 is($data, $x->atom(name => 'WM_TAKE_FOCUS')->id, 'first uint32_t contains WM_TAKE_FOCUS atom');