2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
21 subtest 'Window without WM_TAKE_FOCUS', sub {
24 my $window = open_window;
25 # sync_with_i3 will send a ClientMessage to i3 and i3 will send the same
26 # payload back to $window->id.
27 my $myrnd = sync_with_i3(
28 window_id => $window->id,
29 dont_wait_for_event => 1,
32 # We check whether the first received message has the correct payload — if
33 # not, the received message was a WM_TAKE_FOCUS message.
34 my $first_event_is_clientmessage;
35 wait_for_event 2, sub {
38 return 0 unless $event->{response_type} == 161;
40 my ($win, $rnd) = unpack "LL", $event->{data};
41 if (!defined($first_event_is_clientmessage)) {
42 $first_event_is_clientmessage = ($rnd == $myrnd);
44 return ($rnd == $myrnd);
47 ok($first_event_is_clientmessage, 'did not receive ClientMessage');
52 subtest 'Window with WM_TAKE_FOCUS', sub {
55 my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
57 my $window = open_window({
59 protocols => [ $take_focus ],
64 ok(wait_for_event(1, sub {
65 return 0 unless $_[0]->{response_type} == 161;
66 my ($data, $time) = unpack("L2", $_[0]->{data});
67 return ($data == $take_focus->id);
68 }), 'got ClientMessage with WM_TAKE_FOCUS atom');