From 6c64c0873c64fe233f5bdffb6622cff9f4f689bf Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 13 Dec 2012 11:00:30 -0500 Subject: [PATCH] workspaceThumbnail: unify restack handling Both WorkspacesDisplay and ThumbnailsBox need to know when windows have been restacked. Instead of each tracking changes on their own or trying to call each other, have the overview keep track and do the calculations, emitting a signal with the result. https://bugzilla.gnome.org/show_bug.cgi?id=690175 --- js/ui/overview.js | 14 ++++++++++++++ js/ui/workspaceThumbnail.js | 10 +++++++++- js/ui/workspacesView.js | 18 +++--------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/js/ui/overview.js b/js/ui/overview.js index 5bb8fa1d2..84cd48c6c 100644 --- a/js/ui/overview.js +++ b/js/ui/overview.js @@ -174,6 +174,8 @@ const Overview = new Lang.Class({ Main.xdndHandler.connect('drag-begin', Lang.bind(this, this._onDragBegin)); Main.xdndHandler.connect('drag-end', Lang.bind(this, this._onDragEnd)); + global.screen.connect('restacked', Lang.bind(this, this._onRestacked)); + this._windowSwitchTimeoutId = 0; this._windowSwitchTimestamp = 0; this._lastActiveWorkspaceIndex = -1; @@ -383,6 +385,18 @@ const Overview = new Lang.Class({ this._coverPane.set_size(primary.width, contentHeight); }, + _onRestacked: function() { + let stack = global.get_window_actors(); + 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.emit('windows-restacked', stackIndices); + }, + //// Public methods //// beginItemDrag: function(source) { diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js index b381dab43..fd68ce583 100644 --- a/js/ui/workspaceThumbnail.js +++ b/js/ui/workspaceThumbnail.js @@ -745,6 +745,9 @@ const ThumbnailsBox = new Lang.Class({ this._nWorkspacesNotifyId = global.screen.connect('notify::n-workspaces', Lang.bind(this, this._workspacesChanged)); + this._syncStackingId = + Main.overview.connect('windows-restacked', + Lang.bind(this, this._syncStacking)); this._targetScale = 0; this._scale = 0; @@ -780,6 +783,11 @@ const ThumbnailsBox = new Lang.Class({ this._nWorkspacesNotifyId = 0; } + if (this._syncStackingId > 0) { + Main.overview.disconnect(this._syncStackingId); + this._syncStackingId = 0; + } + for (let w = 0; w < this._thumbnails.length; w++) this._thumbnails[w].destroy(); this._thumbnails = []; @@ -854,7 +862,7 @@ const ThumbnailsBox = new Lang.Class({ this._queueUpdateStates(); }, - syncStacking: function(stackIndices) { + _syncStacking: function(overview, stackIndices) { for (let i = 0; i < this._thumbnails.length; i++) this._thumbnails[i].syncStacking(stackIndices); }, diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js index 5e66c2133..4d22f352f 100644 --- a/js/ui/workspacesView.js +++ b/js/ui/workspacesView.js @@ -577,7 +577,7 @@ const WorkspacesDisplay = new Lang.Class({ this._updateWorkspacesViews(); this._restackedNotifyId = - global.screen.connect('restacked', + Main.overview.connect('windows-restacked', Lang.bind(this, this._onRestacked)); if (this._itemDragBeginId == 0) @@ -598,8 +598,6 @@ const WorkspacesDisplay = new Lang.Class({ if (this._windowDragEndId == 0) this._windowDragEndId = Main.overview.connect('window-drag-end', Lang.bind(this, this._dragEnd)); - - this._onRestacked(); }, zoomFromOverview: function() { @@ -615,7 +613,7 @@ const WorkspacesDisplay = new Lang.Class({ this.zoomFraction = 0; if (this._restackedNotifyId > 0){ - global.screen.disconnect(this._restackedNotifyId); + Main.overview.disconnect(this._restackedNotifyId); this._restackedNotifyId = 0; } if (this._itemDragBeginId > 0) { @@ -877,19 +875,9 @@ const WorkspacesDisplay = new Lang.Class({ } }, - _onRestacked: function() { - let stack = global.get_window_actors(); - 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; - } - + _onRestacked: function(overview, stackIndices) { for (let i = 0; i < this._workspacesViews.length; i++) this._workspacesViews[i].syncStacking(stackIndices); - - this._thumbnailsBox.syncStacking(stackIndices); }, _workspacesChanged: function() {