Merge pull request #3407 from orestisfl/tree_next

tree_next refactor & enhancements
This commit is contained in:
Ingo Bürk
2019-10-15 13:47:24 +02:00
committed by GitHub
17 changed files with 722 additions and 183 deletions

View File

@ -35,9 +35,13 @@ my $bottom = open_window;
# end sleeping for half a second to make sure i3 reacted
#
sub focus_after {
my $msg = shift;
my ($msg, $win_id) = @_;
cmd $msg;
if (defined($win_id)) {
cmd "[id=$win_id] $msg";
} else {
cmd $msg;
}
return $x->input_focus;
}
@ -50,6 +54,14 @@ is($focus, $mid->id, "Middle window focused");
$focus = focus_after('focus up');
is($focus, $top->id, "Top window focused");
# Same using command criteria
$focus = focus_after('focus up', $bottom->id);
is($focus, $mid->id, "Middle window focused");
cmd 'focus down';
$focus = focus_after('focus up', $mid->id);
is($focus, $top->id, "Top window focused");
#####################################################################
# Test focus wrapping
#####################################################################

View File

@ -0,0 +1,72 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://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)
#
# Test focus next|prev
# Ticket: #2587
use i3test;
cmp_tree(
msg => "cmd 'prev' selects leaf 1/2",
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c* d T[e f g]]',
cb => sub {
cmd 'focus prev';
});
cmp_tree(
msg => "cmd 'prev' selects leaf 2/2",
layout_before => 'S[a b] V[c* d T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
cb => sub {
# c* -> V -> b*
cmd 'focus parent, focus prev';
});
cmp_tree(
msg => "cmd 'prev sibling' selects leaf again",
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c* d T[e f g]]',
cb => sub {
cmd 'focus prev sibling';
});
cmp_tree(
msg => "cmd 'next' selects leaf",
# Notice that g is the last to open before focus moves to d*
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g*]]',
cb => sub {
cmd 'focus next';
});
cmp_tree(
msg => "cmd 'next sibling' selects parent 1/2",
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c d T*[e f g]]',
cb => sub {
cmd 'focus next sibling';
});
cmp_tree(
msg => "cmd 'next sibling' selects parent 2/2",
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V*[c d T[e f g]]',
cb => sub {
# b* -> S* -> V*
cmd 'focus parent, focus next sibling';
});
done_testing;

View File

@ -0,0 +1,345 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://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)
#
# Tests focus_wrapping yes|no|force|workspace with cmp_tree
# Tickets: #2180 #2352
use i3test i3_autostart => 0;
my $pid = 0;
sub focus_wrapping {
my ($setting) = @_;
print "--------------------------------------------------------------------------------\n";
print " focus_wrapping $setting\n";
print "--------------------------------------------------------------------------------\n";
exit_gracefully($pid) if $pid > 0;
my $config = <<"EOT";
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
fake-outputs 1024x768+0+0,1024x768+1024+0,1024x768+1024+768,1024x768+0+768
workspace left-top output fake-0
workspace right-top output fake-1
workspace right-bottom output fake-2
workspace left-bottom output fake-3
focus_wrapping $setting
EOT
$pid = launch_with_config($config);
}
###############################################################################
focus_wrapping('yes');
###############################################################################
cmp_tree(
msg => 'Normal focus up - should work for all options',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Normal focus right - should work for all options',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b] V[c d T[e f* g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
});
cmp_tree(
msg => 'Focus leaves workspace vertically',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus down';
is(focused_ws, 'left-bottom', 'Correct workspace focused');
});
cmp_tree(
msg => 'Focus wraps vertically',
layout_before => 'S[a* b] V[c d T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Focus wraps horizontally',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g*]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Directional focus in the orientation of the parent does not wrap',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Focus leaves workspace horizontally',
layout_before => 'S[a b] V[c d* T[e f g*]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
is(focused_ws, 'right-top', 'Correct workspace focused');
});
###############################################################################
focus_wrapping('no');
# See issue #2352
###############################################################################
cmp_tree(
msg => 'Normal focus up - should work for all options',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Normal focus right - should work for all options',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b] V[c d T[e f* g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
});
cmp_tree(
msg => 'Focus leaves workspace vertically',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus down';
is(focused_ws, 'left-bottom', 'Correct workspace focused');
});
cmp_tree(
msg => 'Focus does not wrap vertically',
layout_before => 'S[a* b] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Focus does not wrap horizontally',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Directional focus in the orientation of the parent does not wrap',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Focus leaves workspace horizontally',
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
is(focused_ws, 'right-top', 'Correct workspace focused');
});
###############################################################################
focus_wrapping('force');
###############################################################################
cmp_tree(
msg => 'Normal focus up - should work for all options',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Normal focus right - should work for all options',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b] V[c d T[e f* g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
});
cmp_tree(
msg => 'Focus does not leave workspace vertically',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus down';
is(focused_ws, 'left-top', 'Correct workspace focused');
});
cmp_tree(
msg => 'Focus wraps vertically',
layout_before => 'S[a* b] V[c d T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Focus wraps horizontally (focus direction different than parent\'s orientation)',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g*]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Directional focus in the orientation of the parent wraps',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b] V[c d T[e f g*]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree( # 'focus_wrapping force' exclusive test
msg => 'But leaves when selecting parent',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus parent, focus right';
});
cmp_tree(
msg => 'Focus does not leave workspace horizontally',
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
is(focused_ws, 'left-top', 'Correct workspace focused');
});
cmp_tree( # 'focus_wrapping force|workspace' exclusive test
msg => 'But leaves when selecting parent x2',
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus parent, focus parent, focus right';
is(focused_ws, 'right-top', 'Correct workspace focused');
});
###############################################################################
focus_wrapping('workspace');
# See issue #2180
###############################################################################
cmp_tree(
msg => 'Normal focus up - should work for all options',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Normal focus right - should work for all options',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b] V[c d T[e f* g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
});
cmp_tree(
msg => 'Focus does not leave workspace vertically',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a* b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus down';
is(focused_ws, 'left-top', 'Correct workspace focused');
});
cmp_tree(
msg => 'Focus wraps vertically',
layout_before => 'S[a* b] V[c d T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus up';
});
cmp_tree(
msg => 'Focus wraps horizontally',
layout_before => 'S[a b*] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g*]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Directional focus in the orientation of the parent does not wrap',
layout_before => 'S[a b] V[c d T[e* f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus left';
});
cmp_tree(
msg => 'Focus does not leave workspace horizontally',
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b*] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus right';
is(focused_ws, 'left-top', 'Correct workspace focused');
});
cmp_tree( # 'focus_wrapping force|workspace' exclusive test
msg => 'But leaves when selecting parent x2',
layout_before => 'S[a b] V[c d* T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
cmd 'focus parent, focus parent, focus right';
is(focused_ws, 'right-top', 'Correct workspace focused');
});
cmp_tree( # 'focus_wrapping workspace' exclusive test
msg => 'x',
layout_before => 'S[a* b] V[c d T[e f g]]',
layout_after => 'S[a b] V[c d T[e f g]]',
ws => 'left-top',
cb => sub {
subtest 'random tests' => sub {
my @directions = qw(left right top down);
for my $i (1 .. 50) {
my $direction = $directions[rand @directions];
cmd "focus $direction";
return unless is(focused_ws, 'left-top', "'focus $direction' did not change workspace");
}
};
});
exit_gracefully($pid);
done_testing;