aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/input/seat.c4
-rw-r--r--sway/tree/container.c55
-rw-r--r--sway/tree/layout.c37
3 files changed, 93 insertions, 3 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 7cf0dd08..ae536264 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -8,6 +8,7 @@
#include "sway/input/keyboard.h"
#include "sway/ipc-server.h"
#include "sway/output.h"
+#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "log.h"
@@ -331,6 +332,9 @@ void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *containe
if (last_ws) {
wlr_log(L_DEBUG, "sending workspace event");
ipc_event_workspace(last_ws, container, "focus");
+ if (last_ws->children->length == 0) {
+ container_workspace_destroy(last_ws);
+ }
}
}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 2eac812e..ed39a154 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -58,7 +58,7 @@ static struct sway_container *container_create(enum sway_container_type type) {
return c;
}
-static void container_destroy(struct sway_container *cont) {
+void container_destroy(struct sway_container *cont) {
if (cont == NULL) {
return;
}
@@ -203,8 +203,7 @@ struct sway_container *container_view_create(struct sway_container *sibling,
}
struct sway_container *container_output_destroy(struct sway_container *output) {
- if (!sway_assert(output,
- "null output passed to container_output_destroy")) {
+ if (!sway_assert(output, "cannot destroy null output")) {
return NULL;
}
@@ -236,6 +235,45 @@ struct sway_container *container_output_destroy(struct sway_container *output) {
return &root_container;
}
+struct sway_container *container_workspace_destroy(
+ struct sway_container *workspace) {
+ if (!sway_assert(workspace, "cannot destroy null workspace")) {
+ return NULL;
+ }
+
+ // Do not destroy this if it's the last workspace on this output
+ struct sway_container *output = container_parent(workspace, C_OUTPUT);
+ if (output && output->children->length == 1) {
+ return NULL;
+ }
+
+ struct sway_container *parent = workspace->parent;
+ if (workspace->children->length == 0) {
+ // destroy the WS if there are no children (TODO check for floating)
+ wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
+ ipc_event_workspace(workspace, NULL, "empty");
+ } else {
+ // Move children to a different workspace on this output
+ struct sway_container *new_workspace = NULL;
+ // TODO move floating
+ for (int i = 0; i < output->children->length; i++) {
+ if (output->children->items[i] != workspace) {
+ new_workspace = output->children->items[i];
+ break;
+ }
+ }
+
+ wlr_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
+ workspace->name, new_workspace->name);
+ for (int i = 0; i < workspace->children->length; i++) {
+ container_move_to(workspace->children->items[i], new_workspace);
+ }
+ }
+
+ container_destroy(workspace);
+ return parent;
+}
+
struct sway_container *container_view_destroy(struct sway_container *view) {
if (!view) {
return NULL;
@@ -438,3 +476,14 @@ void container_for_each_descendant_bfs(struct sway_container *con,
list_cat(queue, current->children);
}
}
+
+bool container_has_anscestor(struct sway_container *descendant,
+ struct sway_container *anscestor) {
+ while (descendant->type != C_ROOT) {
+ descendant = descendant->parent;
+ if (descendant == anscestor) {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index dc0ee5b4..97007888 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -11,6 +11,7 @@
#include "sway/output.h"
#include "sway/tree/view.h"
#include "sway/input/seat.h"
+#include "sway/ipc-server.h"
#include "list.h"
#include "log.h"
@@ -121,6 +122,42 @@ struct sway_container *container_remove_child(struct sway_container *child) {
return parent;
}
+struct sway_container *container_reap_empty(struct sway_container *container) {
+ if (!sway_assert(container, "reaping null container")) {
+ return NULL;
+ }
+ while (container->children->length == 0 && container->type == C_CONTAINER) {
+ wlr_log(L_DEBUG, "Container: Destroying container '%p'", container);
+ struct sway_container *parent = container->parent;
+ container_destroy(container);
+ container = parent;
+ }
+ return container;
+}
+
+void container_move_to(struct sway_container* container,
+ struct sway_container* destination) {
+ if (container == destination
+ || container_has_anscestor(container, destination)) {
+ return;
+ }
+ struct sway_container *old_parent = container_remove_child(container);
+ container->width = container->height = 0;
+ struct sway_container *new_parent =
+ container_add_sibling(destination, container);
+ if (destination->type == C_WORKSPACE) {
+ // If the workspace only has one child after adding one, it
+ // means that the workspace was just initialized.
+ // TODO: Consider floating views in this test
+ if (destination->children->length == 1) {
+ ipc_event_workspace(NULL, destination, "init");
+ }
+ }
+ old_parent = container_reap_empty(old_parent);
+ arrange_windows(old_parent, -1, -1);
+ arrange_windows(new_parent, -1, -1);
+}
+
enum sway_container_layout container_get_default_layout(
struct sway_container *output) {
/* TODO WLR