[gnome-shell/wip/hot-corner-barriers: 5/11] layout: Allow multiple barriers to contribute to a PressureBarrier
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/hot-corner-barriers: 5/11] layout: Allow multiple barriers to contribute to a PressureBarrier
- Date: Mon, 4 Mar 2013 19:19:49 +0000 (UTC)
commit 99379e4b58b31abc3ed6402441994db0d1d6ff66
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Mar 1 14:57:38 2013 -0500
layout: Allow multiple barriers to contribute to a PressureBarrier
For the HotCorner case, we want to have to barriers both contribute
to the hot corner pressure, so we can't simply wrap the pressure
barrier.
js/ui/layout.js | 73 +++++++++++++++++++++++++++++++++----------------------
1 files changed, 44 insertions(+), 29 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index 7020c30..7fa982a 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -191,6 +191,7 @@ const LayoutManager = new Lang.Class({
this.trayBox = new St.Widget({ name: 'trayBox',
layout_manager: new Clutter.BinLayout() });
this.addChrome(this.trayBox);
+ this._setupTrayPressure();
this.keyboardBox = new St.BoxLayout({ name: 'keyboardBox',
reactive: true,
@@ -423,33 +424,31 @@ const LayoutManager = new Lang.Class({
}
},
+ _setupTrayPressure: function() {
+ this._trayPressure = new PressureBarrier(MESSAGE_TRAY_PRESSURE_THRESHOLD,
+ MESSAGE_TRAY_PRESSURE_TIMEOUT,
+ Shell.KeyBindingMode.NORMAL |
+ Shell.KeyBindingMode.OVERVIEW);
+ this._trayPressure.setEventFilter(this._trayBarrierEventFilter);
+ this._trayPressure.connect('trigger', function(barrier) {
+ Main.messageTray.openTray();
+ });
+ },
+
_updateTrayBarrier: function() {
let monitor = this.bottomMonitor;
if (this._trayBarrier) {
+ this._trayPressure.removeBarrier(this._trayBarrier);
this._trayBarrier.destroy();
this._trayBarrier = null;
}
- if (this._trayPressure) {
- this._trayPressure.destroy();
- this._trayPressure = null;
- }
-
this._trayBarrier = 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._trayPressure = new PressureBarrier(this._trayBarrier,
- MESSAGE_TRAY_PRESSURE_THRESHOLD,
- MESSAGE_TRAY_PRESSURE_TIMEOUT,
- Shell.KeyBindingMode.NORMAL |
- Shell.KeyBindingMode.OVERVIEW);
- this._trayPressure.setEventFilter(this._trayBarrierEventFilter);
- this._trayPressure.connect('trigger', function(barrier) {
- Main.messageTray.openTray();
- });
+ this._trayPressure.addBarrier(this._trayBarrier);
},
_trayBarrierEventFilter: function(event) {
@@ -1273,25 +1272,37 @@ const HotCorner = new Lang.Class({
const PressureBarrier = new Lang.Class({
Name: 'PressureBarrier',
- _init: function(barrier, threshold, timeout, keybindingMode) {
- this._barrier = barrier;
+ _init: function(threshold, timeout, keybindingMode) {
this._threshold = threshold;
this._timeout = timeout;
this._keybindingMode = keybindingMode;
- this._orientation = (barrier.y1 == barrier.y2) ? Clutter.Orientation.HORIZONTAL :
Clutter.Orientation.VERTICAL;
+ this._barriers = [];
this._eventFilter = null;
this._isTriggered = false;
this._reset();
+ },
+
+ addBarrier: function(barrier) {
+ barrier._pressureHitId = barrier.connect('hit', Lang.bind(this, this._onBarrierHit));
+ barrier._pressureLeftId = barrier.connect('left', Lang.bind(this, this._onBarrierLeft));
- this._barrierHitId = this._barrier.connect('hit', Lang.bind(this, this._onBarrierHit));
- this._barrierLeftId = this._barrier.connect('left', Lang.bind(this, this._onBarrierLeft));
+ this._barriers.push(barrier);
+ },
+
+ _disconnectBarrier: function(barrier) {
+ barrier.disconnect(barrier._pressureHitId);
+ barrier.disconnect(barrier._pressureLeftId);
+ },
+
+ removeBarrier: function(barrier) {
+ this._disconnectBarrier(barrier);
+ this._barriers.splice(this._barriers.indexOf(barrier), 1);
},
destroy: function() {
- this._barrier.disconnect(this._barrierHitId);
- this._barrier.disconnect(this._barrierLeftId);
- this._barrier = null;
+ this._barriers.forEach(Lang.bind(this, this._disconnectBarrier));
+ this._barriers = [];
},
setEventFilter: function(filter) {
@@ -1304,15 +1315,19 @@ const PressureBarrier = new Lang.Class({
this._lastTime = 0;
},
- _getDistanceAcrossBarrier: function(event) {
- if (this._orientation == Clutter.Orientation.HORIZONTAL)
+ _isHorizontal: function(barrier) {
+ return barrier.y1 == barrier.y2;
+ },
+
+ _getDistanceAcrossBarrier: function(barrier, event) {
+ if (this._isHorizontal(barrier))
return Math.abs(event.dy);
else
return Math.abs(event.dx);
},
- _getDistanceAlongBarrier: function(event) {
- if (this._orientation == Clutter.Orientation.HORIZONTAL)
+ _getDistanceAlongBarrier: function(barrier, event) {
+ if (this._isHorizontal(barrier))
return Math.abs(event.dx);
else
return Math.abs(event.dy);
@@ -1366,8 +1381,8 @@ const PressureBarrier = new Lang.Class({
if (!(this._keybindingMode & Main.keybindingMode))
return;
- let slide = this._getDistanceAlongBarrier(event);
- let distance = this._getDistanceAcrossBarrier(event);
+ let slide = this._getDistanceAlongBarrier(barrier, event);
+ let distance = this._getDistanceAcrossBarrier(barrier, event);
if (distance >= this._threshold) {
this._trigger();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]