From 69e5c0f6ce4a1d68a7205a0046a189e0aaa2ef35 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 17 Jul 2010 01:27:47 +0200 Subject: [PATCH] Treat stacking containers as if they are in vertical orientation, add testcase --- include/con.h | 8 +++++ src/con.c | 14 ++++++++ src/tree.c | 4 +-- testcases/t/31-stacking-order.t | 64 +++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 testcases/t/31-stacking-order.t diff --git a/include/con.h b/include/con.h index f2d05dbc..716ebfd3 100644 --- a/include/con.h +++ b/include/con.h @@ -113,4 +113,12 @@ void con_toggle_fullscreen(Con *con); */ void con_move_to_workspace(Con *con, Con *workspace); +/** + * Returns the orientation of the given container (for stacked containers, + * vertical orientation is used regardless of the actual orientation of the + * container). + * + */ +int con_orientation(Con *con); + #endif diff --git a/src/con.c b/src/con.c index dc9e0a54..a28d6633 100644 --- a/src/con.c +++ b/src/con.c @@ -376,3 +376,17 @@ void con_move_to_workspace(Con *con, Con *workspace) { con_detach(con); con_attach(con, next); } + +/* + * Returns the orientation of the given container (for stacked containers, + * vertical orientation is used regardless of the actual orientation of the + * container). + * + */ +int con_orientation(Con *con) { + /* stacking containers behave like they are in vertical orientation */ + if (con->layout == L_STACKED) + return VERT; + + return con->orientation; +} diff --git a/src/tree.c b/src/tree.c index 54e36c34..cf7f60dd 100644 --- a/src/tree.c +++ b/src/tree.c @@ -332,7 +332,7 @@ void tree_render() { void tree_next(char way, orientation_t orientation) { /* 1: get the first parent with the same orientation */ Con *parent = focused->parent; - while (parent->orientation != orientation) { + while (con_orientation(parent) != orientation) { LOG("need to go one level further up\n"); /* if the current parent is an output, we are at a workspace * and the orientation still does not match */ @@ -377,7 +377,7 @@ void tree_move(char way, orientation_t orientation) { if (focused->type == CT_WORKSPACE) return; bool level_changed = false; - while (parent->orientation != orientation) { + while (con_orientation(parent) != orientation) { LOG("need to go one level further up\n"); /* if the current parent is an output, we are at a workspace * and the orientation still does not match */ diff --git a/testcases/t/31-stacking-order.t b/testcases/t/31-stacking-order.t new file mode 100644 index 00000000..caf136fb --- /dev/null +++ b/testcases/t/31-stacking-order.t @@ -0,0 +1,64 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Check if stacking containers can be used independantly of +# the split mode (horizontal/vertical) of the underlying +# container. +# +use i3test tests => 7; +use Time::HiRes qw(sleep); + +my $i3 = i3("/tmp/nestedcons"); + +my $tmp = get_unused_workspace(); +$i3->command("workspace $tmp")->recv; + +ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); + +# Enforce vertical split mode +$i3->command('split v')->recv; + +$i3->command('open')->recv; +my ($nodes, $focus) = get_ws_content($tmp); +my $first = $focus->[0]; + +$i3->command('open')->recv; +($nodes, $focus) = get_ws_content($tmp); +my $second = $focus->[0]; + +isnt($first, $second, 'two different containers opened'); + +############################################################## +# change mode to stacking and cycle through the containers +############################################################## + +$i3->command('layout stacking')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $second, 'second container still focused'); + +$i3->command('next v')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $first, 'first container focused'); + +$i3->command('prev v')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $second, 'second container focused again'); + +############################################################## +# now change the orientation to horizontal and cycle +############################################################## + +$i3->command('level up')->recv; +$i3->command('split h')->recv; +$i3->command('level down')->recv; + +$i3->command('next v')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $first, 'first container focused'); + +$i3->command('prev v')->recv; +($nodes, $focus) = get_ws_content($tmp); +is($focus->[0], $second, 'second container focused again'); + + +diag( "Testing i3, Perl $], $^X" ); -- 2.39.5