Skip to content

Commit

Permalink
[Scale] Refactoring (7): Move more members from display to view.
Browse files Browse the repository at this point in the history
  • Loading branch information
autarkper committed Nov 20, 2012
1 parent 0405db4 commit 4da562f
Showing 1 changed file with 29 additions and 49 deletions.
78 changes: 29 additions & 49 deletions js/ui/workspacesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ WorkspacesView.prototype = {
this._animating = false; // tweening
this._scrolling = false; // swipe-scrolling
this._animatingScroll = false; // programatically updating the adjustment
this._zoomOut = false; // zoom to a larger area

let activeWorkspaceIndex = global.screen.get_active_workspace_index();
this._workspaces = [];
Expand Down Expand Up @@ -82,13 +81,25 @@ WorkspacesView.prototype = {
this._scrollAdjustment.connect('notify::value',
Lang.bind(this, this._onScroll));

this._switchWorkspaceNotifyId =
global.window_manager.connect('switch-workspace',
Lang.bind(this, this._activeWorkspaceChanged));

this._swipeScrollBeginId = 0;
this._swipeScrollEndId = 0;

let restackedNotifyId = global.screen.connect('restacked', Lang.bind(this, this._onRestacked));
let switchWorkspaceNotifyId = global.window_manager.connect('switch-workspace',
Lang.bind(this, this._activeWorkspaceChanged));

let nWorkspacesChangedId = global.screen.connect('notify::n-workspaces', Main.overview.hide);
let monitorsChangedId = Main.layoutManager.connect('monitors-changed', Main.overview.hide);

this._disconnectHandlers = function() {
global.window_manager.disconnect(switchWorkspaceNotifyId);
Main.layoutManager.disconnect(monitorsChangedId);
global.screen.disconnect(nWorkspacesChangedId);
global.screen.disconnect(restackedNotifyId);
};

this._onRestacked();
this.actor.connect('key-press-event', Lang.bind(this, this._onStageKeyPress));
global.stage.set_key_focus(this.actor);
},
Expand Down Expand Up @@ -162,11 +173,6 @@ WorkspacesView.prototype = {
this.actor.destroy();
},

syncStacking: function(stackIndices) {
for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].syncStacking(stackIndices);
},

updateWindowPositions: function() {
for (let w = 0; w < this._workspaces.length; w++)
this._workspaces[w].positionWindows(Workspace.WindowPositionFlags.ANIMATE);
Expand Down Expand Up @@ -269,7 +275,7 @@ WorkspacesView.prototype = {

_onDestroy: function() {
this._scrollAdjustment.run_dispose();
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
this._disconnectHandlers();
},

_onMappedChanged: function() {
Expand Down Expand Up @@ -312,6 +318,19 @@ WorkspacesView.prototype = {
this._updateVisibility();
},

_onRestacked: function() {
let stack = global.get_window_actors().reverse();
let stackIndices = {};

for (let i = 0; i < stack.length; i++) {
// Use the stable sequence for an integer to use as a hash key
stackIndices[stack[i].get_meta_window().get_stable_sequence()] = i;
}

for (let i = 0; i < this._workspaces.length; i++)
this._workspaces[i].syncStacking(stackIndices);
},

// sync the workspaces' positions to the value of the scroll adjustment
// and change the active workspace if appropriate
_onScroll: function(adj) {
Expand Down Expand Up @@ -362,38 +381,15 @@ WorkspacesDisplay.prototype = {
this.actor.connect('scroll-event',
Lang.bind(this, this._onScrollEvent));

this._monitorIndex = Main.layoutManager.primaryIndex;

this.workspacesView = null;

this._zoomOut = false;

Main.layoutManager.connect('monitors-changed', Main.overview.hide);

this._switchWorkspaceNotifyId = 0;
this._nWorkspacesChangedId = 0;
},

show: function() {
this.workspacesView = new WorkspacesView();
this._updateWorkspacesGeometry();

this._restackedNotifyId =
global.screen.connect('restacked',
Lang.bind(this, this._onRestacked));

if (this._nWorkspacesChangedId == 0)
this._nWorkspacesChangedId = global.screen.connect('notify::n-workspaces',
Lang.bind(this, this._workspacesChanged));
this._onRestacked();
},

hide: function() {
if (this._restackedNotifyId > 0){
global.screen.disconnect(this._restackedNotifyId);
this._restackedNotifyId = 0;
}

this.workspacesView.destroy();
this.workspacesView = null;
},
Expand Down Expand Up @@ -426,22 +422,6 @@ WorkspacesDisplay.prototype = {
this.workspacesView.setGeometry(x, y, width, height, difference);
},

_onRestacked: function() {
let stack = global.get_window_actors().reverse();
let stackIndices = {};

for (let i = 0; i < stack.length; i++) {
// Use the stable sequence for an integer to use as a hash key
stackIndices[stack[i].get_meta_window().get_stable_sequence()] = i;
}

this.workspacesView.syncStacking(stackIndices);
},

_workspacesChanged: function() {
Main.overview.hide();
},

_onScrollEvent: function (actor, event) {
switch ( event.get_scroll_direction() ) {
case Clutter.ScrollDirection.UP:
Expand Down

0 comments on commit 4da562f

Please sign in to comment.