Refactor how workspaces are tracked upon workspace context change.
This commit is contained in:
parent
2560ec148f
commit
2c8f4aeaa4
@ -345,18 +345,22 @@ var WorkspaceTracker = class {
|
|||||||
let workspaceManager = global.workspace_manager;
|
let workspaceManager = global.workspace_manager;
|
||||||
let numWorkspaces = workspaceManager.n_workspaces;
|
let numWorkspaces = workspaceManager.n_workspaces;
|
||||||
|
|
||||||
this._workspaces.forEach(workspace => {
|
for (let i = 0; i < numWorkspaces; i++) {
|
||||||
workspace.disconnect(workspace._windowAddedId);
|
let workspace = workspaceManager.get_workspace_by_index(i);
|
||||||
workspace.disconnect(workspace._windowRemovedId);
|
|
||||||
});
|
|
||||||
|
|
||||||
this._workspaces = [];
|
if (i >= this._workspaces.length || this._workspaces[i].get_id() !== workspace.get_id()) {
|
||||||
|
if (this._workspaces[i]) {
|
||||||
for (let w = 0; w < numWorkspaces; w++) {
|
this._workspaces[i].disconnectObject(this);
|
||||||
let workspace = workspaceManager.get_workspace_by_index(w);
|
}
|
||||||
workspace._windowAddedId = workspace.connect('window-added', this._queueCheckWorkspaces.bind(this));
|
this._workspaces[i] = workspace;
|
||||||
workspace._windowRemovedId = workspace.connect('window-removed', this._windowRemoved.bind(this));
|
this._workspaces[i].connectObject(
|
||||||
this._workspaces[w] = workspace;
|
'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();
|
this._queueCheckWorkspaces();
|
||||||
return false;
|
return false;
|
||||||
|
@ -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() {
|
_refreshWorkspaces() {
|
||||||
for (let ws = this._workspaces.pop(); ws; ws = this._workspaces.pop()) {
|
let workspaceManager = global.workspace_manager;
|
||||||
ws.destroy();
|
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();
|
this._updateWorkspaces();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user