]> git.sur5r.net Git - i3/i3/blob - testcases/t/158-wm_take_focus.t
t/158-wm_take_focus: use sync_with_i3 instead of a timeout
[i3/i3] / testcases / t / 158-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 i3test;
7
8 subtest 'Window without WM_TAKE_FOCUS', sub {
9     fresh_workspace;
10
11     my $window = open_window;
12     # sync_with_i3 will send a ClientMessage to i3 and receive one targeted to
13     # $window->id. If it receives WM_TAKE_FOCUS instead, it will return 0, thus
14     # the test will fail.
15     ok(sync_with_i3(window_id => $window->id), 'did not receive ClientMessage');
16
17     done_testing;
18 };
19
20 subtest 'Window with WM_TAKE_FOCUS', sub {
21     fresh_workspace;
22
23     my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
24
25     my $window = open_window({
26         dont_map => 1,
27         protocols => [ $take_focus ],
28     });
29
30     $window->map;
31
32     ok(wait_for_event(1, sub {
33         return 0 unless $_[0]->{response_type} == 161;
34         my ($data, $time) = unpack("L2", $_[0]->{data});
35         return ($data == $take_focus->id);
36     }), 'got ClientMessage with WM_TAKE_FOCUS atom');
37
38     done_testing;
39 };
40
41
42 done_testing;