From 14cb6f4f253963bd7d76477f910f5dd538cff605 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 05b5b2cc6c..64ed422085 100644 --- a/js/ui/swipeTracker.js +++ b/js/ui/swipeTracker.js @@ -564,13 +564,18 @@ 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(delta, distance) { if (this._state !== State.SCROLLING) return; this._progress += delta / distance; - 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); } @@ -706,13 +711,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; } -- GitLab From 8245fd894318eae3ff2e78825365cf7378121385 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js index db4050a2a1..8bf1d5db1e 100644 --- a/js/ui/workspaceAnimation.js +++ b/js/ui/workspaceAnimation.js @@ -14,6 +14,8 @@ import * as Main from './main.js'; export const WINDOW_ANIMATION_TIME = 250; export const WORKSPACE_SPACING = 100; +const WORKSPACE_BUMP_RANGE = 0.1; + export const BaseWorkspaceGroup = GObject.registerClass( class BaseWorkspaceGroup extends Clutter.Actor { constructor(workspace, monitor, movingWindow) { @@ -517,7 +519,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) { -- GitLab