mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 18:01:29 +00:00
move view and workspace destructors to container.c
This commit is contained in:
parent
7afbe9284f
commit
b4c5f79725
|
@ -128,11 +128,12 @@ struct sway_container *container_view_create(
|
||||||
struct sway_container *sibling, struct sway_view *sway_view);
|
struct sway_container *sibling, struct sway_view *sway_view);
|
||||||
|
|
||||||
// TODO don't return the parent on destroy
|
// TODO don't return the parent on destroy
|
||||||
void container_destroy(struct sway_container *container);
|
struct sway_container *container_destroy(struct sway_container *container);
|
||||||
|
|
||||||
|
// TODO make me private
|
||||||
|
struct sway_container *container_finish(struct sway_container *cont);
|
||||||
|
|
||||||
struct sway_container *container_workspace_destroy(struct sway_container *container);
|
|
||||||
struct sway_container *container_output_destroy(struct sway_container *container);
|
struct sway_container *container_output_destroy(struct sway_container *container);
|
||||||
void container_view_destroy(struct sway_container *container);
|
|
||||||
|
|
||||||
struct sway_container *container_close(struct sway_container *container);
|
struct sway_container *container_close(struct sway_container *container);
|
||||||
|
|
||||||
|
|
|
@ -381,7 +381,8 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
||||||
if (last_ws) {
|
if (last_ws) {
|
||||||
ipc_event_workspace(last_ws, container, "focus");
|
ipc_event_workspace(last_ws, container, "focus");
|
||||||
if (last_ws->children->length == 0) {
|
if (last_ws->children->length == 0) {
|
||||||
container_workspace_destroy(last_ws);
|
output_damage_whole(last_ws->parent->sway_output);
|
||||||
|
container_destroy(last_ws);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct sway_container *last_output = last_focus;
|
struct sway_container *last_output = last_focus;
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct sway_container *container_create(enum sway_container_type type) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sway_container *container_finish(struct sway_container *cont) {
|
struct sway_container *container_finish(struct sway_container *cont) {
|
||||||
if (cont == NULL) {
|
if (cont == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ static struct sway_container *container_finish(struct sway_container *cont) {
|
||||||
while (cont->children != NULL && cont->children->length != 0) {
|
while (cont->children != NULL && cont->children->length != 0) {
|
||||||
struct sway_container *child = cont->children->items[0];
|
struct sway_container *child = cont->children->items[0];
|
||||||
container_remove_child(child);
|
container_remove_child(child);
|
||||||
container_destroy(child);
|
container_finish(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cont->marks) {
|
if (cont->marks) {
|
||||||
|
@ -109,6 +109,45 @@ static struct sway_container *container_finish(struct sway_container *cont) {
|
||||||
free(cont);
|
free(cont);
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
static 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_finish(workspace);
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void reap_empty_func(struct sway_container *con, void *data) {
|
static void reap_empty_func(struct sway_container *con, void *data) {
|
||||||
switch (con->type) {
|
switch (con->type) {
|
||||||
|
@ -146,18 +185,46 @@ struct sway_container *container_reap_empty(struct sway_container *container) {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void container_root_finish(struct sway_container *con) {
|
||||||
|
wlr_log(L_ERROR, "TODO: destroy the root container");
|
||||||
|
}
|
||||||
|
|
||||||
void container_destroy(struct sway_container *cont) {
|
struct sway_container *container_destroy(struct sway_container *con) {
|
||||||
if (cont == NULL) {
|
if (con == NULL) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cont->children != NULL && cont->children->length) {
|
struct sway_container *anscestor = NULL;
|
||||||
assert(false && "dont destroy containers with children");
|
|
||||||
|
switch (con->type) {
|
||||||
|
case C_ROOT:
|
||||||
|
container_root_finish(con);
|
||||||
|
break;
|
||||||
|
case C_OUTPUT:
|
||||||
|
anscestor = container_output_destroy(con);
|
||||||
|
break;
|
||||||
|
case C_WORKSPACE:
|
||||||
|
anscestor = container_workspace_destroy(con);
|
||||||
|
break;
|
||||||
|
case C_CONTAINER:
|
||||||
|
if (con->children != NULL && con->children->length) {
|
||||||
|
assert(false && "dont destroy container containers with children");
|
||||||
|
}
|
||||||
|
container_finish(con);
|
||||||
|
// TODO return parent to arrange maybe?
|
||||||
|
break;
|
||||||
|
case C_VIEW:
|
||||||
|
container_finish(con);
|
||||||
|
// TODO return parent to arrange maybe?
|
||||||
|
break;
|
||||||
|
case C_TYPES:
|
||||||
|
wlr_log(L_ERROR, "tried to destroy an invalid container");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
container_finish(cont);
|
|
||||||
container_reap_empty(&root_container);
|
container_reap_empty(&root_container);
|
||||||
|
|
||||||
|
return anscestor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void container_close_func(struct sway_container *container, void *data) {
|
static void container_close_func(struct sway_container *container, void *data) {
|
||||||
|
|
|
@ -27,8 +27,7 @@ void view_destroy(struct sway_view *view) {
|
||||||
view_unmap(view);
|
view_unmap(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
container_view_destroy(view->swayc);
|
container_destroy(view->swayc);
|
||||||
free(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *view_get_title(struct sway_view *view) {
|
const char *view_get_title(struct sway_view *view) {
|
||||||
|
@ -78,14 +77,6 @@ void view_close(struct sway_view *view) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void container_view_destroy(struct sway_container *view) {
|
|
||||||
if (!view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
|
|
||||||
container_destroy(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
void view_damage_whole(struct sway_view *view) {
|
void view_damage_whole(struct sway_view *view) {
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (int i = 0; i < root_container.children->length; ++i) {
|
||||||
struct sway_container *cont = root_container.children->items[i];
|
struct sway_container *cont = root_container.children->items[i];
|
||||||
|
@ -158,7 +149,7 @@ void view_unmap(struct sway_view *view) {
|
||||||
|
|
||||||
view_damage_whole(view);
|
view_damage_whole(view);
|
||||||
|
|
||||||
container_view_destroy(view->swayc);
|
container_destroy(view->swayc);
|
||||||
|
|
||||||
view->swayc = NULL;
|
view->swayc = NULL;
|
||||||
view->surface = NULL;
|
view->surface = NULL;
|
||||||
|
|
|
@ -208,45 +208,6 @@ struct sway_container *workspace_create(const char *name) {
|
||||||
return new_ws;
|
return new_ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the previous or next workspace on the specified output. Wraps around at
|
* Get the previous or next workspace on the specified output. Wraps around at
|
||||||
* the end and beginning. If next is false, the previous workspace is returned,
|
* the end and beginning. If next is false, the previous workspace is returned,
|
||||||
|
|
Loading…
Reference in a new issue