Skip to content

fix: suppress browser context menu and prevent trackpad tap from dism…#1520

Open
aaradhyaberisfdc wants to merge 1 commit intotsl0922:mainfrom
aaradhyaberisfdc:contextmenu-fix
Open

fix: suppress browser context menu and prevent trackpad tap from dism…#1520
aaradhyaberisfdc wants to merge 1 commit intotsl0922:mainfrom
aaradhyaberisfdc:contextmenu-fix

Conversation

@aaradhyaberisfdc
Copy link
Copy Markdown

Problem

When using ttyd with tmux (set -g mouse on), right-clicking to open tmux's context menu has two issues:

  1. Mac trackpad tap dismisses menu instantly: a two-finger tap generates mousedown+mouseup within ~100ms. xterm.js sends the button release as an SGR mouse report, and tmux closes its menu immediately.
  2. Browser context menu overlaps tmux's menu: the native browser menu appears on top, interfering with the application menu.

Additionally, no-button motion events (code & 3 === 3) sent after the release tell tmux "no button is held", which also dismisses the menu.

Fix

Three-layer interception:

  1. contextmenu handler: suppresses the browser menu during mouse tracking. Shift+right-click bypasses to show the browser's native menu.
  2. mouseup capture handler: blocks the right-button release at document level before xterm.js can generate a report.
  3. onData SGR filter: drops right-button release and no-button motion reports while the filter is active. Resets on non-right-button press (user selecting a menu item) or after a safety timeout.

All three are no-ops when mouse tracking is off (normal shell usage).

Testing

With set -g mouse on in tmux:

  • Right-click opens tmux menu and it stays open
  • Click a menu item to select it — works normally
  • Shift+right-click shows browser's native context menu
  • Regular terminal usage (no tmux) is unaffected

…issing tmux menus

When mouse tracking is active, suppress the browser context menu and
filter SGR mouse reports so that a quick Mac trackpad two-finger tap
doesn't instantly dismiss tmux's right-click menu.
Shift+right-click bypasses to show the browser's native menu.
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