Skip to content

cvcGL: Cmd as the shortcut key in a browser on a Mac (stacked on #1536) - #1539

Merged
transfix merged 4 commits into
masterfrom
feat/ari-web-mac-cmd
Nov 26, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/ari-web-mac-cmd

Conversation

@transfix

Copy link
Copy Markdown
Owner

Stacked on #1536. The first commit (625a796) is #1536's own. This PR's change is the second commit, 0bb103e. The base is master so that ci.yml runs. Merge #1536 first. Don't merge this one without Joe's OK.

In a browser on a Mac, arigl-web now uses Cmd as the shortcut key: Cmd+Z, C, V, X and A in a field, and "Cmd+" in the menus, as a native Mac build does. Until now Ctrl was the shortcut key in every browser, a Mac's included.

Why it was Ctrl

ImGui turns its Mac behaviours (io.ConfigMacOSXBehaviors) on from __APPLE__, and a wasm build has no __APPLE__. So Ctrl was the shortcut key in every browser, and ImGuiBackend's mod() labels said "Ctrl+".

The change (src/cvcGL/ImGuiOverlay.cpp)

  • Detection. Under Emscripten the overlay reads the page's platform: navigator.userAgentData.platform, else navigator.platform. On a Mac, iPhone or iPad (isApplePlatformName, in ImGuiKeyNames.h) it turns the Mac behaviours on.
    • ?mackeys=1 or ?mackeys=0 overrules the detection. A host can still set the flag itself after the overlay is made.
    • ImGui's window-switching shortcut is chosen again to match, as ImGui does when it makes a context.
    • The console says which key was chosen, for example cvcGL: Cmd is the shortcut key (the page's platform 'macOS').
  • Cmd itself needs nothing new. Since cvcGL: Cmd+Z, C, V, X and A in an ImGui field on a Mac (the overlay's modifier keys) #1536, SDL hands the browser's Meta to the overlay as Super, and ImGui turns that into its shortcut key.
  • Cmd+V's paste. SDL 3.4.12's Emscripten_HandleKey cancels every keydown that has ctrlKey, but not one with metaKey. So Cmd+V's keydown is left to the browser, and the paste event that Clipboard.cpp reads still arrives. The browser test checks this.
  • A Mac's missing key-ups. A Mac sends no key-up for a key let go while Cmd is down. Chrome and Safari behave this way, and so does Cocoa unless the app reads its own event stream, as SDL does.
    • Left down, Cmd+Z's Z repeated the undo for as long as Cmd was held, until the field was empty. A second Cmd+Z under the same Cmd was no press at all.
    • Under Mac behaviours, a key pressed while Cmd is down is now a tap (press, then release). Cmd's release also lets go of any key still down, including one pressed before Cmd.
    • This also applies to the native hosts on a Mac. SDL's window gets real key-ups, so nothing changes there. VTK's own Cocoa window probably has the same gap; that is unverified.
  • Left alone: VTK's canvas window (CVCGL_SDL_WINDOW=0) reads only ctrlKey, so on a Mac Ctrl stays the shortcut key there, under cvcGL: Cmd+Z, C, V, X and A in an ImGui field on a Mac (the overlay's modifier keys) #1536's rule for a window with one control flag.

Tests

  • New src/arigl/web/test/arigl_web_mac_keys.mjs runs arigl-web in headless Chrome. DevTools' Emulation.setUserAgentOverride makes the page see a Mac's navigator.platform (MacIntel) and userAgentData.platform (macOS). It checks:
    1. cvcGL chooses Cmd. Cmd+Z undoes; Ctrl+Z (ImGui's Super on a Mac) does not.
    2. With Cmd held 1.5 s after Cmd+Z and no key-up for Z, it undoes once. A second Z while Cmd is still down undoes once more.
    3. Cmd+V's keydown is not cancelled, its paste event comes (DevTools' paste editing command stands in for the Mac key binding), and the field takes the text.
    4. Under ?mackeys=0, Ctrl is the shortcut key again: Cmd+Z does nothing and Ctrl+Z undoes.
  • CI: the arigl-web job runs the new test. Its path filter now also covers ImGuiOverlay.cpp, ImGuiKeyNames.h and SdlWindow.cpp; before this, an overlay change didn't trigger the browser job.
  • cvcgl_imgui_key_names checks which platform names count as Apple's.
  • cvcgl_imgui_overlay_keys checks the missing key-up under VTK's window with Mac behaviours on: one undo with Cmd held, a second Z undoing again, and Cmd's release letting go of a key held from before it.

Local results. Linux, with a single-threaded arigl-web built by the recipe's build-wasm.sh from cvcpkg's emsdk and wasm deps, and Chrome 152 headless:

  • arigl_web_mac_keys.mjs: 12 of 12. arigl_web_clipboard.mjs: 10 of 10. arigl_web_smoke.mjs: 25 of 25.
  • With the tap and the release on Cmd's key-up turned off, step 2 fails in the browser. Holding Cmd after Cmd+Z emptied the field, and natively the field also emptied (''). The three native key-up checks fail too.
  • Native: 32 of 32 in the cvcgl_imgui_*, cvcgl_sdl_*, cvcgl_camera_sdl_fly, cvcgl_ariadne_pick, cvcgl_ariadne_node_pick and cvcgl_tf_editor set, under cvcpkg's Xvfb.
  • A screenshot on the emulated Mac shows the field's menu with Cmd+X, Cmd+C, Cmd+V and Cmd+A.

Not verified: a real Mac. Everything above is Chrome on Linux told it runs on a Mac, with the missing key-ups simulated.

macOS lanes: CI/CD run 45585022967 on ci/full/ari-web-mac-cmd. The tap changes native Mac behaviour too.

A separate bug, not fixed here

On a page that isn't on a Mac, SDL cancels Ctrl+V's keydown because ctrlKey makes it a "nav key". So the browser never fires its paste event, and Ctrl+V pastes nothing from the system clipboard into an arigl-web field.

A probe on this build showed it: the keydown was cancelled, no paste event came, and the field stayed ab. arigl_web_clipboard.mjs's Ctrl+V step passes anyway because it dispatches the paste event itself, before the keys. ARIADNE.md §5.28's "Ctrl+V works as it always did, through the page's paste event" is untrue under SDL's window.

ImGui 1.92.9 with ConfigMacOSXBehaviors (its default on Apple) swaps Cmd
and Ctrl in AddKeyEvent, so a host sends Cmd as ImGuiMod_Super. The
overlay sent VTK's control flag as ImGuiMod_Ctrl, which became Super:

- VTK's own window: its Cocoa view sets the one control flag for Cmd or
  Ctrl (vtkCocoaGLView.mm). Cmd+Z did not undo and typed a "z", since
  ImGui drops characters only under its own Ctrl. Under Mac behaviours
  the flag (and its Control_L/R) now goes in as Super.
- cvcGL's SDL3 window dropped the GUI key. SdlRenderWindowInteractor's
  GetSuperKey() now carries SDL_KMOD_GUI, and the overlay hands ImGui
  Ctrl and Super as they are, as imgui_impl_sdl3 does.

cvcgl_imgui_overlay_keys drives a real overlay through a VTK interactor
with Mac behaviours forced on and off, with no window and no GL.
cvcgl_sdl_attach checks the GUI key on SDL's window and through the
overlay. ARIADNE.md says what pick mods mean on a Mac.
On Windows imgui is linked into cvcGL and into each test, each with its
own current context. cvcgl_imgui_overlay_keys and cvcgl_sdl_attach set
only cvcGL's (ImGuiBackend::setImGuiContext), so their own ImGui calls
asserted on "No current context" (exit 0xc0000409 on package-windows).
They now set both, as cvcgl_imgui_touch_scroll does.
A wasm build has no __APPLE__, so ImGui's Mac behaviours were off in
every browser, a Mac's included: Ctrl was the shortcut key and the menus
said "Ctrl+". ImGuiOverlay now reads the page's platform
(navigator.userAgentData.platform, else navigator.platform) and turns
them on for a Mac, iPhone or iPad; ?mackeys=1|0 overrules it. SDL hands
the browser's Meta over as Super, and leaves Cmd+V's keydown to the
browser, so the paste event the clipboard reads still comes.

A Mac sends no key-up for a key let go while Cmd is down (Chrome and
Safari; Cocoa unless the app asks, as SDL does). Left down, Cmd+Z's Z
repeated the undo for as long as Cmd was held, until the field was
empty. Under Mac behaviours a press under Cmd is now a tap, and Cmd's
release lets go of any key still down.

arigl_web_mac_keys.mjs runs arigl-web in headless Chrome told it is on
a Mac (DevTools' user-agent override): Cmd+Z, Ctrl+Z, Cmd held with no
key-up for Z, Cmd+V's paste, and Ctrl again under ?mackeys=0. CI's
arigl-web job runs it, and now also when the overlay changes.
cvcgl_imgui_key_names checks the platform names, and
cvcgl_imgui_overlay_keys the missing key-up.
@transfix
transfix force-pushed the feat/ari-web-mac-cmd branch from 0bb103e to 0f11405 Compare November 25, 2026 20:05
@transfix
transfix merged commit 7ded735 into master Nov 26, 2026
30 checks passed
@transfix
transfix deleted the feat/ari-web-mac-cmd branch November 26, 2026 06:10
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