Skip to content

fix: make context-menu double-click reliable on Linux/macOS (#24, #26, #12)#28

Open
furkanyolal wants to merge 1 commit into
diredocks:mainfrom
furkanyolal:fix/reliable-contextmenu-double-click
Open

fix: make context-menu double-click reliable on Linux/macOS (#24, #26, #12)#28
furkanyolal wants to merge 1 commit into
diredocks:mainfrom
furkanyolal:fix/reliable-contextmenu-double-click

Conversation

@furkanyolal

Copy link
Copy Markdown

Problem

When gestures are bound to the right button, opening the context menu on Linux/macOS takes 3–4 right-clicks instead of the intended double-click (#24, #26, #12).

On these platforms Chromium fires the contextmenu event on mouse-down, so the first right-click is necessarily reserved for gesture detection and the menu is meant to open on a second click. The detection of that second click, however, required it to land within 300 ms AND within the gesture distanceThreshold (10 px) of the first:

const withinTime = now - this._lastClick.time < doubleClickThreshold; // 300 ms
const withinDist = getDistance(...) < this.distanceThreshold;          // 10 px (gesture threshold)

A normal-paced double-click easily exceeds 300 ms, so the second click falls outside the window, gets suppressed again, and _lastClick resets to "now" — the user has to keep clicking until two happen to land < 300 ms apart. Reusing the tiny gesture threshold for the click-distance check makes it even more fragile.

Fix

Keep the existing (and, on Chromium, unavoidable) double-click model, but make it reliable:

  • Configurable, more forgiving time window — replace the hardcoded 300 ms with Settings.Gesture.contextMenuTimeout (default 400 ms), exposed in the advanced gesture settings so users who want a longer window can set one. This directly addresses the maintainer's note in When rocker gestures are on, right clicking on webpages requires double right clicking. #12/Context menu appears after every gesture #18 about adding an option to control this behavior.
  • Decouple the double-click distance from the gesture distanceThreshold via a dedicated, more generous constant (24 px), so minor cursor jitter between the two clicks no longer resets the sequence.
  • Clear the pending first-click when a real gesture starts, so a gesture's suppressed contextmenu can't be mistaken for the second click of a context-menu double-click.

No behavioural change on Windows (where contextmenu fires on mouse-up and single-click already works) — only the non-Windows double-click path and its new tunable are affected. Defaults are backward-compatible.

Testing

Built with npm run dist and loaded unpacked in Brave 1.91.171 / Chromium 149 on KDE Plasma 6.6 Wayland:

  • Normal-paced double right-click now opens the context menu reliably (previously 3–4 tries).
  • Right-button gestures (left/right drag) still work, with the trace drawn.
  • No stray context menu appears after completing a gesture.
  • New "Context menu timeout" setting appears under advanced gesture settings and takes effect live.

Note

This does not (and cannot) provide single-right-click context menus with right-button gestures on Chromium — that requires the menu to fire on mouse-up, which Chromium does not expose to extensions (see chromium issue 41029299). This PR only makes the existing double-click compromise dependable.

On platforms where Chromium fires `contextmenu` on mouse-down (Linux,
macOS), the first right-click is reserved for gesture detection and the
context menu only opens on a second click. The detection for that second
click required it to land within 300ms AND within the *gesture*
`distanceThreshold` (10px) of the first. A normal-paced double-click
easily exceeds 300ms, so the menu was repeatedly re-suppressed and users
had to right-click 3-4 times to open it (diredocks#24, diredocks#26, diredocks#12).

- Widen the time window to a configurable `contextMenuTimeout`
  (default 400ms, exposed in advanced settings) instead of the
  hardcoded 300ms.
- Decouple the double-click distance tolerance from the gesture
  `distanceThreshold` (dedicated 24px constant) so minor cursor jitter
  between the two clicks no longer resets the sequence.
- Clear the pending first-click when a real gesture starts, so a
  gesture's suppressed contextmenu can't be mistaken for the second
  click of a context-menu double-click.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant