adds ability to scroll between workspaces as well as fixing the issue with trackpad

This commit is contained in:
Bridget Morningstar
2024-11-28 22:19:25 -06:00
parent 12afbcd03d
commit 90fe7d8e03
3 changed files with 82 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@@ -112,36 +112,71 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
_setupSidebarHandlers() {
const toolbox = document.getElementById('navigator-toolbox');
toolbox.addEventListener('mouseenter', () => {
this._hoveringSidebar = true;
});
toolbox.addEventListener('mouseleave', () => {
this._hoveringSidebar = false;
});
const scrollCooldown = 500; // Milliseconds to wait before allowing another scroll
const scrollThreshold = 5; // Minimum scroll delta to trigger workspace change
const scrollCooldown = 200; // Milliseconds to wait before allowing another scroll
const scrollThreshold = 2; // Minimum scroll delta to trigger workspace change
toolbox.addEventListener('wheel', async (event) => {
if (!this.workspaceEnabled) return;
// Only process horizontal scroll (deltaX)
if (!event.deltaX) return;
// Only process non-gesture scrolls
if (event.deltaMode !== 1) return;
const isVerticalScroll = event.deltaY && !event.deltaX;
const isHorizontalScroll = event.deltaX && !event.deltaY;
//if the scroll is vertical this checks that a modifier key is used before proceeding
if (isVerticalScroll) {
const activationMethod = Services.prefs.getStringPref('zen.workspaces.scroll-modifier-key', 'ctrl');
const activationKeyMap = {
ctrl: event.ctrlKey,
alt: event.altKey,
shift: event.shiftKey,
meta: event.metaKey,
};
if (activationMethod in activationKeyMap && !activationKeyMap[activationMethod]) {
return;
}
}
const currentTime = Date.now();
if (currentTime - this._lastScrollTime < scrollCooldown) {
return;
if (currentTime - this._lastScrollTime < scrollCooldown) return;
//this decides which delta to use
const delta = isVerticalScroll ? event.deltaY : event.deltaX;
if (Math.abs(delta) < scrollThreshold) return;
// Determine scroll direction
const direction = delta > 0 ? -1 : 1;
// Workspace logic
const workspaces = (await this._workspaces()).workspaces;
const currentIndex = workspaces.findIndex(w => w.uuid === this.activeWorkspace);
if (currentIndex === -1) return; // No valid current workspace
let targetIndex = currentIndex + direction;
if (Services.prefs.getBoolPref('zen.workspaces.wrap-around-navigation', false)) {
// Add length to handle negative indices and loop
targetIndex = (targetIndex + workspaces.length) % workspaces.length;
} else {
// Clamp within bounds to disable looping
targetIndex = Math.max(0, Math.min(workspaces.length - 1, targetIndex));
}
// Only process if the horizontal scroll is significant enough
if (Math.abs(event.deltaX) < scrollThreshold) {
return;
if (targetIndex !== currentIndex) {
await this.changeWorkspace(workspaces[targetIndex]);
}
// Change workspace based on scroll direction
const direction = event.deltaX > 0 ? 1 : -1;
await this.changeWorkspaceShortcut(direction);
this._lastScrollTime = currentTime;
}, { passive: true });
}
@@ -212,26 +247,32 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
async _handleSwipeEnd(event) {
if (!this.workspaceEnabled || !this._swipeState?.isGestureActive) return;
event.preventDefault();
event.stopPropagation();
if (this._swipeState.direction) {
const workspaces = (await this._workspaces()).workspaces;
const currentIndex = workspaces.findIndex(w => w.uuid === this.activeWorkspace);
if (currentIndex !== -1) {
const isRTL = document.documentElement.matches(':-moz-locale-dir(rtl)');
const moveForward = (this._swipeState.direction === 'right') !== isRTL;
let targetIndex;
if (moveForward) {
targetIndex = (currentIndex + 1) % workspaces.length;
let targetIndex = moveForward
? currentIndex + 1
: currentIndex - 1;
if (Services.prefs.getBoolPref('zen.workspaces.wrap-around-navigation', false)) {
// Add length to handle negative indices and clamp within bounds
targetIndex = (targetIndex + workspaces.length) % workspaces.length;
} else {
targetIndex = (currentIndex - 1 + workspaces.length) % workspaces.length;
// Clamp within bounds for to remove looping
targetIndex = Math.max(0, Math.min(workspaces.length - 1, targetIndex));
}
if (targetIndex !== currentIndex) {
await this.changeWorkspace(workspaces[targetIndex]);
}
await this.changeWorkspace(workspaces[targetIndex]);
}
}

View File

@@ -1001,6 +1001,16 @@ Preferences.addAll([
type: 'bool',
default: true,
},
{
id: 'zen.workspaces.wrap-around-navigation',
type: 'bool',
default: true,
},
{
id: 'zen.workspaces.scroll-modifier-key',
type: "string",
default: "ctrl",
},
{
id: 'zen.pinned-tab-manager.close-shortcut-behavior',
type: 'string',