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

Fix issue #67: Double right-click to open context menu in OSX/Linux #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/content/mouseEvents.js
Expand Up @@ -24,13 +24,22 @@ window.fg.module('mouseEvents', function (exports, fg) {
// Used by commands to target a specific nested frame.
exports.scriptFrameId = fg.helpers.makeScriptFrameId();

// On OSX/Linux, double right-click to open context menu. See:
// https://github.com/marklieberman/foxygestures/issues/67
// and for the user agent reference documentation:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
const isLinuxOSX = window.navigator.userAgent.indexOf("Linux") !== -1 ||
window.navigator.userAgent.indexOf("Macintosh") !== -1;
const linuxOSXDoubleClickTimeoutValue = 600;

// State for this module.
var state = (exports.state = {
gestureState: GESTURE_STATE.NONE, // Gesture state machine state.
contextMenu: false, // Context menu is enabled?
isNested: (window !== window.top), // Is this frame nested?
nestedFrames: [], // Array of all nested frames.
isUnloading: false // Is the page is unloading?
isUnloading: false, // Is the page is unloading?
linuxOSXDoubleClickTimeout: null // No right-click detected yet
});

// Settings for this module.
Expand Down Expand Up @@ -167,6 +176,24 @@ window.fg.module('mouseEvents', function (exports, fg) {
}, true);

window.addEventListener('contextmenu', function (event) {

if (isLinuxOSX) {
// If this timeout is active (non-null), we're waiting for the second
// right-click on Linux or OSX. If it isn't active, this is the first
// right-click so we prevent the default action and wait for the next
// right-click within linuxOSXDoubleClickTimeoutValue
if (state.linuxOSXDoubleClickTimeout) {
clearTimeout(state.linuxOSXDoubleClickTimeout)
state.linuxOSXDoubleClickTimeout = null;
} else {
event.preventDefault();
event.stopPropagation();
state.linuxOSXDoubleClickTimeout = setTimeout(function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason you chose to use setTimeout instead of just measuring the difference in milliseconds between first and second click?

state.linuxOSXDoubleClickTimeout = null;
}, linuxOSXDoubleClickTimeoutValue);
}
}

if (!state.contextMenu) {
event.preventDefault();
event.stopPropagation();
Expand Down