From 891243c62a27972cff78159c1f3bb4deb370a50b Mon Sep 17 00:00:00 2001 From: Alessandro Bono Date: Sat, 12 Nov 2022 14:20:07 +0100 Subject: [PATCH 1/2] swipeTracker: Allow to specify a bump range Right now, given the snap points [0, 1, 2] we can't go below 0 or above 2 during the swipe update. In order to give more feedback during the swipe sometimes it is useful to move the content even when we already reached the first or the latest snap point. Address this by adding a bump range. With a bump range specified, the gesture progress update is not limited by the snap points boundaries. For example, with snap points [0, 1, 2] and a bumpRange 0.1, the update swipe progress value can now be between -0.1 and 2.1. --- js/ui/swipeTracker.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/ui/swipeTracker.js b/js/ui/swipeTracker.js index cef904c05..9b19baf71 100644 --- a/js/ui/swipeTracker.js +++ b/js/ui/swipeTracker.js @@ -647,6 +647,11 @@ export const SwipeTracker = GObject.registerClass({ return [this._snapPoints[lowerIndex], this._snapPoints[upperIndex]]; } + _getBoundsWithBumpRange(pos) { + const bounds = this._getBounds(pos); + return [bounds[0] - this._bumpRange, bounds[1] + this._bumpRange]; + } + _updateGesture(gesture, time, delta, distance) { if (this._state !== State.SCROLLING) return; @@ -663,7 +668,7 @@ export const SwipeTracker = GObject.registerClass({ this._progress += delta / distance; this._history.append(time, delta); - this._progress = Math.clamp(this._progress, ...this._getBounds(this._initialProgress)); + this._progress = Math.clamp(this._progress, ...this._getBoundsWithBumpRange(this._initialProgress)); this.emit('update', this._progress); } @@ -758,13 +763,16 @@ export const SwipeTracker = GObject.registerClass({ * @param {number[]} snapPoints - An array of snap points, sorted in ascending order * @param {number} currentProgress - initial progress value * @param {number} cancelProgress - the value to be used on cancelling + * @param {number} bumpRange - how much the user can stretch beyond the first or + * the latest snap point */ - confirmSwipe(distance, snapPoints, currentProgress, cancelProgress) { + confirmSwipe(distance, snapPoints, currentProgress, cancelProgress, bumpRange = 0) { this.distance = distance; this._snapPoints = snapPoints; this._initialProgress = currentProgress; this._progress = currentProgress; this._cancelProgress = cancelProgress; + this._bumpRange = bumpRange; this._state = State.SCROLLING; } From 48cdffe56b616e467bdbeef66f1f857abdd2a46c Mon Sep 17 00:00:00 2001 From: Alessandro Bono Date: Sat, 12 Nov 2022 14:22:17 +0100 Subject: [PATCH 2/2] workspaceAnimation: Add gesture feedback when reached latest workspace When we already are in the first/last workspace and we try to swipe left/right nothing happens. Provide a feedback and allow to drag the workspace a little anyway. The gesture will bump back to the initial workspace when completed. --- js/ui/workspaceAnimation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js index b278113e2..c7790c6e1 100644 --- a/js/ui/workspaceAnimation.js +++ b/js/ui/workspaceAnimation.js @@ -14,6 +14,7 @@ import * as Util from '../misc/util.js'; import * as Main from './main.js'; const WINDOW_ANIMATION_TIME = 250; +const WORKSPACE_BUMP_RANGE = 0.1; export const WORKSPACE_SPACING = 100; export const WorkspaceGroup = GObject.registerClass( @@ -477,7 +478,7 @@ export class WorkspaceAnimationController { this._switchData.baseMonitorGroup = monitorGroup; - tracker.confirmSwipe(baseDistance, points, progress, cancelProgress); + tracker.confirmSwipe(baseDistance, points, progress, cancelProgress, WORKSPACE_BUMP_RANGE); } _switchWorkspaceUpdate(tracker, progress) {