2014-02-22 11:52:01 +01:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
|
|
|
# Please read the following documents before working on tests:
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/testsuite.html
|
2014-02-22 11:52:01 +01:00
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/lib-i3test.html
|
2014-02-22 11:52:01 +01:00
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/ipc.html
|
2014-02-22 11:52:01 +01:00
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
|
|
|
|
use i3test;
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Window focus event
|
|
|
|
################################
|
|
|
|
|
|
|
|
cmd 'split h';
|
|
|
|
|
|
|
|
my $win0 = open_window;
|
|
|
|
my $win1 = open_window;
|
|
|
|
my $win2 = open_window;
|
|
|
|
|
|
|
|
# ensure the rightmost window contains input focus
|
2017-09-24 15:40:30 +02:00
|
|
|
cmd '[id="' . $win2->id . '"] focus';
|
2014-02-22 11:52:01 +01:00
|
|
|
is($x->input_focus, $win2->id, "Window 2 focused");
|
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
sub focus_subtest {
|
|
|
|
my ($cmd, $name) = @_;
|
2014-02-22 11:52:01 +01:00
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
my $focus = AnyEvent->condvar;
|
2014-02-22 11:52:01 +01:00
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
my @events = events_for(
|
|
|
|
sub { cmd $cmd },
|
|
|
|
'window');
|
2014-02-22 11:52:01 +01:00
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
is(scalar @events, 1, 'Received 1 event');
|
|
|
|
is($events[0]->{change}, 'focus', 'Focus event received');
|
|
|
|
is($events[0]->{container}->{name}, $name, "$name focused");
|
2014-02-22 11:52:01 +01:00
|
|
|
}
|
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
subtest 'focus left (1)', \&focus_subtest, 'focus left', 'Window 1';
|
|
|
|
subtest 'focus left (2)', \&focus_subtest, 'focus left', 'Window 0';
|
|
|
|
subtest 'focus right (1)', \&focus_subtest, 'focus right', 'Window 1';
|
|
|
|
subtest 'focus right (2)', \&focus_subtest, 'focus right', 'Window 2';
|
|
|
|
subtest 'focus right (3)', \&focus_subtest, 'focus right', 'Window 0';
|
|
|
|
subtest 'focus left', \&focus_subtest, 'focus left', 'Window 2';
|
|
|
|
|
2014-02-22 11:52:01 +01:00
|
|
|
done_testing;
|