diff options
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 73c4849b..588ceb2d 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,42 @@ 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 && | 105 | struct 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 | struct sway_container *parent = container->parent; | ||
114 | container_workspace_destroy(container); | ||
115 | return parent; | ||
116 | } | ||
117 | return container; | ||
118 | } else if (container->type == C_CONTAINER) { | ||
119 | struct sway_container *parent = container->parent; | ||
120 | container_destroy(container); | ||
121 | container = parent; | ||
122 | } else { | ||
123 | container = container->parent; | ||
124 | } | ||
125 | } | ||
126 | return container; | ||
110 | } | 127 | } |
111 | 128 | ||
112 | struct sway_container *container_remove_child(struct sway_container *child) { | 129 | struct sway_container *container_remove_child(struct sway_container *child) { |
113 | int i; | ||
114 | struct sway_container *parent = child->parent; | 130 | struct sway_container *parent = child->parent; |
115 | for (i = 0; i < parent->children->length; ++i) { | 131 | for (int i = 0; i < parent->children->length; ++i) { |
116 | if (parent->children->items[i] == child) { | 132 | if (parent->children->items[i] == child) { |
117 | list_del(parent->children, i); | 133 | list_del(parent->children, i); |
118 | break; | 134 | break; |
119 | } | 135 | } |
120 | } | 136 | } |
121 | child->parent = NULL; | 137 | child->parent = NULL; |
122 | return parent; | 138 | return container_reap_empty(parent); |
123 | } | ||
124 | |||
125 | struct 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 | } | 139 | } |
137 | 140 | ||
138 | void container_move_to(struct sway_container* container, | 141 | void container_move_to(struct sway_container* container, |
@@ -145,16 +148,9 @@ void container_move_to(struct sway_container* container, | |||
145 | container->width = container->height = 0; | 148 | container->width = container->height = 0; |
146 | struct sway_container *new_parent = | 149 | struct sway_container *new_parent = |
147 | container_add_sibling(destination, container); | 150 | container_add_sibling(destination, container); |
148 | if (destination->type == C_WORKSPACE) { | 151 | if (old_parent) { |
149 | // If the workspace only has one child after adding one, it | 152 | 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 | } | 153 | } |
156 | old_parent = container_reap_empty(old_parent); | ||
157 | arrange_windows(old_parent, -1, -1); | ||
158 | arrange_windows(new_parent, -1, -1); | 154 | arrange_windows(new_parent, -1, -1); |
159 | } | 155 | } |
160 | 156 | ||