From 0fc459892e381469a8b967c3895c33eda6c87b48 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Mon, 30 Jan 2012 16:13:44 +0000
Subject: [PATCH] Bugfix: Properly split when the current container is alone
 within a stacked/tabbed con (+test) (Thanks aksr)

Fixes: #630
---
 src/tree.c              |  3 ++-
 testcases/t/122-split.t | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/tree.c b/src/tree.c
index 53993b99..f5bac193 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -291,7 +291,8 @@ void tree_split(Con *con, orientation_t orientation) {
     /* if we are in a container whose parent contains only one
      * child (its split functionality is unused so far), we just change the
      * orientation (more intuitive than splitting again) */
-    if (con_num_children(parent) == 1) {
+    if (con_num_children(parent) == 1 &&
+        parent->layout == L_DEFAULT) {
         parent->orientation = orientation;
         DLOG("Just changing orientation of existing container\n");
         return;
diff --git a/testcases/t/122-split.t b/testcases/t/122-split.t
index 3484c7fc..0dfb99a3 100644
--- a/testcases/t/122-split.t
+++ b/testcases/t/122-split.t
@@ -89,4 +89,25 @@ cmd 'split v';
 my $count = sum_nodes(\@content);
 is($count, $old_count, 'not more windows after splitting again');
 
+######################################################################
+# In the special case of being inside a stacked or tabbed container, we don’t
+# want this to happen.
+######################################################################
+
+$tmp = fresh_workspace;
+
+cmd 'open';
+@content = @{get_ws_content($tmp)};
+is(scalar @content, 1, 'Precisely one container on this ws');
+cmd 'layout stacked';
+@content = @{get_ws_content($tmp)};
+is(scalar @content, 1, 'Still one container on this ws');
+is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con has one child node');
+
+cmd 'split h';
+cmd 'open';
+@content = @{get_ws_content($tmp)};
+is(scalar @content, 1, 'Still one container on this ws');
+is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node');
+
 done_testing;