refactor tree_move() into src/move.c, change config (!), change testcase

Due to lots of cases which were added and added to tree_move(), the function
was not really easy to understand. For this refactoring, I wrote tree_move()
from scratch, thinking about (hopefully) all cases. The testsuite still passes.

The move command also has different parameters now. Instead of the hard to
understand 'before v' stuff, we use 'move [left|right|up|down]'.
This commit is contained in:
Michael Stapelberg
2011-02-14 23:05:20 +01:00
parent 28dd226259
commit 26a416e016
14 changed files with 302 additions and 250 deletions

View File

@ -13,13 +13,13 @@ use X11::XCB qw(:all);
my $i3 = i3("/tmp/nestedcons");
my $tmp = get_unused_workspace();
$i3->command("workspace $tmp")->recv;
cmd "workspace $tmp";
######################################################################
# 1) move a container which cannot be moved
######################################################################
$i3->command('open')->recv;
cmd 'open';
my $old_content = get_ws_content($tmp);
is(@{$old_content}, 1, 'one container on this workspace');
@ -46,22 +46,22 @@ my $second = $content->[1]->{id};
is($content->[0]->{id}, $first, 'first container unmodified');
# Move the second container before the first one (→ swap them)
$i3->command('move before h')->recv;
$i3->command('move left')->recv;
$content = get_ws_content($tmp);
is($content->[0]->{id}, $second, 'first container modified');
# We should not be able to move any further
$i3->command('move before h')->recv;
$i3->command('move left')->recv;
$content = get_ws_content($tmp);
is($content->[0]->{id}, $second, 'first container unmodified');
# Now move in the other direction
$i3->command('move after h')->recv;
$i3->command('move right')->recv;
$content = get_ws_content($tmp);
is($content->[0]->{id}, $first, 'first container modified');
# We should not be able to move any further
$i3->command('move after h')->recv;
$i3->command('move right')->recv;
$content = get_ws_content($tmp);
is($content->[0]->{id}, $first, 'first container unmodified');
@ -84,7 +84,7 @@ $content = get_ws_content($tmp);
is(@{$content}, 3, 'three containers on this workspace');
my $third = $content->[2]->{id};
$i3->command('move before h')->recv;
$i3->command('move left')->recv;
$content = get_ws_content($tmp);
is(@{$content}, 2, 'only two containers on this workspace');
my $nodes = $content->[1]->{nodes};
@ -95,19 +95,21 @@ is($nodes->[1]->{id}, $third, 'third container on bottom');
# move it inside the split container
######################################################################
$i3->command('move before v')->recv;
$i3->command('move up')->recv;
$nodes = get_ws_content($tmp)->[1]->{nodes};
is($nodes->[0]->{id}, $third, 'third container on top');
is($nodes->[1]->{id}, $second, 'second container on bottom');
# move it outside again
$i3->command('move before h')->recv;
$i3->command('move left')->recv;
$content = get_ws_content($tmp);
is(@{$content}, 3, 'three nodes on this workspace');
$i3->command('move after h')->recv;
# due to automatic flattening/cleanup, the remaining split container
# will be replaced by the con itself, so we will still have 3 nodes
$i3->command('move right')->recv;
$content = get_ws_content($tmp);
is(@{$content}, 2, 'two nodes on this workspace');
is(@{$content}, 3, 'two nodes on this workspace');
######################################################################
# 4) We create two v-split containers on the workspace, then we move
@ -116,7 +118,7 @@ is(@{$content}, 2, 'two nodes on this workspace');
######################################################################
my $otmp = get_unused_workspace();
$i3->command("workspace $otmp")->recv;
cmd "workspace $otmp";
$i3->command("open")->recv;
$i3->command("open")->recv;
@ -125,9 +127,9 @@ $i3->command("open")->recv;
$i3->command("prev h")->recv;
$i3->command("split v")->recv;
$i3->command("open")->recv;
$i3->command("move after h")->recv;
$i3->command("move right")->recv;
$i3->command("prev h")->recv;
$i3->command("move after h")->recv;
$i3->command("move right")->recv;
$content = get_ws_content($otmp);
is(@{$content}, 1, 'only one nodes on this workspace');