[gnome-shell/wip/pressure: 2/3] layout: Trigger the message tray by downward pressure



commit b7fa55f0d30418cb601a60775a0232e9fd735652
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Jul 30 16:25:07 2012 -0300

    layout: Trigger the message tray by downward pressure
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677215

 js/ui/layout.js      |   93 ++++++++++++++++++++++++++++++++++++++++++++------
 js/ui/messageTray.js |   17 +--------
 2 files changed, 83 insertions(+), 27 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index 7320d74..d1bfc97 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -17,6 +17,8 @@ const HOT_CORNER_ACTIVATION_TIMEOUT = 0.5;
 const STARTUP_ANIMATION_TIME = 0.2;
 const KEYBOARD_ANIMATION_TIME = 0.5;
 
+const MESSAGE_TRAY_PRESSURE_THRESHOLD = 3000;
+
 const LayoutManager = new Lang.Class({
     Name: 'LayoutManager',
 
@@ -28,7 +30,8 @@ const LayoutManager = new Lang.Class({
         this._hotCorners = [];
         this._leftPanelBarrier = null;
         this._rightPanelBarrier = null;
-        this._trayBarrier = null;
+        this._vertTrayBarrier = null;
+        this._horizTrayBarrier = null;
 
         this._chrome = new Chrome(this);
 
@@ -48,7 +51,7 @@ const LayoutManager = new Lang.Class({
         this.trayBox = new St.BoxLayout({ name: 'trayBox' }); 
         this.addChrome(this.trayBox);
         this.trayBox.connect('allocation-changed',
-                             Lang.bind(this, this._updateTrayBarrier));
+                             Lang.bind(this, this._updateTrayBarriers));
 
         this.keyboardBox = new St.BoxLayout({ name: 'keyboardBox',
                                               reactive: true,
@@ -202,19 +205,34 @@ const LayoutManager = new Lang.Class({
         }
     },
 
-    _updateTrayBarrier: function() {
+    _updateTrayBarriers: function() {
         let monitor = this.bottomMonitor;
 
-        if (this._trayBarrier) {
-            this._trayBarrier.destroy();
-            this._trayBarrier = null;
+        if (this._vertTrayBarrier) {
+            this._vertTrayBarrier.destroy();
+            this._vertTrayBarrier = null;
+        }
+
+        if (this._horizTrayBarrier) {
+            this._horizTrayBarrier.destroy();
+            this._horizTrayBarrier = null;
         }
 
         if (Main.messageTray) {
-            this._trayBarrier = new Meta.Barrier({ display: global.display,
-                                                   x1: monitor.x + monitor.width, y1: monitor.y + monitor.height - Main.messageTray.actor.height,
-                                                   x2: monitor.x + monitor.width, y2: monitor.y + monitor.height,
-                                                   directions: Meta.BarrierDirection.NEGATIVE_X });
+            this._vertTrayBarrier = new Meta.Barrier({ display: global.display,
+                                                       x1: monitor.x + monitor.width, y1: monitor.y + monitor.height - Main.messageTray.actor.height,
+                                                       x2: monitor.x + monitor.width, y2: monitor.y + monitor.height,
+                                                       directions: Meta.BarrierDirection.NEGATIVE_X });
+
+            this._horizTrayBarrier = new Meta.Barrier({ display: global.display,
+                                                        x1: monitor.x, x2: monitor.x + monitor.width,
+                                                        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.connect('trigger', function() {
+                Main.messageTray.openTray();
+            });
         }
     },
 
@@ -977,5 +995,58 @@ const Chrome = new Lang.Class({
         return false;
     }
 });
-
 Signals.addSignalMethods(Chrome.prototype);
+
+const PressureBarrier = new Lang.Class({
+    Name: 'TrayPressure',
+
+    _init: function(barrier, threshold) {
+        this._barrier = barrier;
+        this._threshold = threshold;
+        this._getVelocity = this._makeGetVelocity(barrier);
+
+        this._reset(0);
+
+        this._barrierHitId = this._barrier.connect('hit', Lang.bind(this, this._onBarrierHit));
+    },
+
+    destroy: function() {
+        this._barrier.disconnect(this._barrierHitId);
+        this._barrier = null;
+    },
+
+    _reset: function(eventId) {
+        this._currentEventId = eventId;
+        this._currentPressure = 0;
+    },
+
+    _makeGetVelocity: function(barrier) {
+        if (barrier.y1 === barrier.y2) {
+            return function(event) {
+                return Math.abs(event.dy);
+            };
+        } else {
+            return function(event) {
+                return Math.abs(event.dx);
+            };
+        }
+    },
+
+    _onBarrierHit: function(barrier, event) {
+        // Event IDs are incremented every time the user stops
+        // hitting the barrier. So, if the event ID switches,
+        // reset the current state, and start over.
+        if (this._currentEventId != event.event_id) {
+            this._reset(event.event_id);
+        }
+
+        let velocity = this._getVelocity(event);
+
+        this._currentPressure += velocity;
+        if (this._currentPressure >= this._threshold) {
+            this.emit('trigger');
+            this._reset(0);
+        }
+    }
+});
+Signals.addSignalMethods(PressureBarrier.prototype);
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index e4c2079..e92379f 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1353,14 +1353,6 @@ const MessageTray = new Lang.Class({
         this._inFullscreen = false;
         this._desktopClone = null;
 
-        this._corner = new Clutter.Rectangle({ width: 1,
-                                               height: 1,
-                                               opacity: 0,
-                                               reactive: true });
-        this._corner.connect('enter-event', Lang.bind(this, this._onCornerEnter));
-        Main.layoutManager.trayBox.add_actor(this._corner);
-        Main.layoutManager.trackChrome(this._corner);
-
         Main.layoutManager.trayBox.add_actor(this.actor);
         this.actor.y = 0;
         Main.layoutManager.trackChrome(this.actor);
@@ -1396,7 +1388,7 @@ const MessageTray = new Lang.Class({
         this._chatSummaryItemsCount = 0;
     },
 
-    _onCornerEnter: function(actor, event) {
+    openTray: function() {
         this._traySummoned = true;
         this._updateState();
     },
@@ -1407,13 +1399,6 @@ const MessageTray = new Lang.Class({
         this._notificationBin.width = monitor.width;
         this._summaryBin.x = 0;
         this._summaryBin.width = monitor.width;
-
-        if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
-            this._corner.x = 0;
-        else
-            this._corner.x = Main.layoutManager.trayBox.width - 1;
-
-        this._corner.y = Main.layoutManager.trayBox.height - 1;
     },
 
     contains: function(source) {



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