Merge branch 'wip/abono/swipe-workspace-bump' into 'main'

workspaceAnimation: Add gesture feedback when reached the first or last workspace

See merge request GNOME/gnome-shell!2539
This commit is contained in:
Alessandro Bono 2024-06-27 18:25:54 +00:00
commit 368ed2c0a7
2 changed files with 12 additions and 3 deletions

View file

@ -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;
}

View file

@ -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) {