WorkspacesView: fix removal of workspaces that are not at the end

Workspaces can removed from any index, and in particular they
will be removed by the WorkspaceTracker if they stop containing
windows at some point. Make sure WorkspacesView is not confused
and destroyes the right Workspace objects.

https://bugzilla.gnome.org/show_bug.cgi?id=721417
This commit is contained in:
Giovanni Campagna 2014-01-03 19:04:06 +01:00
parent d9624d9882
commit 1b152e6bd0

View File

@ -237,29 +237,32 @@ const WorkspacesView = new Lang.Class({
}, },
_updateWorkspaces: function() { _updateWorkspaces: function() {
let oldNumWorkspaces = this._workspaces.length;
let newNumWorkspaces = global.screen.n_workspaces; let newNumWorkspaces = global.screen.n_workspaces;
this.scrollAdjustment.upper = newNumWorkspaces; this.scrollAdjustment.upper = newNumWorkspaces;
if (newNumWorkspaces > oldNumWorkspaces) { let needsUpdate = false;
for (let w = oldNumWorkspaces; w < newNumWorkspaces; w++) { for (let j = 0; j < newNumWorkspaces; j++) {
let metaWorkspace = global.screen.get_workspace_by_index(w); let metaWorkspace = global.screen.get_workspace_by_index(j);
let workspace = new Workspace.Workspace(metaWorkspace, this._monitorIndex); let workspace;
this._workspaces.push(workspace);
this.actor.add_actor(workspace.actor);
}
if (this._fullGeometry) if (j >= this._workspaces.length) { /* added */
this._updateWorkspaceActors(false); workspace = new Workspace.Workspace(metaWorkspace, this._monitorIndex);
} else if (newNumWorkspaces < oldNumWorkspaces) { this.actor.add_actor(workspace.actor);
let nRemoved = (newNumWorkspaces - oldNumWorkspaces); this._workspaces[j] = workspace;
let removed = this._workspaces.splice(oldNumWorkspaces, nRemoved); } else {
removed.forEach(function(workspace) { workspace = this._workspaces[j];
workspace.destroy();
}); if (workspace.metaWorkspace != metaWorkspace) { /* removed */
workspace.destroy();
this._workspaces.splice(j, 1);
} /* else kept */
}
} }
if (this._fullGeometry)
this._updateWorkspaceActors(false);
this._syncGeometry(); this._syncGeometry();
}, },