[gnome-shell/wip/pressure: 206/207] layout: Trigger the message tray by downward pressure
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/pressure: 206/207] layout: Trigger the message tray by downward pressure
- Date: Fri, 31 Aug 2012 20:30:47 +0000 (UTC)
commit 54febe3d1099630d23ad63da7ce52472b1c01479
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 | 37 +-------------------
2 files changed, 83 insertions(+), 47 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index 493c73a..cc7c792 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -18,6 +18,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 MonitorConstraint = new Lang.Class({
Name: 'MonitorConstraint',
Extends: Clutter.Constraint,
@@ -102,7 +104,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);
@@ -123,7 +126,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,
@@ -277,19 +280,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();
+ });
}
},
@@ -1052,5 +1070,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 2d7ef8e..2dcd649 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1489,44 +1489,9 @@ const MessageTray = new Lang.Class({
this._summaryItems = [];
this._chatSummaryItemsCount = 0;
-
- let pointerWatcher = PointerWatcher.getPointerWatcher();
- pointerWatcher.addWatch(TRAY_DWELL_CHECK_INTERVAL, Lang.bind(this, this._checkTrayDwell));
- this._trayDwellTimeoutId = 0;
- this._trayDwelling = false;
},
- _checkTrayDwell: function(x, y) {
- let monitor = Main.layoutManager.bottomMonitor;
- let shouldDwell = (x >= monitor.x && x <= monitor.x + monitor.width &&
- y == monitor.y + monitor.height - 1);
- if (shouldDwell) {
- // We only set up dwell timeout when the user is not hovering over the tray
- // (!this.actor.hover). This avoids bringing up the message tray after the
- // user clicks on a notification with the pointer on the bottom pixel
- // of the monitor. The _trayDwelling variable is used so that we only try to
- // fire off one tray dwell - if it fails (because, say, the user has the mouse down),
- // we don't try again until the user moves the mouse up and down again.
- if (!this._trayDwelling && !this.actor.hover && this._trayDwellTimeoutId == 0)
- this._trayDwellTimeoutId = Mainloop.timeout_add(TRAY_DWELL_TIME,
- Lang.bind(this, this._trayDwellTimeout));
- this._trayDwelling = true;
- } else {
- this._cancelTrayDwell();
- this._trayDwelling = false;
- }
- },
-
- _cancelTrayDwell: function() {
- if (this._trayDwellTimeoutId != 0) {
- Mainloop.source_remove(this._trayDwellTimeoutId);
- this._trayDwellTimeoutId = 0;
- }
- },
-
- _trayDwellTimeout: function() {
- this._trayDwellTimeoutId = 0;
-
+ openTray: function() {
this._traySummoned = true;
this._updateState();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]