2011-03-18 21:21:46 -04:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
2012-09-10 08:09:01 -04:00
|
|
|
# Please read the following documents before working on tests:
|
|
|
|
# • http://build.i3wm.org/docs/testsuite.html
|
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
|
|
|
# • http://build.i3wm.org/docs/lib-i3test.html
|
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
|
|
|
# • http://build.i3wm.org/docs/ipc.html
|
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
#
|
2011-03-18 21:21:46 -04:00
|
|
|
# Tests if the WM_TAKE_FOCUS protocol is correctly handled by i3
|
|
|
|
#
|
|
|
|
use i3test;
|
|
|
|
|
|
|
|
subtest 'Window without WM_TAKE_FOCUS', sub {
|
2011-09-24 10:38:31 -04:00
|
|
|
fresh_workspace;
|
2011-03-18 21:21:46 -04:00
|
|
|
|
2011-11-21 18:47:32 -05:00
|
|
|
my $window = open_window;
|
2014-04-09 15:47:32 -04: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);
|
|
|
|
};
|
|
|
|
|
|
|
|
ok($first_event_is_clientmessage, 'did not receive ClientMessage');
|
2011-05-25 14:16:14 -04:00
|
|
|
|
|
|
|
done_testing;
|
2011-03-18 21:21:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
subtest 'Window with WM_TAKE_FOCUS', sub {
|
2011-09-24 10:38:31 -04:00
|
|
|
fresh_workspace;
|
2011-03-18 21:21:46 -04:00
|
|
|
|
2011-09-24 10:38:31 -04:00
|
|
|
my $take_focus = $x->atom(name => 'WM_TAKE_FOCUS');
|
2011-03-18 21:21:46 -04:00
|
|
|
|
2011-11-21 18:47:32 -05:00
|
|
|
my $window = open_window({
|
2011-09-24 10:38:31 -04:00
|
|
|
dont_map => 1,
|
|
|
|
protocols => [ $take_focus ],
|
|
|
|
});
|
2011-03-18 21:21:46 -04:00
|
|
|
|
|
|
|
$window->map;
|
|
|
|
|
2011-11-21 17:37:04 -05:00
|
|
|
ok(wait_for_event(1, sub {
|
2011-09-24 10:38:31 -04:00
|
|
|
return 0 unless $_[0]->{response_type} == 161;
|
|
|
|
my ($data, $time) = unpack("L2", $_[0]->{data});
|
|
|
|
return ($data == $take_focus->id);
|
|
|
|
}), 'got ClientMessage with WM_TAKE_FOCUS atom');
|
2011-05-25 14:16:14 -04:00
|
|
|
|
|
|
|
done_testing;
|
2011-03-18 21:21:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
done_testing;
|