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)
|
|
|
|
|
2018-12-14 19:39:34 +01:00
|
|
|
use i3test i3_config => <<EOT;
|
|
|
|
# i3 config file (v4)
|
|
|
|
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
|
|
|
|
|
|
|
# fake-1 under fake-0 to not interfere with left/right wraping
|
|
|
|
fake-outputs 1024x768+0+0,1024x768+0+1024
|
|
|
|
workspace X output fake-1
|
|
|
|
EOT
|
2014-02-22 11:52:01 +01:00
|
|
|
|
|
|
|
################################
|
|
|
|
# Window focus event
|
|
|
|
################################
|
|
|
|
|
2018-12-14 19:39:34 +01:00
|
|
|
my $ws = fresh_workspace(output => 0);
|
2014-02-22 11:52:01 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-12-14 19:37:29 +01:00
|
|
|
sub kill_subtest {
|
|
|
|
my ($cmd, $name) = @_;
|
|
|
|
|
|
|
|
my $focus = AnyEvent->condvar;
|
|
|
|
|
|
|
|
my @events = events_for(
|
|
|
|
sub { cmd $cmd },
|
|
|
|
'window');
|
|
|
|
|
|
|
|
is(scalar @events, 1, 'Received 1 event');
|
|
|
|
is($events[0]->{change}, 'close', 'Close event received');
|
|
|
|
is($events[0]->{container}->{name}, $name, "$name closed");
|
|
|
|
}
|
|
|
|
|
2017-10-03 09:58:10 +02:00
|
|
|
subtest 'focus left (1)', \&focus_subtest, 'focus left', $win1->name;
|
|
|
|
subtest 'focus left (2)', \&focus_subtest, 'focus left', $win0->name;
|
|
|
|
subtest 'focus right (1)', \&focus_subtest, 'focus right', $win1->name;
|
|
|
|
subtest 'focus right (2)', \&focus_subtest, 'focus right', $win2->name;
|
|
|
|
subtest 'focus right (3)', \&focus_subtest, 'focus right', $win0->name;
|
|
|
|
subtest 'focus left', \&focus_subtest, 'focus left', $win2->name;
|
2018-12-14 19:37:29 +01:00
|
|
|
subtest 'kill doesn\'t produce focus event', \&kill_subtest, '[id=' . $win1->id . '] kill', $win1->name;
|
2017-09-24 15:40:30 +02:00
|
|
|
|
2018-12-14 19:39:34 +01:00
|
|
|
# See issue #3562. We need to switch to an existing workspace on the second
|
|
|
|
# output to trigger the bug.
|
|
|
|
cmd 'workspace X';
|
|
|
|
subtest 'workspace focus', \&focus_subtest, "workspace $ws", $win2->name;
|
|
|
|
|
|
|
|
sub scratchpad_subtest {
|
|
|
|
my ($cmd, $name) = @_;
|
|
|
|
|
|
|
|
my $focus = AnyEvent->condvar;
|
|
|
|
|
|
|
|
my @events = events_for(
|
|
|
|
sub { cmd $cmd },
|
|
|
|
'window');
|
|
|
|
|
|
|
|
is(scalar @events, 2, 'Received 2 events');
|
|
|
|
is($events[0]->{change}, 'move', 'Move event received');
|
|
|
|
is($events[0]->{container}->{nodes}->[0]->{name}, $name, "$name moved");
|
|
|
|
is($events[1]->{change}, 'focus', 'Focus event received');
|
|
|
|
is($events[1]->{container}->{name}, $name, "$name focused");
|
|
|
|
}
|
|
|
|
|
|
|
|
fresh_workspace;
|
|
|
|
my $win = open_window;
|
|
|
|
cmd 'move scratchpad';
|
|
|
|
subtest 'scratchpad', \&scratchpad_subtest, '[id=' . $win->id . '] scratchpad show', $win->name;
|
|
|
|
|
2014-02-22 11:52:01 +01:00
|
|
|
done_testing;
|