[gnome-shell] workspaces-display: Make workspacesView private



commit f2c79be11aca5990090a2012b88a16376a724791
Author: Florian MÃllner <fmuellner gnome org>
Date:   Sat Nov 26 00:02:13 2011 +0100

    workspaces-display: Make workspacesView private
    
    WorkspacesDisplay was introduced to manage the workspace objects
    and views; however, the overview still accesses the view held
    by the workspacesDisplay directly, which is a bit odd.
    Add some additional methods needed by the overview, and make the
    view a private property.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=652580

 js/ui/overview.js       |   15 ++--------
 js/ui/viewSelector.js   |   23 ---------------
 js/ui/workspace.js      |   16 +++-------
 js/ui/workspacesView.js |   71 ++++++++++++++++++++++++++++++++++------------
 4 files changed, 60 insertions(+), 65 deletions(-)
---
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 1f66d75..fa3650a 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -108,7 +108,6 @@ const Overview = new Lang.Class({
         if (this.isDummy) {
             this.animationInProgress = false;
             this.visible = false;
-            this.workspaces = null;
             return;
         }
 
@@ -180,8 +179,6 @@ const Overview = new Lang.Class({
         this._lastActiveWorkspaceIndex = -1;
         this._lastHoveredWindow = null;
         this._needsFakePointerEvent = false;
-
-        this.workspaces = null;
     },
 
     // The members we construct that are implemented in JS might
@@ -587,13 +584,10 @@ const Overview = new Lang.Class({
 
         this._workspacesDisplay.show();
 
-        this.workspaces = this._workspacesDisplay.workspacesView;
-        global.overlay_group.add_actor(this.workspaces.actor);
-
         if (!this._desktopFade.child)
             this._desktopFade.child = this._getDesktopClone();
 
-        if (!this.workspaces.getActiveWorkspace().hasMaximizedWindows()) {
+        if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows()) {
             this._desktopFade.opacity = 255;
             this._desktopFade.show();
             Tweener.addTween(this._desktopFade,
@@ -728,7 +722,7 @@ const Overview = new Lang.Class({
         this.animationInProgress = true;
         this._hideInProgress = true;
 
-        if (!this.workspaces.getActiveWorkspace().hasMaximizedWindows()) {
+        if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows()) {
             this._desktopFade.opacity = 0;
             this._desktopFade.show();
             Tweener.addTween(this._desktopFade,
@@ -737,7 +731,7 @@ const Overview = new Lang.Class({
                                transition: 'easeOutQuad' });
         }
 
-        this.workspaces.hide();
+        this._workspacesDisplay.zoomFromOverview();
 
         // Make other elements fade out.
         Tweener.addTween(this._group,
@@ -779,9 +773,6 @@ const Overview = new Lang.Class({
 
         global.window_group.show();
 
-        this.workspaces.destroy();
-        this.workspaces = null;
-
         this._workspacesDisplay.hide();
 
         this._desktopFade.hide();
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index f7bf491..fa0418c 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -419,29 +419,6 @@ const ViewSelector = new Lang.Class({
         // not when setting the initially selected one.
         if (!tab.visible)
             tab.show(!firstSwitch);
-
-        // Pull a Meg Ryan:
-        if (!firstSwitch && Main.overview.workspaces) {
-            if (tab != this._tabs[0]) {
-                Tweener.addTween(Main.overview.workspaces.actor,
-                                 { opacity: 0,
-                                   time: 0.1,
-                                   transition: 'easeOutQuad',
-                                   onComplete: Lang.bind(this,
-                                       function() {
-                                           Main.overview.workspaces.actor.hide();
-                                           Main.overview.workspaces.actor.opacity = 255;
-                                       })
-                                });
-            } else {
-                Main.overview.workspaces.actor.opacity = 0;
-                Main.overview.workspaces.actor.show();
-                Tweener.addTween(Main.overview.workspaces.actor,
-                                 { opacity: 255,
-                                   time: 0.1,
-                                   transition: 'easeOutQuad' });
-            }
-        }
     },
 
     switchTab: function(id) {
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index d7b61df..6ac9f01 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -94,10 +94,11 @@ const ScaledPoint = new Lang.Class({
 const WindowClone = new Lang.Class({
     Name: 'WindowClone',
 
-    _init : function(realWindow) {
+    _init : function(realWindow, workspace) {
         this.realWindow = realWindow;
         this.metaWindow = realWindow.meta_window;
         this.metaWindow._delegate = this;
+        this._workspace = workspace;
 
         let [borderX, borderY] = this._getInvisibleBorderPadding();
         this._windowClone = new Clutter.Clone({ source: realWindow.get_texture(),
@@ -383,19 +384,12 @@ const WindowClone = new Lang.Class({
         this.emit('drag-begin');
     },
 
-    _getWorkspaceActor : function() {
-        let index = this.metaWindow.get_workspace().index();
-        return Main.overview.workspaces.getWorkspaceByIndex(index);
-    },
-
     handleDragOver : function(source, actor, x, y, time) {
-        let workspace = this._getWorkspaceActor();
-        return workspace.handleDragOver(source, actor, x, y, time);
+        return this._workspace.handleDragOver(source, actor, x, y, time);
     },
 
     acceptDrop : function(source, actor, x, y, time) {
-        let workspace = this._getWorkspaceActor();
-        workspace.acceptDrop(source, actor, x, y, time);
+        this._workspace.acceptDrop(source, actor, x, y, time);
     },
 
     _onDragCancelled : function (draggable, time) {
@@ -1386,7 +1380,7 @@ const Workspace = new Lang.Class({
 
     // Create a clone of a (non-desktop) window and add it to the window list
     _addWindowClone : function(win) {
-        let clone = new WindowClone(win);
+        let clone = new WindowClone(win, this);
         let overlay = new WindowOverlay(clone, this._windowOverlaysGroup);
 
         clone.connect('selected',
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index fb45e21..fd4cef1 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -157,10 +157,6 @@ const WorkspacesView = new Lang.Class({
         return this._workspaces[active];
     },
 
-    getWorkspaceByIndex: function(index) {
-        return this._workspaces[index];
-    },
-
     hide: function() {
         let activeWorkspaceIndex = global.screen.get_active_workspace_index();
         let activeWorkspace = this._workspaces[activeWorkspaceIndex];
@@ -462,6 +458,7 @@ const WorkspacesDisplay = new Lang.Class({
         this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
         this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
         this.actor.connect('allocate', Lang.bind(this, this._allocate));
+        this.actor.connect('parent-set', Lang.bind(this, this._parentSet));
         this.actor.set_clip_to_allocation(true);
 
         let controls = new St.Bin({ style_class: 'workspace-controls',
@@ -483,7 +480,7 @@ const WorkspacesDisplay = new Lang.Class({
         this._thumbnailsBox = new WorkspaceThumbnail.ThumbnailsBox();
         controls.add_actor(this._thumbnailsBox.actor);
 
-        this.workspacesView = null;
+        this._workspacesView = null;
 
         this._inDrag = false;
         this._cancelledDrag = false;
@@ -514,6 +511,7 @@ const WorkspacesDisplay = new Lang.Class({
         this._windowDragBeginId = 0;
         this._windowDragCancelledId = 0;
         this._windowDragEndId = 0;
+        this._notifyOpacityId = 0;
     },
 
     show: function() {
@@ -530,10 +528,11 @@ const WorkspacesDisplay = new Lang.Class({
             this._workspaces[i] = new Workspace.Workspace(metaWorkspace, this._monitorIndex);
         }
 
-        if (this.workspacesView)
-            this.workspacesView.destroy();
-        this.workspacesView = new WorkspacesView(this._workspaces);
+        if (this._workspacesView)
+            this._workspacesView.destroy();
+        this._workspacesView = new WorkspacesView(this._workspaces);
         this._updateWorkspacesGeometry();
+        global.overlay_group.add_actor(this._workspacesView.actor);
 
         this._restackedNotifyId =
             global.screen.connect('restacked',
@@ -564,6 +563,10 @@ const WorkspacesDisplay = new Lang.Class({
         this._onRestacked();
     },
 
+    zoomFromOverview: function() {
+        this._workspacesView.hide();
+    },
+
     hide: function() {
         this._controls.hide();
         this._thumbnailsBox.hide();
@@ -597,14 +600,18 @@ const WorkspacesDisplay = new Lang.Class({
             this._windowDragEndId = 0;
         }
 
-        this.workspacesView.destroy();
-        this.workspacesView = null;
+        this._workspacesView.destroy();
+        this._workspacesView = null;
         for (let w = 0; w < this._workspaces.length; w++) {
             this._workspaces[w].disconnectAll();
             this._workspaces[w].destroy();
         }
     },
 
+    activeWorkspaceHasMaximizedWindows: function() {
+        return this._workspacesView.getActiveWorkspace().hasMaximizedWindows();
+    },
+
     // zoomFraction property allows us to tween the controls sliding in and out
     set zoomFraction(fraction) {
         this._zoomFraction = fraction;
@@ -675,8 +682,34 @@ const WorkspacesDisplay = new Lang.Class({
         this._updateWorkspacesGeometry();
     },
 
+    _parentSet: function(actor, oldParent) {
+        if (oldParent && this._notifyOpacityId)
+            oldParent.disconnect(this._notifyOpacityId);
+        this._notifyOpacityId = 0;
+
+        Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this,
+            function() {
+                let newParent = this.actor.get_parent();
+                if (!newParent)
+                    return;
+
+                // This is kinda hackish - we want the primary view to
+                // appear as parent of this.actor, though in reality it
+                // is added directly to overlay_group
+                this._notifyOpacityId = newParent.connect('notify::opacity',
+                    Lang.bind(this, function() {
+                        let opacity = this.actor.get_parent().opacity;
+                        this._workspacesView.actor.opacity = opacity;
+                        if (opacity == 0)
+                            this._workspacesView.actor.hide();
+                        else
+                            this._workspacesView.actor.show();
+                    }));
+        }));
+    },
+
     _updateWorkspacesGeometry: function() {
-        if (!this.workspacesView)
+        if (!this._workspacesView)
             return;
 
         let fullWidth = this.actor.allocation.x2 - this.actor.allocation.x1;
@@ -697,7 +730,7 @@ const WorkspacesDisplay = new Lang.Class({
         let clipX = rtl ? x + controlsVisible : x;
         let clipY = y + (fullHeight - clipHeight) / 2;
 
-        this.workspacesView.setClipRect(clipX, clipY, clipWidth, clipHeight);
+        this._workspacesView.setClipRect(clipX, clipY, clipWidth, clipHeight);
 
         if (this._zoomOut) {
             width -= controlsNatural;
@@ -713,7 +746,7 @@ const WorkspacesDisplay = new Lang.Class({
         let difference = fullHeight - height;
         y += difference / 2;
 
-        this.workspacesView.setGeometry(x, y, width, height, difference);
+        this._workspacesView.setGeometry(x, y, width, height, difference);
     },
 
     _onRestacked: function() {
@@ -725,7 +758,7 @@ const WorkspacesDisplay = new Lang.Class({
             stackIndices[stack[i].get_meta_window().get_stable_sequence()] = i;
         }
 
-        this.workspacesView.syncStacking(stackIndices);
+        this._workspacesView.syncStacking(stackIndices);
         this._thumbnailsBox.syncStacking(stackIndices);
     },
 
@@ -740,7 +773,7 @@ const WorkspacesDisplay = new Lang.Class({
         this._updateAlwaysZoom();
         this._updateZoom();
 
-        if (this.workspacesView == null)
+        if (this._workspacesView == null)
             return;
 
         let lostWorkspaces = [];
@@ -776,8 +809,8 @@ const WorkspacesDisplay = new Lang.Class({
             this._thumbnailsBox.removeThumbmails(removedIndex, removedNum);
         }
 
-        this.workspacesView.updateWorkspaces(oldNumWorkspaces,
-                                             newNumWorkspaces);
+        this._workspacesView.updateWorkspaces(oldNumWorkspaces,
+                                              newNumWorkspaces);
     },
 
     _updateZoom : function() {
@@ -789,7 +822,7 @@ const WorkspacesDisplay = new Lang.Class({
             this._zoomOut = shouldZoom;
             this._updateWorkspacesGeometry();
 
-            if (!this.workspacesView)
+            if (!this._workspacesView)
                 return;
 
             Tweener.addTween(this,
@@ -797,7 +830,7 @@ const WorkspacesDisplay = new Lang.Class({
                                time: WORKSPACE_SWITCH_TIME,
                                transition: 'easeOutQuad' });
 
-            this.workspacesView.updateWindowPositions();
+            this._workspacesView.updateWindowPositions();
         }
     },
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]