aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/layout.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 11:58:17 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 13:49:34 -0400
commit49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6 (patch)
treeb67a66382125811fde75e5c3dff37d7081860c78 /sway/tree/layout.c
parentMerge pull request #1664 from swaywm/xwayland-add-to-focused (diff)
downloadsway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.tar.gz
sway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.tar.zst
sway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.zip
Fix workspace deletion edge cases
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r--sway/tree/layout.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 73c4849b..32e6a77c 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -9,6 +9,7 @@
9#include "sway/tree/container.h" 9#include "sway/tree/container.h"
10#include "sway/tree/layout.h" 10#include "sway/tree/layout.h"
11#include "sway/output.h" 11#include "sway/output.h"
12#include "sway/tree/workspace.h"
12#include "sway/tree/view.h" 13#include "sway/tree/view.h"
13#include "sway/input/seat.h" 14#include "sway/input/seat.h"
14#include "sway/ipc-server.h" 15#include "sway/ipc-server.h"
@@ -99,40 +100,40 @@ void container_add_child(struct sway_container *parent,
99 parent, parent->type, parent->width, parent->height); 100 parent, parent->type, parent->width, parent->height);
100 list_add(parent->children, child); 101 list_add(parent->children, child);
101 child->parent = parent; 102 child->parent = parent;
102 // set focus for this container 103}
103 /* TODO WLR 104
104 if (parent->type == C_WORKSPACE && child->type == C_VIEW && 105struct sway_container *container_reap_empty(struct sway_container *container) {
105 (parent->workspace_layout == L_TABBED || parent->workspace_layout == 106 if (!sway_assert(container, "reaping null container")) {
106 L_STACKED)) { 107 return NULL;
107 child = new_container(child, parent->workspace_layout);
108 } 108 }
109 */ 109 wlr_log(L_DEBUG, "reaping %p %s", container, container->name);
110 while (container->children->length == 0) {
111 if (container->type == C_WORKSPACE) {
112 if (!workspace_is_visible(container)) {
113 container_workspace_destroy(container);
114 }
115 break;
116 } else if (container->type == C_CONTAINER) {
117 struct sway_container *parent = container->parent;
118 container_destroy(container);
119 container = parent;
120 } else {
121 container = container->parent;
122 }
123 }
124 return container;
110} 125}
111 126
112struct sway_container *container_remove_child(struct sway_container *child) { 127struct sway_container *container_remove_child(struct sway_container *child) {
113 int i;
114 struct sway_container *parent = child->parent; 128 struct sway_container *parent = child->parent;
115 for (i = 0; i < parent->children->length; ++i) { 129 for (int i = 0; i < parent->children->length; ++i) {
116 if (parent->children->items[i] == child) { 130 if (parent->children->items[i] == child) {
117 list_del(parent->children, i); 131 list_del(parent->children, i);
118 break; 132 break;
119 } 133 }
120 } 134 }
121 child->parent = NULL; 135 child->parent = NULL;
122 return parent; 136 return container_reap_empty(parent);
123}
124
125struct sway_container *container_reap_empty(struct sway_container *container) {
126 if (!sway_assert(container, "reaping null container")) {
127 return NULL;
128 }
129 while (container->children->length == 0 && container->type == C_CONTAINER) {
130 wlr_log(L_DEBUG, "Container: Destroying container '%p'", container);
131 struct sway_container *parent = container->parent;
132 container_destroy(container);
133 container = parent;
134 }
135 return container;
136} 137}
137 138
138void container_move_to(struct sway_container* container, 139void container_move_to(struct sway_container* container,
@@ -145,16 +146,9 @@ void container_move_to(struct sway_container* container,
145 container->width = container->height = 0; 146 container->width = container->height = 0;
146 struct sway_container *new_parent = 147 struct sway_container *new_parent =
147 container_add_sibling(destination, container); 148 container_add_sibling(destination, container);
148 if (destination->type == C_WORKSPACE) { 149 if (old_parent) {
149 // If the workspace only has one child after adding one, it 150 arrange_windows(old_parent, -1, -1);
150 // means that the workspace was just initialized.
151 // TODO: Consider floating views in this test
152 if (destination->children->length == 1) {
153 ipc_event_workspace(NULL, destination, "init");
154 }
155 } 151 }
156 old_parent = container_reap_empty(old_parent);
157 arrange_windows(old_parent, -1, -1);
158 arrange_windows(new_parent, -1, -1); 152 arrange_windows(new_parent, -1, -1);
159} 153}
160 154