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



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

    workspaceThumbnails: restore previous slide-out behavior
    
    Start with the workspace selector half-visible, then slide it out either
    on hover, when in drag, or when showing multiple workspaces/when using
    an external monitor with windows on it.

 js/ui/workspaceThumbnail.js |   52 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index 9d55cad..bedefc0 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 when during a drag, or if workspaces are
+        // actually used, e.g. there are windows on more than one
+        let alwaysZoomOut = this._inDrag || global.screen.n_workspaces > 2;
+
+        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,9 @@ const ThumbnailsBox = new Lang.Class({
     },
 
     _onDragBegin: function() {
+        this._inDrag = true;
+        this._updateTranslation();
+
         this._dragCancelled = false;
         this._dragMonitor = {
             dragMotion: Lang.bind(this, this._onDragMotion)
@@ -618,6 +664,8 @@ const ThumbnailsBox = new Lang.Class({
     _endDrag: function() {
         this._clearDragPlaceholder();
         DND.removeDragMonitor(this._dragMonitor);
+        this._inDrag = false;
+        this._updateTranslation();
     },
 
     _onDragMotion: function(dragEvent) {
@@ -776,7 +824,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 +860,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]