[gnome-shell/wip/exalm/swipes: 7/8] swipeTracker: Check orientation with a threshold for touchpad
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/exalm/swipes: 7/8] swipeTracker: Check orientation with a threshold for touchpad
- Date: Mon, 1 Mar 2021 16:59:58 +0000 (UTC)
commit bb77393713b1ffaa22fe66db20b009466ed9cd11
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Feb 28 19:23:29 2021 +0500
swipeTracker: Check orientation with a threshold for touchpad
Avoid picking the direction too early.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3755
js/ui/swipeTracker.js | 60 +++++++++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 21 deletions(-)
---
diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js
index 5dc3c12b06..e93cb889b9 100644
--- a/js/ui/swipeTracker.js
+++ b/js/ui/swipeTracker.js
@@ -25,6 +25,7 @@ const DECELERATION_TOUCH = 0.998;
const DECELERATION_TOUCHPAD = 0.997;
const VELOCITY_CURVE_THRESHOLD = 2;
const DECELERATION_PARABOLA_MULTIPLIER = 0.35;
+const DRAG_THRESHOLD_DISTANCE = 16;
// Derivative of easeOutCubic at t=0
const DURATION_MULTIPLIER = 3;
@@ -40,8 +41,9 @@ const State = {
const TouchpadState = {
NONE: 0,
- HANDLING: 1,
- IGNORED: 2,
+ PENDING: 1,
+ HANDLING: 2,
+ IGNORED: 3,
};
const EventHistory = class {
@@ -104,6 +106,8 @@ const TouchpadSwipeGesture = GObject.registerClass({
super._init();
this._allowedModes = allowedModes;
this._state = TouchpadState.NONE;
+ this._cumulativeX = 0;
+ this._cumulativeY = 0;
this._touchpadSettings = new Gio.Settings({
schema_id: 'org.gnome.desktop.peripherals.touchpad',
});
@@ -132,25 +136,44 @@ const TouchpadSwipeGesture = GObject.registerClass({
return Clutter.EVENT_PROPAGATE;
let time = event.get_time();
-
- let [x, y] = event.get_coords();
const [dx, dy] = event.get_gesture_motion_delta_unaccelerated();
+ const [x, y] = event.get_coords();
- if (this._state === TouchpadState.NONE && dx === 0 && dy === 0)
- return Clutter.EVENT_PROPAGATE;
+ if (this._state === TouchpadState.NONE) {
+ if (dx === 0 && dy === 0)
+ return Clutter.EVENT_PROPAGATE;
- let gestureOrientation = -1;
- if (dx !== dy) {
- gestureOrientation = Math.abs(dx) > Math.abs(dy)
- ? Clutter.Orientation.HORIZONTAL
- : Clutter.Orientation.VERTICAL;
+ this._cumulativeX = 0;
+ this._cumulativeY = 0;
+ this._state = TouchpadState.PENDING;
}
- if (this._state === TouchpadState.NONE &&
- gestureOrientation >= 0 &&
- gestureOrientation !== this.orientation) {
- this._state = TouchpadState.IGNORED;
- return Clutter.EVENT_PROPAGATE;
+ if (this._state === TouchpadState.PENDING) {
+ this._cumulativeX += dx;
+ this._cumulativeY += dy;
+
+ const cdx = this._cumulativeX;
+ const cdy = this._cumulativeY;
+ const distance = Math.sqrt(cdx * cdx + cdy * cdy);
+
+ if (distance >= DRAG_THRESHOLD_DISTANCE) {
+ const gestureOrientation = Math.abs(cdx) > Math.abs(cdy)
+ ? Clutter.Orientation.HORIZONTAL
+ : Clutter.Orientation.VERTICAL;
+
+ this._cumulativeX = 0;
+ this._cumulativeY = 0;
+
+ if (gestureOrientation === this.orientation) {
+ this._state = TouchpadState.HANDLING;
+ this.emit('begin', time, x, y);
+ } else {
+ this._state = TouchpadState.IGNORED;
+ return Clutter.EVENT_PROPAGATE;
+ }
+ } else {
+ return Clutter.EVENT_PROPAGATE;
+ }
}
const vertical = this.orientation === Clutter.Orientation.VERTICAL;
@@ -160,11 +183,6 @@ const TouchpadSwipeGesture = GObject.registerClass({
switch (event.get_gesture_phase()) {
case Clutter.TouchpadGesturePhase.BEGIN:
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]