Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspace navigation via mouse back/forward buttons #2771

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/browser/base/zen-components/ZenWorkspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
cumulativeDelta: 0,
direction: null
};
_hoveringSidebar = false;

async init() {
if (!this.shouldHaveWorkspaces) {
Expand Down Expand Up @@ -47,10 +48,58 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
console.info('ZenWorkspaces: ZenWorkspaces initialized');

this.initializeGestureHandlers();
this.initializeWorkspaceNavigation();

Services.obs.addObserver(this, 'weave:engine:sync:finish');
}

initializeWorkspaceNavigation() {
this._setupAppCommandHandlers();
this._setupHoverDetection();
}

_setupAppCommandHandlers() {
// Remove existing handler temporarily - this is needed so that _handleAppCommand is called before the original
window.removeEventListener("AppCommand", HandleAppCommandEvent, true);

// Add our handler first
window.addEventListener("AppCommand", this._handleAppCommand.bind(this), true);

// Re-add original handler
window.addEventListener("AppCommand", HandleAppCommandEvent, true);
}

_handleAppCommand(event) {
if (!this.workspaceEnabled || !this._hoveringSidebar) {
return;
}

switch (event.command) {
case "Forward":
this.changeWorkspaceShortcut(1);
event.stopImmediatePropagation();
event.preventDefault();
break;
case "Back":
this.changeWorkspaceShortcut(-1);
event.stopImmediatePropagation();
event.preventDefault();
break;
}
}

_setupHoverDetection() {
const toolbox = document.getElementById('navigator-toolbox');

toolbox.addEventListener('mouseenter', () => {
this._hoveringSidebar = true;
});

toolbox.addEventListener('mouseleave', () => {
this._hoveringSidebar = false;
});
}

initializeGestureHandlers() {
const elements = [
document.getElementById('navigator-toolbox'),
Expand Down Expand Up @@ -113,7 +162,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._swipeState.direction = this._swipeState.cumulativeDelta > 0 ? 'right' : 'left';
}

console.log('MozSwipeGestureUpdateEND', this._swipeState);
}

async _handleSwipeEnd(event) {
Expand Down
Loading