]> git.sur5r.net Git - i3/i3/blob - testcases/t/58-wm_take_focus.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 58-wm_take_focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
5 #
6 use X11::XCB qw(:all);
7 use i3test;
8 use v5.10;
9
10 BEGIN {
11     use_ok('EV');
12     use_ok('AnyEvent');
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');
17 }
18
19 my $x = X11::XCB::Connection->new;
20 my $i3 = i3(get_socket_path());
21
22 subtest 'Window without WM_TAKE_FOCUS', sub {
23
24     my $tmp = fresh_workspace;
25
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' ],
31     );
32
33     $window->name('Window 1');
34     $window->map;
35
36     my $cv = AE::cv;
37
38     my $prep = EV::prepare sub {
39         $x->flush;
40     };
41
42     my $check = EV::check sub {
43         while (defined(my $event = $x->poll_for_event)) {
44             if ($event->response_type == 161) {
45                 # clientmessage
46                 $cv->send(0);
47             }
48         }
49     };
50
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
53     };
54
55     # Trigger timeout after 1 second
56     my $t = AE::timer 1, 0, sub {
57         $cv->send(1);
58     };
59
60     my $result = $cv->recv;
61     ok($result, 'cv result');
62
63     done_testing;
64 };
65
66 subtest 'Window with WM_TAKE_FOCUS', sub {
67
68     my $tmp = fresh_workspace;
69
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') ],
76     );
77
78     $window->name('Window 1');
79     $window->map;
80
81     my $cv = AE::cv;
82
83     my $prep = EV::prepare sub {
84         $x->flush;
85     };
86
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);
91             }
92         }
93     };
94
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
97     };
98
99     my $t = AE::timer 1, 0, sub {
100         say "timer!";
101         $cv->send(undef);
102     };
103
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');
109     }
110
111     done_testing;
112 };
113
114
115 done_testing;