aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-20 12:34:39 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-20 13:07:33 +1000
commited771a6a6e147d667c3791f897ad62e307b260fe (patch)
tree04892c5c4a3002c378439bf0ca160a6dbdc6919b /sway/tree/workspace.c
parentMerge pull request #2872 from RyanDwyer/cursor-rebase (diff)
downloadsway-ed771a6a6e147d667c3791f897ad62e307b260fe.tar.gz
sway-ed771a6a6e147d667c3791f897ad62e307b260fe.tar.zst
sway-ed771a6a6e147d667c3791f897ad62e307b260fe.zip
Fix crash when view unmaps while no outputs connected
When a view unmaps, we call workspace_consider_destroy. This function assumed the workspace would always have an output, but this is not the case when hotplugged down to zero. The function now handles this and allows itself to be destroyed when there is no output. This means that workspace_begin_destroy must remove the workspace from the root->saved_workspaces list to avoid an eventual dangling pointer, so it does that now. Lastly, when an output is plugged in again and it has to create a new initial workspace for it, we must emit the workspace::init IPC event otherwise swaybar shows no workspaces at all. I guess when you start sway, swaybar is started after the workspace has been created which is why this hasn't been needed earlier.
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 2a00824d..ed875ebb 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -119,6 +119,11 @@ void workspace_begin_destroy(struct sway_workspace *workspace) {
119 119
120 if (workspace->output) { 120 if (workspace->output) {
121 workspace_detach(workspace); 121 workspace_detach(workspace);
122 } else {
123 int index = list_find(root->saved_workspaces, workspace);
124 if (index != -1) {
125 list_del(root->saved_workspaces, index);
126 }
122 } 127 }
123 128
124 workspace->node.destroying = true; 129 workspace->node.destroying = true;
@@ -126,10 +131,13 @@ void workspace_begin_destroy(struct sway_workspace *workspace) {
126} 131}
127 132
128void workspace_consider_destroy(struct sway_workspace *ws) { 133void workspace_consider_destroy(struct sway_workspace *ws) {
129 if (ws->tiling->length == 0 && ws->floating->length == 0 134 if (ws->tiling->length || ws->floating->length) {
130 && output_get_active_workspace(ws->output) != ws) { 135 return;
131 workspace_begin_destroy(ws); 136 }
137 if (ws->output && output_get_active_workspace(ws->output) == ws) {
138 return;
132 } 139 }
140 workspace_begin_destroy(ws);
133} 141}
134 142
135char *prev_workspace_name = NULL; 143char *prev_workspace_name = NULL;