[gnome-shell] swipeTracker: Try harder to start touchpad gestures with a direction
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] swipeTracker: Try harder to start touchpad gestures with a direction
- Date: Wed, 17 Feb 2021 13:23:04 +0000 (UTC)
commit 504ca7d4c33f2138ae560b2f5b8f0e22630addeb
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Feb 12 12:13:57 2021 +0100
swipeTracker: Try harder to start touchpad gestures with a direction
Make the touchpad gesture keep track of its state, and enter in a
rejected state if the swipe is happening in the wrong direction.
Effectively, this means touchpad gestures are locked on a single
direction, and horizontal+vertical swipeTrackers won't be handling
events at the same time.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1643>
js/ui/swipeTracker.js | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index 5bc2c49e48..cf5e01d716 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -39,6 +39,12 @@ const State = {
SCROLLING: 1,
};
+const TouchpadState = {
+ NONE: 0,
+ HANDLING: 1,
+ IGNORED: 2,
+};
+
const EventHistory = class {
constructor() {
this.reset();
@@ -98,6 +104,7 @@ const TouchpadSwipeGesture = GObject.registerClass({
_init(allowedModes) {
super._init();
this._allowedModes = allowedModes;
+ this._state = TouchpadState.NONE;
this._touchpadSettings = new Gio.Settings({
schema_id: 'org.gnome.desktop.peripherals.touchpad',
});
@@ -110,6 +117,9 @@ const TouchpadSwipeGesture = GObject.registerClass({
if (event.type() !== Clutter.EventType.TOUCHPAD_SWIPE)
return Clutter.EVENT_PROPAGATE;
+ if (event.get_gesture_phase() === Clutter.TouchpadGesturePhase.BEGIN)
+ this._state = TouchpadState.NONE;
+
if (event.get_touchpad_gesture_finger_count() !== GESTURE_FINGER_COUNT)
return Clutter.EVENT_PROPAGATE;
@@ -119,11 +129,17 @@ const TouchpadSwipeGesture = GObject.registerClass({
if (!this.enabled)
return Clutter.EVENT_PROPAGATE;
+ if (this._state === TouchpadState.IGNORED)
+ return Clutter.EVENT_PROPAGATE;
+
let time = event.get_time();
let [x, y] = event.get_coords();
let [dx, dy] = event.get_gesture_motion_delta();
+ if (this._state === TouchpadState.NONE && dx === 0 && dy === 0)
+ return Clutter.EVENT_PROPAGATE;
+
let gestureOrientation = -1;
if (dx !== dy) {
gestureOrientation = Math.abs(dx) > Math.abs(dy)
@@ -131,9 +147,12 @@ const TouchpadSwipeGesture = GObject.registerClass({
: Clutter.Orientation.VERTICAL;
}
- if (gestureOrientation >= 0 &&
- gestureOrientation !== this.orientation)
+ if (this._state === TouchpadState.NONE &&
+ gestureOrientation >= 0 &&
+ gestureOrientation !== this.orientation) {
+ this._state = TouchpadState.IGNORED;
return Clutter.EVENT_PROPAGATE;
+ }
const vertical = this.orientation === Clutter.Orientation.VERTICAL;
let delta = (vertical ? dy : dx) * SWIPE_MULTIPLIER;
@@ -141,10 +160,12 @@ const TouchpadSwipeGesture = GObject.registerClass({
switch (event.get_gesture_phase()) {
case Clutter.TouchpadGesturePhase.BEGIN:
- this.emit('begin', time, x, y);
- break;
-
case Clutter.TouchpadGesturePhase.UPDATE:
+ if (this._state === TouchpadState.NONE) {
+ this.emit('begin', time, x, y);
+ this._state = TouchpadState.HANDLING;
+ }
+
if (this._touchpadSettings.get_boolean('natural-scroll'))
delta = -delta;
@@ -154,10 +175,11 @@ const TouchpadSwipeGesture = GObject.registerClass({
case Clutter.TouchpadGesturePhase.END:
case Clutter.TouchpadGesturePhase.CANCEL:
this.emit('end', time, distance);
+ this._state = TouchpadState.NONE;
break;
}
- return gestureOrientation === this.orientation
+ return this._state === TouchpadState.HANDLING
? Clutter.EVENT_STOP
: Clutter.EVENT_PROPAGATE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]