Skip to content

Fix double click never firing on emscripten - #185

Merged
treeform merged 4 commits into
masterfrom
emscripten-double-click
Aug 6, 2026
Merged

Fix double click never firing on emscripten#185
treeform merged 4 commits into
masterfrom
emscripten-double-click

Conversation

@treeform

@treeform treeform commented Aug 6, 2026

Copy link
Copy Markdown
Owner

The shared multi click logic in internal.nim compares the time between clicks against platformDoubleClickInterval, which each platform sets at init: macOS from NSEvent.doubleClickInterval, win32 from GetDoubleClickTime(). The emscripten platform never set it, so it stayed 0.0 and the check doubleClickInterval <= platformDoubleClickInterval could never pass. DoubleClick, TripleClick and QuadrupleClick simply never fired in browser builds.

Browsers do not expose the user's double click speed, so this sets the common 500 ms default at init.

Verified in a WebGL2 emscripten build (windy + boxy game): double click events now arrive.

Note: the linux X11 platform also does not appear to set platformDoubleClickInterval, so it likely has the same bug and could use the same treatment.

🤖 Generated with Claude Code

relh and others added 4 commits July 22, 2026 14:36
Keep the native fetch handle so cancellation and deadlines can stop the request. Mark the request complete before closing it because Emscripten calls the error callback during an in-flight close.
Focus and resize events can arrive while Asyncify has suspended onFrame. Queue those callbacks until onFrame returns so window state changes at a frame boundary.
processFlagsChanged toggled each modifier key per event, so any edge
delivered while the window was not key (focus stolen mid-chord, Cmd-Tab
entry, activation settling during launch) latched an inverted modifier
for the rest of the session. Every unmodified key chord then resolved
with a phantom SHIFT/CTRL/ALT attached, silently retargeting exact-match
consumers.

Shift/Control/Option/Command now derive up/down from the absolute
NSEventModifierFlags state (class bit plus IOKit device bits for the
left/right split), so a missed edge self-corrects on the next
flagsChanged. windowDidBecomeKey seeds the same absolute state after
clearing buttons, so a modifier held across focus gain cannot register
its release as a phantom press. CapsLock keeps toggle semantics.

Also register the NSWindow key-eligibility override with its real
zero-argument selector: 'canBecomeKeyWindow:' (with colon) never
overrode the getter, leaving borderless windows unable to become key.
Co-Authored-By: Claude Fable 5 <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.

2 participants