swipeTracker: Check orientation with a threshold for touchpad
Avoid picking the direction too early. Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3755 Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1731>
This commit is contained in:
parent
3d2812063f
commit
c06bc74d6d
@ -26,6 +26,7 @@ const DECELERATION_TOUCH = 0.998;
|
|||||||
const DECELERATION_TOUCHPAD = 0.997;
|
const DECELERATION_TOUCHPAD = 0.997;
|
||||||
const VELOCITY_CURVE_THRESHOLD = 2;
|
const VELOCITY_CURVE_THRESHOLD = 2;
|
||||||
const DECELERATION_PARABOLA_MULTIPLIER = 0.35;
|
const DECELERATION_PARABOLA_MULTIPLIER = 0.35;
|
||||||
|
const DRAG_THRESHOLD_DISTANCE = 16;
|
||||||
|
|
||||||
// Derivative of easeOutCubic at t=0
|
// Derivative of easeOutCubic at t=0
|
||||||
const DURATION_MULTIPLIER = 3;
|
const DURATION_MULTIPLIER = 3;
|
||||||
@ -41,8 +42,9 @@ const State = {
|
|||||||
|
|
||||||
const TouchpadState = {
|
const TouchpadState = {
|
||||||
NONE: 0,
|
NONE: 0,
|
||||||
HANDLING: 1,
|
PENDING: 1,
|
||||||
IGNORED: 2,
|
HANDLING: 2,
|
||||||
|
IGNORED: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
const EventHistory = class {
|
const EventHistory = class {
|
||||||
@ -105,6 +107,8 @@ const TouchpadSwipeGesture = GObject.registerClass({
|
|||||||
super._init();
|
super._init();
|
||||||
this._allowedModes = allowedModes;
|
this._allowedModes = allowedModes;
|
||||||
this._state = TouchpadState.NONE;
|
this._state = TouchpadState.NONE;
|
||||||
|
this._cumulativeX = 0;
|
||||||
|
this._cumulativeY = 0;
|
||||||
this._touchpadSettings = new Gio.Settings({
|
this._touchpadSettings = new Gio.Settings({
|
||||||
schema_id: 'org.gnome.desktop.peripherals.touchpad',
|
schema_id: 'org.gnome.desktop.peripherals.touchpad',
|
||||||
});
|
});
|
||||||
@ -134,24 +138,44 @@ const TouchpadSwipeGesture = GObject.registerClass({
|
|||||||
|
|
||||||
let time = event.get_time();
|
let time = event.get_time();
|
||||||
|
|
||||||
let [x, y] = event.get_coords();
|
const [x, y] = event.get_coords();
|
||||||
let [dx, dy] = event.get_gesture_motion_delta();
|
let [dx, dy] = event.get_gesture_motion_delta();
|
||||||
|
|
||||||
if (this._state === TouchpadState.NONE && dx === 0 && dy === 0)
|
if (this._state === TouchpadState.NONE) {
|
||||||
return Clutter.EVENT_PROPAGATE;
|
if (dx === 0 && dy === 0)
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
let gestureOrientation = -1;
|
this._cumulativeX = 0;
|
||||||
if (dx !== dy) {
|
this._cumulativeY = 0;
|
||||||
gestureOrientation = Math.abs(dx) > Math.abs(dy)
|
this._state = TouchpadState.PENDING;
|
||||||
? Clutter.Orientation.HORIZONTAL
|
|
||||||
: Clutter.Orientation.VERTICAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._state === TouchpadState.NONE &&
|
if (this._state === TouchpadState.PENDING) {
|
||||||
gestureOrientation >= 0 &&
|
this._cumulativeX += dx * SWIPE_MULTIPLIER;
|
||||||
gestureOrientation !== this.orientation) {
|
this._cumulativeY += dy * SWIPE_MULTIPLIER;
|
||||||
this._state = TouchpadState.IGNORED;
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
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;
|
const vertical = this.orientation === Clutter.Orientation.VERTICAL;
|
||||||
@ -161,11 +185,6 @@ const TouchpadSwipeGesture = GObject.registerClass({
|
|||||||
switch (event.get_gesture_phase()) {
|
switch (event.get_gesture_phase()) {
|
||||||
case Clutter.TouchpadGesturePhase.BEGIN:
|
case Clutter.TouchpadGesturePhase.BEGIN:
|
||||||
case Clutter.TouchpadGesturePhase.UPDATE:
|
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'))
|
if (this._touchpadSettings.get_boolean('natural-scroll'))
|
||||||
delta = -delta;
|
delta = -delta;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user