Refactor how workspaces are tracked upon workspace context change.

This commit is contained in:
2022-11-13 09:17:45 -05:00
parent b92df61f50
commit 9a32a113b2
2 changed files with 54 additions and 13 deletions

View File

@ -362,18 +362,22 @@ class WorkspaceTracker {
let workspaceManager = global.workspace_manager;
let numWorkspaces = workspaceManager.n_workspaces;
this._workspaces.forEach(workspace => {
workspace.disconnect(workspace._windowAddedId);
workspace.disconnect(workspace._windowRemovedId);
});
for (let i = 0; i < numWorkspaces; i++) {
let workspace = workspaceManager.get_workspace_by_index(i);
this._workspaces = [];
for (let w = 0; w < numWorkspaces; w++) {
let workspace = workspaceManager.get_workspace_by_index(w);
workspace._windowAddedId = workspace.connect('window-added', this._queueCheckWorkspaces.bind(this));
workspace._windowRemovedId = workspace.connect('window-removed', this._windowRemoved.bind(this));
this._workspaces[w] = workspace;
if (i >= this._workspaces.length || this._workspaces[i].get_id() !== workspace.get_id()) {
if (this._workspaces[i]) {
this._workspaces[i].disconnectObject(this);
}
this._workspaces[i] = workspace;
this._workspaces[i].connectObject(
'window-added', this._queueCheckWorkspaces.bind(this),
'window-removed', this._windowRemoved.bind(this), this);
}
}
for (let i = this._workspaces.length - 1; i >= numWorkspaces; i--) {
this._workspaces[i].disconnectObject(this);
this._workspaces.splice(i, 1);
}
this._queueCheckWorkspaces();
return false;