Skip to content

fix: prevent context menu from dismissing on trackpad press release#58

Open
TigerInYourDream wants to merge 3 commits intomainfrom
fix/context-menu-dismiss-on-press
Open

fix: prevent context menu from dismissing on trackpad press release#58
TigerInYourDream wants to merge 3 commits intomainfrom
fix/context-menu-dismiss-on-press

Conversation

@TigerInYourDream
Copy link
Copy Markdown

@TigerInYourDream TigerInYourDream commented Apr 7, 2026

Summary

Fixes #57

On macOS trackpad, right-clicking via two-finger press caused the context menu to flash and immediately disappear. This affected both the room context menu and the message context menu.

Root Cause

macOS trackpad generates a FingerScroll(0, 0) event on two-finger press. Both menus had Hit::FingerScroll(_) => true which unconditionally closed on any scroll event, including zero-scroll.

Fix (two layers)

Layer 1 — FingerScroll zero-scroll filter (direct fix):

// Before: any scroll closes
Hit::FingerScroll(_) => true,

// After: only real scrolls close
Hit::FingerScroll(fse) => fse.scroll.x != 0.0 || fse.scroll.y != 0.0,

Layer 2 — ContextMenuOpenGesture (defense-in-depth):

Tracks the digit_id + capture_time of the gesture that opened the menu. If a FingerUp arrives matching this gesture, it's consumed instead of treated as "click outside". This protects against edge cases where:

  • The menu position is adjusted for window bounds (the FingerUp lands outside main_content)
  • The finger drifts slightly between press and release

The capture_time matching is verified correct via Makepad source: FingerDown.time is stored as capture.time during capture_digit(), then read back as FingerUp.capture_time.

Changes

  • src/home/mod.rsContextMenuOpenGesture struct (digit_id + capture_time) and consume_context_menu_opening_finger_up() shared utility
  • src/home/room_context_menu.rs — Track opening gesture, filter zero-scroll FingerScroll
  • src/home/new_message_context_menu.rs — Same fix for message context menu
  • src/home/rooms_list_entry.rs — Pass ContextMenuOpenGesture in SecondaryClicked action
  • src/home/rooms_list.rs — Forward gesture through OpenRoomContextMenu action
  • src/home/room_screen.rs — Pass gesture through OpenMessageContextMenu action
  • src/app.rs — Forward gesture to show() calls

Test plan

  • macOS trackpad: two-finger tap on room → context menu stays open
  • macOS trackpad: two-finger press on room → context menu stays open (was broken)
  • macOS trackpad: two-finger press on message → message context menu stays open
  • Click outside menu → menu closes normally
  • Press Escape → menu closes normally
  • Scroll (real scroll with non-zero delta) → menu closes normally
  • Long-press on room (mobile gesture) → context menu stays open after release

Track the opening gesture (digit_id + capture_time) when showing a
context menu, and consume the corresponding FingerUp event instead
of treating it as a "click outside" dismissal.

Fixes #57
The actual root cause of the trackpad press dismissal was FingerScroll(0,0):
macOS generates a zero-scroll event on two-finger press, which the menu's
unconditional `Hit::FingerScroll(_) => true` treated as a close trigger.

- Only close on FingerScroll when scroll delta is non-zero
- Restore capture_time field in ContextMenuOpenGesture for precise
  gesture matching (digit_id + capture_time from Makepad capture chain)

Fixes #57
Keep function signatures and call sites in their original horizontal
style to minimize diff noise in the PR.
@tyreseluo tyreseluo marked this pull request as draft April 7, 2026 09:53
@tyreseluo tyreseluo marked this pull request as ready for review April 7, 2026 09:53
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.

Context menu flashes and dismisses immediately on macOS trackpad press

2 participants