Skip to content

Commit fd2863f

Browse files
committed
WorkspaceManager: Fix crash on workspace removed
1 parent 56a4365 commit fd2863f

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/WorkspaceManager.vala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class Gala.WorkspaceManager : Object {
120120
// or else things might get broke
121121
DragDropAction.cancel_all_by_id ("multitaskingview-window");
122122

123-
remove_workspace (prev_workspace);
123+
queue_remove_workspace (prev_workspace);
124124
}
125125
}
126126

@@ -178,7 +178,7 @@ public class Gala.WorkspaceManager : Object {
178178
&& Utils.get_n_windows (workspace, true, window) == 0
179179
&& workspace != last_workspace
180180
) {
181-
remove_workspace (workspace);
181+
queue_remove_workspace (workspace);
182182
}
183183

184184
// if window is the second last and empty, make it the last workspace
@@ -187,7 +187,7 @@ public class Gala.WorkspaceManager : Object {
187187
&& Utils.get_n_windows (workspace, true, window) == 0
188188
&& workspace.index () == last_workspace_index - 1
189189
) {
190-
remove_workspace (last_workspace);
190+
queue_remove_workspace (last_workspace);
191191
}
192192
}
193193

@@ -221,12 +221,23 @@ public class Gala.WorkspaceManager : Object {
221221
manager.append_new_workspace (false, display.get_current_time ());
222222
}
223223

224+
private void queue_remove_workspace (Meta.Workspace workspace) {
225+
// workspace has already been removed
226+
if (workspace in workspaces_marked_removed) {
227+
return;
228+
}
229+
230+
workspaces_marked_removed.add (workspace);
231+
232+
Idle.add (() => remove_workspace (workspace));
233+
}
234+
224235
/**
225236
* Make sure we switch to a different workspace and remove the given one
226237
*
227238
* @param workspace The workspace to remove
228239
*/
229-
private void remove_workspace (Meta.Workspace workspace) {
240+
private bool remove_workspace (Meta.Workspace workspace) {
230241
unowned Meta.Display display = workspace.get_display ();
231242
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
232243
var time = display.get_current_time ();
@@ -246,17 +257,12 @@ public class Gala.WorkspaceManager : Object {
246257
}
247258
}
248259

249-
// workspace has already been removed
250-
if (workspace in workspaces_marked_removed) {
251-
return;
252-
}
253-
254260
workspace.window_added.disconnect (queue_window_added);
255261
workspace.window_removed.disconnect (window_removed);
256262

257-
workspaces_marked_removed.add (workspace);
258-
259263
manager.remove_workspace (workspace, time);
264+
265+
return Source.REMOVE;
260266
}
261267

262268
/**
@@ -292,7 +298,7 @@ public class Gala.WorkspaceManager : Object {
292298
foreach (var workspace in manager.get_workspaces ()) {
293299
var last_index = manager.get_n_workspaces () - 1;
294300
if (Utils.get_n_windows (workspace) == 0 && workspace.index () != last_index) {
295-
remove_workspace (workspace);
301+
queue_remove_workspace (workspace);
296302
}
297303
}
298304
}

0 commit comments

Comments
 (0)