[gnome-shell/wip/re-search-v2: 33/33] workspaceThumbnails: restore previous slide-out behavior



commit b1caf0ede7e205d6819851a7894b11ed6e48e350
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Dec 2 14:37:40 2012 -0500

    workspaceThumbnails: restore previous slide-out behavior

 js/ui/workspaceThumbnail.js |   50 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index 9d55cad..f546c8f 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -497,6 +497,7 @@ const ThumbnailsBox = new Lang.Class({
         this.actor = new Shell.GenericContainer({ reactive: true,
                                                   style_class: 'workspace-thumbnails',
                                                   can_focus: true,
+                                                  track_hover: true,
                                                   request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
         this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
         this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
@@ -525,6 +526,7 @@ const ThumbnailsBox = new Lang.Class({
         this._indicator = indicator;
         this.actor.add_actor(indicator);
 
+        this._inDrag = false;
         this._dropWorkspace = -1;
         this._dropPlaceholderPos = -1;
         this._dropPlaceholder = new St.Bin({ style_class: 'placeholder' });
@@ -550,6 +552,9 @@ const ThumbnailsBox = new Lang.Class({
         this.actor.connect('key-release-event',
                            Lang.bind(this, this._onKeyRelease));
 
+        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._updateTranslation));
+        this.actor.connect('notify::hover', Lang.bind(this, this._updateTranslation));
+
         Main.overview.connect('showing',
                               Lang.bind(this, this._createThumbnails));
         Main.overview.connect('hidden',
@@ -573,6 +578,44 @@ const ThumbnailsBox = new Lang.Class({
             Lang.bind(this, this._updateSwitcherVisibility));
     },
 
+    _getInitialTranslation: function() {
+        // Always show the pager if workspaces are actually used,
+        // e.g. there are windows on more than one
+        let alwaysZoomOut = global.screen.n_workspaces > 2 || this._inDrag;
+
+        if (!alwaysZoomOut) {
+            let monitors = Main.layoutManager.monitors;
+            let primary = Main.layoutManager.primaryMonitor;
+
+            /* Look for any monitor to the right of the primary, if there is
+             * one, we always keep zoom out, otherwise its hard to reach
+             * the thumbnail area without passing into the next monitor. */
+            for (let i = 0; i < monitors.length; i++) {
+                if (monitors[i].x >= primary.x + primary.width) {
+                    alwaysZoomOut = true;
+                    break;
+                }
+            }
+        }
+
+        if (alwaysZoomOut)
+            return 0;
+
+        let rtl = (this.actor.get_text_direction() == Clutter.TextDirection.RTL);
+        return (rtl ? - this.actor.width : this.actor.width) / 2;
+    },
+
+    _updateTranslation: function() {
+        let targetX = this._getInitialTranslation();
+
+        if (this.actor.hover)
+            targetX = 0;
+
+        Tweener.addTween(this.actor, { translation_x: targetX,
+                                       time: SLIDE_ANIMATION_TIME,
+                                       transition: 'easeOutQuad' });
+    },
+
     _updateSwitcherVisibility: function() {
         this.actor.visible =
             this._settings.get_boolean('dynamic-workspaces') ||
@@ -596,6 +639,7 @@ const ThumbnailsBox = new Lang.Class({
     },
 
     _onDragBegin: function() {
+        this._inDrag = true;
         this._dragCancelled = false;
         this._dragMonitor = {
             dragMotion: Lang.bind(this, this._onDragMotion)
@@ -618,6 +662,8 @@ const ThumbnailsBox = new Lang.Class({
     _endDrag: function() {
         this._clearDragPlaceholder();
         DND.removeDragMonitor(this._dragMonitor);
+        this._inDrag = false;
+        this._updateTranslation();
     },
 
     _onDragMotion: function(dragEvent) {
@@ -776,7 +822,7 @@ const ThumbnailsBox = new Lang.Class({
 
         // reset any translation and make sure the actor is visible when
         // entering the overview
-        this.actor.translation_x = 0;
+        this.actor.translation_x = this._getInitialTranslation();
         this.actor.show();
 
         this._updateSwitcherVisibility();
@@ -812,7 +858,7 @@ const ThumbnailsBox = new Lang.Class({
 
     show: function() {
         this.actor.show();
-        Tweener.addTween(this.actor, { translation_x: 0,
+        Tweener.addTween(this.actor, { translation_x: this._getInitialTranslation(),
                                        transition: 'easeOutQuad',
                                        time: SLIDE_ANIMATION_TIME
                                      });



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