Skip to content

Commit c3e0cec

Browse files
authored
WorkspaceManager: Fix dynamic workspaces (#2286)
1 parent 6698bb2 commit c3e0cec

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed

src/WorkspaceManager.vala

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,8 @@ public class Gala.WorkspaceManager : Object {
9898
}
9999

100100
private void workspace_switched (Meta.WorkspaceManager manager, int from, int to, Meta.MotionDirection direction) {
101-
// remove empty workspaces after we switched away from them unless it's the last one
102-
var prev_workspace = manager.get_workspace_by_index (from);
103-
if (Utils.get_n_windows (prev_workspace) < 1
104-
&& from != manager.get_n_workspaces () - 1
105-
) {
106-
107-
// If we're about to remove a workspace, cancel any DnD going on in the multitasking view
108-
// or else things might get broke
109-
DragDropAction.cancel_all_by_id ("multitaskingview-window");
110-
111-
queue_remove_workspace (prev_workspace);
112-
}
101+
// remove empty workspaces after we switched away from them
102+
maybe_remove_workspace (manager.get_workspace_by_index (from), null);
113103
}
114104

115105
private void queue_window_added (Meta.Workspace? workspace, Meta.Window window) {
@@ -142,11 +132,6 @@ public class Gala.WorkspaceManager : Object {
142132
return;
143133
}
144134

145-
unowned Meta.WorkspaceManager manager = workspace.get_display ().get_workspace_manager ();
146-
bool is_active_workspace = workspace == manager.get_active_workspace ();
147-
var last_workspace_index = manager.get_n_workspaces () - 1;
148-
unowned var last_workspace = manager.get_workspace_by_index (last_workspace_index);
149-
150135
if (window.window_type != Meta.WindowType.NORMAL
151136
&& window.window_type != Meta.WindowType.DIALOG
152137
&& window.window_type != Meta.WindowType.MODAL_DIALOG
@@ -159,24 +144,7 @@ public class Gala.WorkspaceManager : Object {
159144
return;
160145
}
161146

162-
// remove it right away if it was the active workspace and it's not the very last
163-
// or we are in modal-mode
164-
if ((!is_active_workspace || wm.is_modal ())
165-
&& remove_freeze_count < 1
166-
&& Utils.get_n_windows (workspace, true, window) == 0
167-
&& workspace != last_workspace
168-
) {
169-
queue_remove_workspace (workspace);
170-
}
171-
172-
// if window is the second last and empty, make it the last workspace
173-
if (is_active_workspace
174-
&& remove_freeze_count < 1
175-
&& Utils.get_n_windows (workspace, true, window) == 0
176-
&& workspace.index () == last_workspace_index - 1
177-
) {
178-
queue_remove_workspace (last_workspace);
179-
}
147+
maybe_remove_workspace (workspace, window);
180148
}
181149

182150
private void window_entered_monitor (Meta.Display display, int monitor, Meta.Window window) {
@@ -198,6 +166,28 @@ public class Gala.WorkspaceManager : Object {
198166
manager.append_new_workspace (false, display.get_current_time ());
199167
}
200168

169+
private void maybe_remove_workspace (Meta.Workspace workspace, Meta.Window? window) {
170+
unowned var manager = workspace.get_display ().get_workspace_manager ();
171+
var is_active_workspace = workspace == manager.get_active_workspace ();
172+
var last_workspace_index = manager.get_n_workspaces () - 1 - workspaces_marked_removed.size;
173+
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.index () != last_workspace_index
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 (manager.get_workspace_by_index (last_workspace_index));
188+
}
189+
}
190+
201191
private void queue_remove_workspace (Meta.Workspace workspace) {
202192
// workspace has already been removed
203193
if (workspace in workspaces_marked_removed) {
@@ -273,10 +263,7 @@ public class Gala.WorkspaceManager : Object {
273263
unowned Meta.WorkspaceManager manager = wm.get_display ().get_workspace_manager ();
274264

275265
foreach (var workspace in manager.get_workspaces ()) {
276-
var last_index = manager.get_n_workspaces () - 1;
277-
if (Utils.get_n_windows (workspace) == 0 && workspace.index () != last_index) {
278-
queue_remove_workspace (workspace);
279-
}
266+
maybe_remove_workspace (workspace, null);
280267
}
281268
}
282269
}

0 commit comments

Comments
 (0)