2011-03-19 02:21:46 +01:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
2012-09-10 14:09:01 +02:00
|
|
|
# Please read the following documents before working on tests:
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/testsuite.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/lib-i3test.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/ipc.html
|
2012-09-10 14:09:01 +02:00
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
#
|
2011-03-19 02:21:46 +01:00
|
|
|
# Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
|
|
|
|
#
|
2014-04-10 19:28:14 +02:00
|
|
|
# For more information on the protocol and input handling, see:
|
2017-09-24 10:19:50 +02:00
|
|
|
# https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
|
2014-04-10 19:28:14 +02:00
|
|
|
#
|
2011-03-19 02:21:46 +01:00
|
|
|
use i3test;
|
|
|
|
|
2014-04-10 19:28:14 +02:00
|
|
|
sub recv_take_focus {
|
|
|
|
my ($window) = @_;
|
2011-03-19 02:21:46 +01:00
|
|
|
|
2014-04-09 21:47:32 +02:00
|
|
|
# sync_with_i3 will send a ClientMessage to i3 and i3 will send the same
|
|
|
|
# payload back to $window->id.
|
|
|
|
my $myrnd = sync_with_i3(
|
|
|
|
window_id => $window->id,
|
|
|
|
dont_wait_for_event => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
# We check whether the first received message has the correct payload — if
|
|
|
|
# not, the received message was a WM_TAKE_FOCUS message.
|
|
|
|
my $first_event_is_clientmessage;
|
|
|
|
wait_for_event 2, sub {
|
|
|
|
my ($event) = @_;
|
|
|
|
# TODO: const
|
|
|
|
return 0 unless $event->{response_type} == 161;
|
|
|
|
|
|
|
|
my ($win, $rnd) = unpack "LL", $event->{data};
|
|
|
|
if (!defined($first_event_is_clientmessage)) {
|
|
|
|
$first_event_is_clientmessage = ($rnd == $myrnd);
|
|
|
|
}
|
|
|
|
return ($rnd == $myrnd);
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:28:14 +02:00
|
|
|
return !$first_event_is_clientmessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
subtest 'Window without WM_TAKE_FOCUS', sub {
|
2015-04-26 04:43:46 +02:00
|
|
|
my $ws = fresh_workspace;
|
2014-04-10 19:28:14 +02:00
|
|
|
|
|
|
|
my $window = open_window;
|
|
|
|
|
|
|
|
ok(!recv_take_focus($window), 'did not receive ClientMessage');
|
2016-07-25 02:43:56 +02:00
|
|
|
ok(is_net_wm_state_focused($window), '_NET_WM_STATE_FOCUSED set');
|
2011-05-25 20:16:14 +02:00
|
|
|
|
2016-09-26 17:29:27 +02:00
|
|
|
my ($nodes) = get_ws_content($ws);
|
|
|
|
my $con = shift @$nodes;
|
2015-04-26 04:43:46 +02:00
|
|
|
ok($con->{focused}, 'con is focused');
|
|
|
|
|
2011-05-25 20:16:14 +02:00
|
|
|
done_testing;
|
2011-03-19 02:21:46 +01:00
|
|
|
};
|
|
|
|
|
2017-09-24 10:19:50 +02:00
|
|
|
# https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
|
2014-06-17 08:49:39 +02:00
|
|
|
# > Clients using the Globally Active model can only use a SetInputFocus request
|
|
|
|
# > to acquire the input focus when they do not already have it on receipt of one
|
|
|
|
# > of the following events:
|
|
|
|
# > * ButtonPress
|
|
|
|
# > * ButtonRelease
|
|
|
|
# > * Passive-grabbed KeyPress
|
|
|
|
# > * Passive-grabbed KeyRelease
|
|
|
|
#
|
|
|
|
# Since managing a window happens on a MapNotify (which is absent from this
|
|
|
|
# list), the window cannot accept input focus, so we should not try to focus
|
|
|
|
# the window at all.
|
2014-04-10 19:28:14 +02:00
|
|
|
subtest 'Window with WM_TAKE_FOCUS and without InputHint', sub {
|
2015-04-26 04:43:46 +02:00
|
|
|
my $ws = fresh_workspace;
|
2011-03-19 02:21:46 +01:00
|
|
|
|
2011-09-24 16:38:31 +02:00
|
|
|
my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
|
2011-03-19 02:21:46 +01:00
|
|
|
|
2011-11-22 00:47:32 +01:00
|
|
|
my $window = open_window({
|
2011-09-24 16:38:31 +02:00
|
|
|
dont_map => 1,
|
|
|
|
protocols => [ $take_focus ],
|
|
|
|
});
|
2011-03-19 02:21:46 +01:00
|
|
|
|
2014-04-10 19:28:14 +02:00
|
|
|
# add an (empty) WM_HINTS property without the InputHint
|
|
|
|
$window->delete_hint('input');
|
|
|
|
|
2011-03-19 02:21:46 +01:00
|
|
|
$window->map;
|
|
|
|
|
2014-06-17 08:49:39 +02:00
|
|
|
ok(!recv_take_focus($window), 'did not receive ClientMessage');
|
2016-07-25 02:43:56 +02:00
|
|
|
ok(is_net_wm_state_focused($window), '_NET_WM_STATE_FOCUSED set');
|
2011-05-25 20:16:14 +02:00
|
|
|
|
2016-09-26 17:29:27 +02:00
|
|
|
my ($nodes) = get_ws_content($ws);
|
|
|
|
my $con = shift @$nodes;
|
2015-04-26 04:43:46 +02:00
|
|
|
ok($con->{focused}, 'con is focused');
|
|
|
|
|
2011-05-25 20:16:14 +02:00
|
|
|
done_testing;
|
2011-03-19 02:21:46 +01:00
|
|
|
};
|
|
|
|
|
2014-04-10 19:28:14 +02:00
|
|
|
# If the InputHint is unspecified, i3 should use the simpler method of focusing
|
|
|
|
# the window directly rather than using the WM_TAKE_FOCUS protocol.
|
|
|
|
# XXX: The code paths for an unspecified and set InputHint are
|
|
|
|
# nearly identical presently, so this is currently used also as a proxy test
|
|
|
|
# for the latter case.
|
|
|
|
subtest 'Window with WM_TAKE_FOCUS and unspecified InputHint', sub {
|
2015-04-26 04:43:46 +02:00
|
|
|
my $ws = fresh_workspace;
|
2014-04-10 19:28:14 +02:00
|
|
|
|
|
|
|
my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
|
|
|
|
|
|
|
|
my $window = open_window({ protocols => [ $take_focus ] });
|
|
|
|
|
|
|
|
ok(!recv_take_focus($window), 'did not receive ClientMessage');
|
2016-07-25 02:43:56 +02:00
|
|
|
ok(is_net_wm_state_focused($window), '_NET_WM_STATE_FOCUSED set');
|
2014-04-10 19:28:14 +02:00
|
|
|
|
2016-09-26 17:29:27 +02:00
|
|
|
my ($nodes) = get_ws_content($ws);
|
|
|
|
my $con = shift @$nodes;
|
2015-04-26 04:43:46 +02:00
|
|
|
ok($con->{focused}, 'con is focused');
|
|
|
|
|
2014-04-10 19:28:14 +02:00
|
|
|
done_testing;
|
|
|
|
};
|
2011-03-19 02:21:46 +01:00
|
|
|
|
|
|
|
done_testing;
|