]> git.sur5r.net Git - i3/i3/blob - testcases/t/158-wm_take_focus.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 158-wm_take_focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
18 #
19 use i3test;
20
21 subtest 'Window without WM_TAKE_FOCUS', sub {
22     fresh_workspace;
23
24     my $window = open_window;
25     # sync_with_i3 will send a ClientMessage to i3 and receive one targeted to
26     # $window->id. If it receives WM_TAKE_FOCUS instead, it will return 0, thus
27     # the test will fail.
28     ok(sync_with_i3(window_id => $window->id), 'did not receive ClientMessage');
29
30     done_testing;
31 };
32
33 subtest 'Window with WM_TAKE_FOCUS', sub {
34     fresh_workspace;
35
36     my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
37
38     my $window = open_window({
39         dont_map => 1,
40         protocols => [ $take_focus ],
41     });
42
43     $window->map;
44
45     ok(wait_for_event(1, sub {
46         return 0 unless $_[0]->{response_type} == 161;
47         my ($data, $time) = unpack("L2", $_[0]->{data});
48         return ($data == $take_focus->id);
49     }), 'got ClientMessage with WM_TAKE_FOCUS atom');
50
51     done_testing;
52 };
53
54
55 done_testing;