From a66fd74a547f1d6fa6b752314ddd674eb44b6da7 Mon Sep 17 00:00:00 2001
From: Brian Ashworth <bosrsf04@gmail.com>
Date: Mon, 28 May 2018 10:52:49 -0400
Subject: Fix breaking out of tabs/stacks

---
 sway/tree/layout.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 1507eba9..96501cc3 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -309,6 +309,21 @@ static void workspace_rejigger(struct sway_container *ws,
 	arrange_workspace(ws);
 }
 
+static void move_out_of_tabs_stacks(struct sway_container *container,
+		struct sway_container *current, enum movement_direction move_dir,
+		int offs) {
+	wlr_log(L_DEBUG, "Moving out of tab/stack into a split");
+	struct sway_container *old_parent = current->parent->parent;
+	struct sway_container *new_parent = container_split(current->parent,
+		move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT);
+	container_insert_child(new_parent, container, offs < 0 ? 0 : 1);
+	container_reap_empty_recursive(new_parent->parent);
+	container_flatten(new_parent->parent);
+	wl_signal_emit(&current->events.reparent, old_parent);
+	container_create_notify(new_parent);
+	arrange_children_of(new_parent);
+}
+
 void container_move(struct sway_container *container,
 		enum movement_direction move_dir, int move_amt) {
 	if (!sway_assert(
@@ -390,6 +405,10 @@ void container_move(struct sway_container *container,
 					arrange_workspace(current);
 				}
 				return;
+			} else if (current->layout == L_TABBED
+					|| current->layout == L_STACKED) {
+				wlr_log(L_DEBUG, "Rejiggering out of tabs/stacks");
+				workspace_rejigger(current, container, move_dir);
 			} else {
 				wlr_log(L_DEBUG, "Selecting output");
 				current = current->parent;
@@ -401,8 +420,15 @@ void container_move(struct sway_container *container,
 				if ((index == parent->children->length - 1 && offs > 0)
 						|| (index == 0 && offs < 0)) {
 					if (current->parent == container->parent) {
-						wlr_log(L_DEBUG, "Hit limit, selecting parent");
-						current = current->parent;
+						if (parent->layout == L_TABBED
+								|| parent->layout == L_STACKED) {
+							move_out_of_tabs_stacks(container, current,
+									move_dir, offs);
+							return;
+						} else {
+							wlr_log(L_DEBUG, "Hit limit, selecting parent");
+							current = current->parent;
+						}
 					} else {
 						wlr_log(L_DEBUG, "Hit limit, "
 								"promoting descendant to sibling");
@@ -419,6 +445,10 @@ void container_move(struct sway_container *container,
 					sibling = parent->children->items[index + offs];
 					wlr_log(L_DEBUG, "Selecting sibling id:%zd", sibling->id);
 				}
+			} else if (parent->layout == L_TABBED
+					|| parent->layout == L_STACKED) {
+				move_out_of_tabs_stacks(container, current, move_dir, offs);
+				return;
 			} else {
 				wlr_log(L_DEBUG, "Moving up to find a parallel container");
 				current = current->parent;
-- 
cgit v1.2.3


From 103a302fa409cf9ba88f5163280d73fbf886bca2 Mon Sep 17 00:00:00 2001
From: Brian Ashworth <bosrsf04@gmail.com>
Date: Mon, 28 May 2018 21:37:29 -0400
Subject: Fix moving out of a tabbed/stacked workspace

---
 sway/tree/layout.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 96501cc3..c2a338f9 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -313,15 +313,24 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
 		struct sway_container *current, enum movement_direction move_dir,
 		int offs) {
 	wlr_log(L_DEBUG, "Moving out of tab/stack into a split");
+	bool is_workspace = current->parent->type == C_WORKSPACE;
 	struct sway_container *old_parent = current->parent->parent;
 	struct sway_container *new_parent = container_split(current->parent,
 		move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT);
-	container_insert_child(new_parent, container, offs < 0 ? 0 : 1);
-	container_reap_empty_recursive(new_parent->parent);
-	container_flatten(new_parent->parent);
-	wl_signal_emit(&current->events.reparent, old_parent);
+	if (is_workspace) {
+		container_insert_child(new_parent->parent, container, offs < 0 ? 0 : 1);
+	} else {
+		container_insert_child(new_parent, container, offs < 0 ? 0 : 1);
+		container_reap_empty_recursive(new_parent->parent);
+		container_flatten(new_parent->parent);
+	}
+	wl_signal_emit(&container->events.reparent, old_parent);
 	container_create_notify(new_parent);
-	arrange_children_of(new_parent);
+	if (is_workspace) {
+		arrange_workspace(new_parent->parent);
+	} else {
+		arrange_children_of(new_parent);
+	}
 }
 
 void container_move(struct sway_container *container,
-- 
cgit v1.2.3


From f5e44d4b2c5711862c4bffb37bc15899678c6c19 Mon Sep 17 00:00:00 2001
From: Brian Ashworth <bosrsf04@gmail.com>
Date: Tue, 29 May 2018 11:21:18 -0400
Subject: Fix layout in -t get_tree

---
 sway/ipc-json.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 0233a36e..d2aee9a9 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -160,7 +160,8 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
 	json_object_object_add(object, "type", json_object_new_string("con"));
 
 	if (c->parent) {
-		enum sway_container_layout layout = (c->parent->type == C_CONTAINER) ?
+		enum sway_container_layout layout =
+			(c->parent->type == C_CONTAINER && c->type == C_VIEW) ?
 			c->parent->layout : c->layout;
 
 		json_object_object_add(object, "layout",
-- 
cgit v1.2.3


From 3b90b556668376256294c71915327999a688a65e Mon Sep 17 00:00:00 2001
From: Brian Ashworth <bosrsf04@gmail.com>
Date: Tue, 29 May 2018 11:27:04 -0400
Subject: Notify of subtree change

---
 sway/tree/layout.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index c2a338f9..9594b75a 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -331,6 +331,7 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
 	} else {
 		arrange_children_of(new_parent);
 	}
+	container_notify_subtree_changed(new_parent);
 }
 
 void container_move(struct sway_container *container,
-- 
cgit v1.2.3


From 64225b1137f1dccb196de404105aeb45616ea988 Mon Sep 17 00:00:00 2001
From: Brian Ashworth <bosrsf04@gmail.com>
Date: Tue, 29 May 2018 21:45:18 -0400
Subject: Send IPC layout of node itself

---
 sway/ipc-json.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index d2aee9a9..03582950 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -160,12 +160,8 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
 	json_object_object_add(object, "type", json_object_new_string("con"));
 
 	if (c->parent) {
-		enum sway_container_layout layout =
-			(c->parent->type == C_CONTAINER && c->type == C_VIEW) ?
-			c->parent->layout : c->layout;
-
 		json_object_object_add(object, "layout",
-			json_object_new_string(ipc_json_layout_description(layout)));
+			json_object_new_string(ipc_json_layout_description(c->layout)));
 	}
 }
 
-- 
cgit v1.2.3