[gnome-shell] linearView: Cancel workspace scrolling when the user stops dragging



commit 44c2027b406f4f770845b13f5f774229b9ad2190
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Mon May 10 21:28:26 2010 +0200

    linearView: Cancel workspace scrolling when the user stops dragging
    
    Currently there is no way for the user to cancel a workspace drag action,
    which means the user has to complete the drag action before and move back
    to the other workspace manually afterwards.
    So cancel the drag action when the user stops.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618062

 js/ui/workspacesView.js |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 99f0805..b34c222 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -653,7 +653,7 @@ SingleView.prototype = {
         this._scrolling = false; // dragging scroll bar or desktop
         this._animatingScroll = false; // programatically move the scroll bar
         this._inDrag = false; // dragging a window
-
+        this._lastMotionTime = -1; // used to track "stopping" while dragging workspaces
         let primary = global.get_primary_monitor();
         this._dropGroup = new Clutter.Group({ x: 0, y: 0,
                                               width: primary.width,
@@ -833,11 +833,21 @@ SingleView.prototype = {
                 let activate = this._dragIndex;
                 let last = global.screen.n_workspaces - 1;
 
-                // switch workspaces according to the drag direction
-                if (stageX > this._dragStartX && activate > 0)
-                    activate--;
-                else if (stageX < this._dragStartX && activate < last)
-                    activate++;
+                // If the user has moved more than half a workspace, we want to "settle"
+                // to the new workspace even if the user stops dragging rather "throws"
+                // by releasing during the drag.
+                let noStop = Math.abs(activate - this._scroll.adjustment.value) > 0.5;
+
+                // We detect if the user is stopped by comparing the timestamp of the button
+                // release with the timestamp of the last motion. Experimentally, a difference
+                // of 0 or 1 millisecond indicates that the mouse is in motion, a larger
+                // difference indicates that the mouse is stopped.
+                if ((this._lastMotionTime > 0 && this._lastMotionTime > event.get_time() - 2) || noStop) {
+                    if (stageX > this._dragStartX && activate > 0)
+                        activate--;
+                    else if (stageX < this._dragStartX && activate < last)
+                        activate++;
+                }
 
                 if (activate != active) {
                     let workspace = this._workspaces[activate].metaWorkspace;
@@ -859,6 +869,7 @@ SingleView.prototype = {
 
                 this._scroll.adjustment.value += (dx / primary.width);
                 this._dragX = stageX;
+                this._lastMotionTime = event.get_time();
 
                 return true;
         }



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