Skip to content

Commit d4e98d8

Browse files
committed
Fix removal once again :(
1 parent d558bf3 commit d4e98d8

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

src/WorkspaceManager.vala

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,8 @@ public class Gala.WorkspaceManager : Object {
110110
return;
111111
}
112112

113-
// remove empty workspaces after we switched away from them unless it's the last one
114-
var prev_workspace = manager.get_workspace_by_index (from);
115-
if (Utils.get_n_windows (prev_workspace) < 1
116-
&& from != manager.get_n_workspaces () - 1
117-
) {
118-
119-
// If we're about to remove a workspace, cancel any DnD going on in the multitasking view
120-
// or else things might get broke
121-
DragDropAction.cancel_all_by_id ("multitaskingview-window");
122-
123-
queue_remove_workspace (prev_workspace);
124-
}
113+
// remove empty workspaces after we switched away from them
114+
maybe_remove_workspace (manager.get_workspace_by_index (from), null);
125115
}
126116

127117
private void queue_window_added (Meta.Workspace? workspace, Meta.Window window) {
@@ -154,11 +144,6 @@ public class Gala.WorkspaceManager : Object {
154144
return;
155145
}
156146

157-
unowned Meta.WorkspaceManager manager = workspace.get_display ().get_workspace_manager ();
158-
bool is_active_workspace = workspace == manager.get_active_workspace ();
159-
var last_workspace_index = manager.get_n_workspaces () - 1;
160-
unowned var last_workspace = manager.get_workspace_by_index (last_workspace_index);
161-
162147
if (window.window_type != Meta.WindowType.NORMAL
163148
&& window.window_type != Meta.WindowType.DIALOG
164149
&& window.window_type != Meta.WindowType.MODAL_DIALOG
@@ -171,21 +156,7 @@ public class Gala.WorkspaceManager : Object {
171156
return;
172157
}
173158

174-
// remove it right away if it was the active workspace and it's not the very last
175-
// or we are in modal-mode
176-
if ((!is_active_workspace || wm.is_modal ())
177-
&& remove_freeze_count < 1
178-
&& Utils.get_n_windows (workspace, true, window) == 0
179-
&& workspace != last_workspace
180-
) {
181-
queue_remove_workspace (workspace);
182-
} else if (is_active_workspace // if window is the second last and empty, make it the last workspace
183-
&& remove_freeze_count < 1
184-
&& Utils.get_n_windows (workspace, true, window) == 0
185-
&& workspace.index () == last_workspace_index - 1
186-
) {
187-
queue_remove_workspace (last_workspace);
188-
}
159+
maybe_remove_workspace (workspace, window);
189160
}
190161

191162
private void window_entered_monitor (Meta.Display display, int monitor, Meta.Window window) {
@@ -218,6 +189,28 @@ public class Gala.WorkspaceManager : Object {
218189
manager.append_new_workspace (false, display.get_current_time ());
219190
}
220191

192+
private void maybe_remove_workspace (Meta.Workspace workspace, Meta.Window? window) {
193+
unowned var manager = workspace.get_display ().get_workspace_manager ();
194+
var is_active_workspace = workspace == manager.get_active_workspace ();
195+
var last_workspace_index = manager.get_n_workspaces () - 1 - workspaces_marked_removed.size;
196+
197+
// remove it right away if it was the active workspace and it's not the very last
198+
// or we are in modal-mode
199+
if ((!is_active_workspace || wm.is_modal ())
200+
&& remove_freeze_count < 1
201+
&& Utils.get_n_windows (workspace, true, window) == 0
202+
&& workspace.index () != last_workspace_index
203+
) {
204+
queue_remove_workspace (workspace);
205+
} else if (is_active_workspace // if window is the second last and empty, make it the last workspace
206+
&& remove_freeze_count < 1
207+
&& Utils.get_n_windows (workspace, true, window) == 0
208+
&& workspace.index () == last_workspace_index - 1
209+
) {
210+
queue_remove_workspace (manager.get_workspace_by_index (last_workspace_index));
211+
}
212+
}
213+
221214
private void queue_remove_workspace (Meta.Workspace workspace) {
222215
// workspace has already been removed
223216
if (workspace in workspaces_marked_removed) {
@@ -297,10 +290,7 @@ public class Gala.WorkspaceManager : Object {
297290
unowned Meta.WorkspaceManager manager = wm.get_display ().get_workspace_manager ();
298291

299292
foreach (var workspace in manager.get_workspaces ()) {
300-
var last_index = manager.get_n_workspaces () - 1;
301-
if (Utils.get_n_windows (workspace) == 0 && workspace.index () != last_index) {
302-
queue_remove_workspace (workspace);
303-
}
293+
maybe_remove_workspace (workspace, null);
304294
}
305295
}
306296
}

0 commit comments

Comments
 (0)