Started using force calculations when swiping between workspaces

This commit is contained in:
mr. m
2025-02-17 12:21:04 +01:00
parent dfac1c1b98
commit 6df2c97cc5

View File

@@ -393,17 +393,23 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
const delta = event.delta * 300; const delta = event.delta * 300 + 1;
const stripWidth = document.getElementById('tabbrowser-tabs').scrollWidth;
let translateX = this._swipeState.lastDelta + delta;
// Add a force multiplier as we are translating the strip depending on how close to the edge we are
let forceMultiplier = Math.min(1, 1 - (Math.abs(translateX) / (stripWidth * 1.5)));
if (forceMultiplier > 0.5) {
translateX *= forceMultiplier;
this._swipeState.lastDelta = delta; this._swipeState.lastDelta = delta;
} else {
translateX = this._swipeState.lastDelta;
}
if (Math.abs(delta) > 1) { if (Math.abs(delta) > 1) {
this._swipeState.direction = delta > 0 ? 'left' : 'right'; this._swipeState.direction = delta > 0 ? 'left' : 'right';
} }
// Apply a translateX to the tab strip to give the user feedback on the swipe // Apply a translateX to the tab strip to give the user feedback on the swipe
const stripWidth = document.getElementById('tabbrowser-tabs').scrollWidth;
const translateX = Math.max(-stripWidth, Math.min(delta, stripWidth));
const currentWorkspace = this.activeWorkspace; const currentWorkspace = this.activeWorkspace;
this._organizeWorkspaceStripLocations({ uuid: currentWorkspace }, true, translateX); this._organizeWorkspaceStripLocations({ uuid: currentWorkspace }, true, translateX);
} }