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



commit 60e7136a98756c45cbc7c5a25095dab0a2841f1e
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 |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index cc7c792..7c3bd9a 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -19,6 +19,10 @@ const STARTUP_ANIMATION_TIME = 0.2;
 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 MonitorConstraint = new Lang.Class({
     Name: 'MonitorConstraint',
@@ -304,7 +308,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();
             });
@@ -1075,10 +1081,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);
 
@@ -1093,16 +1100,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];
             };
         }
     },
@@ -1115,10 +1123,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]