aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c106
1 files changed, 103 insertions, 3 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index cf50ee09..60256336 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -79,6 +79,65 @@ struct sway_container *workspace_create(struct sway_container *output,
return workspace;
}
+void workspace_destroy(struct sway_container *workspace) {
+ if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ if (!sway_assert(workspace->destroying,
+ "Tried to free workspace which wasn't marked as destroying")) {
+ return;
+ }
+ if (!sway_assert(workspace->ntxnrefs == 0, "Tried to free workspace "
+ "which is still referenced by transactions")) {
+ return;
+ }
+ // sway_workspace
+ struct sway_workspace *ws = workspace->sway_workspace;
+ list_foreach(ws->output_priority, free);
+ list_free(ws->output_priority);
+ list_free(ws->floating);
+ free(ws);
+
+ // swayc
+ free(workspace->name);
+ free(workspace->formatted_title);
+ wlr_texture_destroy(workspace->title_focused);
+ wlr_texture_destroy(workspace->title_focused_inactive);
+ wlr_texture_destroy(workspace->title_unfocused);
+ wlr_texture_destroy(workspace->title_urgent);
+ list_free(workspace->children);
+ list_free(workspace->current.children);
+ list_free(workspace->outputs);
+ free(workspace);
+}
+
+void workspace_begin_destroy(struct sway_container *workspace) {
+ if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ wlr_log(WLR_DEBUG, "Destroying workspace '%s'", workspace->name);
+ wl_signal_emit(&workspace->events.destroy, workspace);
+ ipc_event_workspace(NULL, workspace, "empty"); // intentional
+
+ workspace->destroying = true;
+ container_set_dirty(workspace);
+
+ if (workspace->parent) {
+ container_remove_child(workspace);
+ }
+}
+
+void workspace_consider_destroy(struct sway_container *ws) {
+ if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ if (ws->children->length == 0 && ws->sway_workspace->floating->length == 0
+ && seat_get_active_child(seat, ws->parent) != ws) {
+ workspace_begin_destroy(ws);
+ }
+}
+
char *prev_workspace_name = NULL;
void next_name_map(struct sway_container *ws, void *data) {
@@ -421,9 +480,7 @@ bool workspace_switch(struct sway_container *workspace,
// no op. We therefore need to send the IPC event and clean up the old
// workspace here.
ipc_event_workspace(active_ws, workspace, "focus");
- if (!workspace_is_visible(active_ws) && workspace_is_empty(active_ws)) {
- container_destroy(active_ws);
- }
+ workspace_consider_destroy(active_ws);
}
seat_set_focus(seat, next);
struct sway_container *output = container_parent(workspace, C_OUTPUT);
@@ -608,3 +665,46 @@ void workspace_add_floating(struct sway_container *workspace,
container_set_dirty(workspace);
container_set_dirty(con);
}
+
+void workspace_remove_gaps(struct sway_container *ws) {
+ if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ if (ws->current_gaps == 0) {
+ return;
+ }
+
+ ws->width += ws->current_gaps * 2;
+ ws->height += ws->current_gaps * 2;
+ ws->x -= ws->current_gaps;
+ ws->y -= ws->current_gaps;
+ ws->current_gaps = 0;
+}
+
+void workspace_add_gaps(struct sway_container *ws) {
+ if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ if (ws->current_gaps > 0) {
+ return;
+ }
+ bool should_apply =
+ config->edge_gaps || (config->smart_gaps && ws->children->length > 1);
+ if (!should_apply) {
+ return;
+ }
+
+ ws->current_gaps = ws->has_gaps ? ws->gaps_outer : config->gaps_outer;
+
+ if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
+ // We have to add inner gaps for this, because children of tabbed and
+ // stacked containers don't apply their own gaps - they assume the
+ // tabbed/stacked container is using gaps.
+ ws->current_gaps += ws->has_gaps ? ws->gaps_inner : config->gaps_inner;
+ }
+
+ ws->x += ws->current_gaps;
+ ws->y += ws->current_gaps;
+ ws->width -= 2 * ws->current_gaps;
+ ws->height -= 2 * ws->current_gaps;
+}