[gnome-shell/wip/pressure: 3/3] layout: Don't show the tray if the user is just skirting the barrier



commit 0b9a8a6fe2e493d470650f1ac143fbf66eaa829a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jul 31 10:58:58 2012 -0300

    layout: Don't show the tray if the user is just skirting the barrier
    
    If the user is just pushing their mouse along the barrier's edge, rather
    than pushing down onto the barrier, we shouldn't show the tray. Do this
    by keeping track of the distance traveled perpendicular to the barrier,
    and releasing the accumulated pressure if we pass a threshold.

 js/ui/layout.js |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index d1bfc97..3b91e96 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -19,6 +19,11 @@ const KEYBOARD_ANIMATION_TIME = 0.5;
 
 const MESSAGE_TRAY_PRESSURE_THRESHOLD = 3000;
 
+// The maximium amount that the user is allowed to travel
+// perpendicular to the barrier before we release the accumulated
+// pressure.
+const MESSAGE_TRAY_MAX_SKIRT = 100;
+
 const LayoutManager = new Lang.Class({
     Name: 'LayoutManager',
 
@@ -229,7 +234,9 @@ const LayoutManager = new Lang.Class({
                                                         y1: monitor.y + monitor.height, y2: monitor.y + monitor.height,
                                                         directions: Meta.BarrierDirection.NEGATIVE_Y });
 
-            this._horizTrayPressure = new PressureBarrier(this._horizTrayBarrier, MESSAGE_TRAY_PRESSURE_THRESHOLD);
+            this._horizTrayPressure = new PressureBarrier(this._horizTrayBarrier,
+                                                          MESSAGE_TRAY_PRESSURE_THRESHOLD,
+                                                          MESSAGE_TRAY_MAX_SKIRT);
             this._horizTrayPressure.connect('trigger', function() {
                 Main.messageTray.openTray();
             });
@@ -1000,10 +1007,11 @@ Signals.addSignalMethods(Chrome.prototype);
 const PressureBarrier = new Lang.Class({
     Name: 'TrayPressure',
 
-    _init: function(barrier, threshold) {
+    _init: function(barrier, pressureThreshold, perpThreshold) {
         this._barrier = barrier;
-        this._threshold = threshold;
-        this._getVelocity = this._makeGetVelocity(barrier);
+        this._pressureThreshold = pressureThreshold;
+        this._perpThreshold = perpThreshold;
+        this._getVelocityAndPerp = this._makeGetVelocityAndPerp(barrier);
 
         this._reset(0);
 
@@ -1018,16 +1026,17 @@ const PressureBarrier = new Lang.Class({
     _reset: function(eventId) {
         this._currentEventId = eventId;
         this._currentPressure = 0;
+        this._perpAccumulator = 0;
     },
 
-    _makeGetVelocity: function(barrier) {
+    _makeGetVelocityAndPerp: function(barrier) {
         if (barrier.y1 === barrier.y2) {
             return function(event) {
-                return Math.abs(event.dy);
+                return [Math.abs(event.dy), event.dx];
             };
         } else {
             return function(event) {
-                return Math.abs(event.dx);
+                return [Math.abs(event.dx), event.dy];
             };
         }
     },
@@ -1040,10 +1049,19 @@ const PressureBarrier = new Lang.Class({
             this._reset(event.event_id);
         }
 
-        let velocity = this._getVelocity(event);
+        let [velocity, perp] = this._getVelocityAndPerp(event);
+        this._perpAccumulator += perp;
+
+        // If the user travels too far in the direction perpendicular
+        // to the barrier, start over from scratch -- the user is simply
+        // trying to skirt along the barrier.
+        if (Math.abs(this._perpAccumulator) >= this._perpThreshold) {
+            this._reset(0);
+            return;
+        }
 
         this._currentPressure += velocity;
-        if (this._currentPressure >= this._threshold) {
+        if (this._currentPressure >= this._pressureThreshold) {
             this.emit('trigger');
             this._reset(0);
         }



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