Refactor how workspaces are tracked upon workspace context change.

This commit is contained in:
Bruce Leidl 2022-11-13 09:17:45 -05:00
parent 2560ec148f
commit 2c8f4aeaa4
2 changed files with 54 additions and 13 deletions

View File

@ -345,18 +345,22 @@ var WorkspaceTracker = class {
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;

View File

@ -435,9 +435,46 @@ class WorkspacesView extends WorkspacesViewBase {
}
}
_refreshMetaWorkspace(metaWorkspace, idx) {
// If the current element at idx matches metaWorkspace don't do anything
if (idx < this._workspaces.length) {
if (this._workspaces[idx].metaWorkspace.get_id() === metaWorkspace.get_id()) {
return;
}
}
let workspace = new Workspace.Workspace(
metaWorkspace,
this._monitorIndex,
this._overviewAdjustment);
if (idx < this._workspaces.length) {
// Replace a current entry
let old = this._workspaces[idx];
this._workspaces[idx] = workspace;
this.add_actor(workspace);
this.set_child_at_index(workspace, idx);
old.destroy();
} else {
// Append a new entry
this.add_actor(workspace);
this._workspaces.push(workspace);
}
}
_refreshWorkspaces() {
for (let ws = this._workspaces.pop(); ws; ws = this._workspaces.pop()) {
ws.destroy();
let workspaceManager = global.workspace_manager;
let nWorkspaces = workspaceManager.n_workspaces;
for (let i = 0; i < nWorkspaces; i++) {
let metaWorkspace = workspaceManager.get_workspace_by_index(i);
this._refreshMetaWorkspace(metaWorkspace, i);
}
for (let i = this._workspaces.length - 1; i >= nWorkspaces; i--) {
this._workspaces[i].destroy();
this._workspaces.splice(i, 1);
}
this._updateWorkspaces();
}