mirror of
https://github.com/swaywm/sway.git
synced 2025-11-07 13:29:56 -05:00
Destroy empty workspaces when moving away
This commit is contained in:
parent
2d46050281
commit
01af343912
5 changed files with 104 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue