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
19 # For more information on the protocol and input handling, see:
20 # http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
27 # sync_with_i3 will send a ClientMessage to i3 and i3 will send the same
28 # payload back to $window->id.
29 my $myrnd = sync_with_i3(
30 window_id => $window->id,
31 dont_wait_for_event => 1,
34 # We check whether the first received message has the correct payload — if
35 # not, the received message was a WM_TAKE_FOCUS message.
36 my $first_event_is_clientmessage;
37 wait_for_event 2, sub {
40 return 0 unless $event->{response_type} == 161;
42 my ($win, $rnd) = unpack "LL", $event->{data};
43 if (!defined($first_event_is_clientmessage)) {
44 $first_event_is_clientmessage = ($rnd == $myrnd);
46 return ($rnd == $myrnd);
49 return !$first_event_is_clientmessage;
52 subtest 'Window without WM_TAKE_FOCUS', sub {
53 my $ws = fresh_workspace;
55 my $window = open_window;
57 ok(!recv_take_focus($window), 'did not receive ClientMessage');
59 my $con = shift get_ws_content($ws);
60 ok($con->{focused}, 'con is focused');
65 # http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
66 # > Clients using the Globally Active model can only use a SetInputFocus request
67 # > to acquire the input focus when they do not already have it on receipt of one
68 # > of the following events:
71 # > * Passive-grabbed KeyPress
72 # > * Passive-grabbed KeyRelease
74 # Since managing a window happens on a MapNotify (which is absent from this
75 # list), the window cannot accept input focus, so we should not try to focus
77 subtest 'Window with WM_TAKE_FOCUS and without InputHint', sub {
78 my $ws = fresh_workspace;
80 my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
82 my $window = open_window({
84 protocols => [ $take_focus ],
87 # add an (empty) WM_HINTS property without the InputHint
88 $window->delete_hint('input');
92 ok(!recv_take_focus($window), 'did not receive ClientMessage');
94 my $con = shift get_ws_content($ws);
95 ok($con->{focused}, 'con is focused');
100 # If the InputHint is unspecified, i3 should use the simpler method of focusing
101 # the window directly rather than using the WM_TAKE_FOCUS protocol.
102 # XXX: The code paths for an unspecified and set InputHint are
103 # nearly identical presently, so this is currently used also as a proxy test
104 # for the latter case.
105 subtest 'Window with WM_TAKE_FOCUS and unspecified InputHint', sub {
106 my $ws = fresh_workspace;
108 my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
110 my $window = open_window({ protocols => [ $take_focus ] });
112 ok(!recv_take_focus($window), 'did not receive ClientMessage');
114 my $con = shift get_ws_content($ws);
115 ok($con->{focused}, 'con is focused');