Skip to content

cvcGL: Cmd+Z, C, V, X and A in an ImGui field on a Mac (the overlay's modifier keys) - #1536

Closed
transfix wants to merge 2 commits into
masterfrom
fix/imgui-overlay-macos-mods
Closed

transfix wants to merge 2 commits into
masterfrom
fix/imgui-overlay-macos-mods

Conversation

@transfix

Copy link
Copy Markdown
Owner

On a Mac, ImGuiOverlay passed ImGui the wrong modifier for Cmd, in both of cvcGL's windows. So Cmd+Z, C, V, X and A probably did nothing in an ImGui field, and in VTK's window Cmd+C probably typed a "c". No one has run this on a real Mac yet. The CI evidence is listed under Tests.

The bug

ImGui 1.92.9 with io.ConfigMacOSXBehaviors swaps Cmd and Ctrl inside AddKeyEvent. That setting is on by default on Apple. After the swap, ImGui's ImGuiMod_Ctrl is its shortcut key: the one Shortcut(ImGuiMod_Ctrl | ImGuiKey_Z) and InputText's undo look for. A host has to send Cmd as ImGuiMod_Super, and ImGui turns it into Ctrl.

  • VTK's own window (vtkCocoaGLView.mm:241, the same in VTK 9.5 and master) has one control flag, set for Cmd or Ctrl. The overlay sent it as ImGuiMod_Ctrl, and ImGui swapped it to Super. So Cmd+Z did not undo. ImGui drops typed characters only under its own Ctrl, so the "z" that Cocoa sends with Cmd+Z went into the field. Physical Ctrl+Z did nothing either, because its ^Z is filtered out.
  • cvcGL's SDL3 window is the default onscreen window wherever cvcGL has SDL, the macOS packages included. It set VTK's control flag from SDL_KMOD_CTRL only and dropped the GUI key (Cmd).

The fix

  • ImGuiOverlay.cpp, VTK's window: under ConfigMacOSXBehaviors the control flag goes in as ImGuiMod_Super, which ImGui turns into its shortcut key. Control_L/Control_R go in as LeftSuper/RightSuper to match. With Mac behaviours off, nothing changes. This is the same change macOS CI: contour_tiler's macOS golden, Cmd+Z in the context-menu test, ci/full for new goldens #1526 made to the context-menu test's undo step.
  • SdlWindow: SdlRenderWindowInteractor::GetSuperKey() carries SDL_KMOD_GUI, since VTK has no flag for it. On SDL's window the overlay passes Ctrl as ImGuiMod_Ctrl and GUI as ImGuiMod_Super, the way imgui_impl_sdl3 does, and ImGui swaps them on a Mac. On other platforms the GUI key (the Windows key, a browser's Meta) now reaches ImGui as Super, and no ImGui shortcut uses Super there.

Other changes on a Mac (also unverified on a real Mac)

  • Ariadne's pick mods are ImGui's io.KeyCtrl/io.KeySuper, so Cmd now reports ctrl. Before, it reported super under VTK's window and nothing under SDL's. Physical Ctrl reports super under SDL's window and ctrl under VTK's. ARIADNE.md now says what the mods mean on a Mac.
  • ImGui's Ctrl+click as a right click: under VTK's window, Cmd+click and Ctrl+click no longer count as a right click, because the one flag is now the shortcut key. Under SDL's window, Ctrl+click is still a right click, as on a native Mac app.

Checked and left alone

  • ImGuiBackend.cpp's mod() menu labels already say "Cmd+" under ConfigMacOSXBehaviors, and that now matches what works.
  • The browser (arigl-web): under Emscripten ConfigMacOSXBehaviors is off, because __APPLE__ is not defined. So Ctrl stays the shortcut key in a browser on a Mac, and the labels say "Ctrl+". VTK's canvas interactor reads ctrlKey only. Making Cmd the shortcut there means reading the page's platform and checking the browser's paste event under Cmd+V, so it is left as a follow-up.
  • SdlInput.cpp:117 builds SDL-style modifiers from VTK's window for app input, not for ImGui. Cmd still arrives there as LCTRL.

Tests

  • New cvcgl_imgui_overlay_keys, which needs no GL and no Mac and runs on every lane. It builds a real ImGuiOverlay on an offscreen view with an uninitialized VTK interactor, and runs ImGui's frames on the overlay's own context.
    • With Mac behaviours forced on, it sends keys the way VTK's Cocoa view does. Cmd+Z (the flag plus a "z" CharEvent) undoes and types no "z". Ctrl+Z (the flag plus ^Z) undoes too. Cmd+A selects all.
    • With them off: Ctrl+Z undoes and Ctrl+A selects all.
    • Both ways it also sends ImGuiMod_Ctrl+Z straight to ImGui, which is what the overlay used to send. It does not undo with Mac behaviours on, and does with them off.
  • cvcgl_sdl_attach, on a real SDL window (Xvfb on package-linux), gains these checks:
    • GUI+Z sets GetSuperKey and leaves the control flag clear. Ctrl+Z sets only the control flag.
    • Through the overlay with Mac behaviours on, Cmd+Z undoes and Ctrl is Super. With them off, Ctrl+Z undoes and GUI is Super.

Local results (Linux, Release, phm; cvcpkg's Xvfb and Mesa for the SDL window):

  • cvcgl_imgui_overlay_keys passes 11 of 11, with a display and without one.
  • Against master's overlay it fails 5 of the 6 Mac checks. Cmd+Z leaves 'abcz' and Cmd+A types an "a": the symptom described above, reproduced.
  • cvcgl_sdl_attach passes, and fails 4 of its new checks against master's overlay.
  • 32 of 32 pass in the cvcgl_imgui_*, cvcgl_sdl_*, cvcgl_camera_sdl_fly, cvcgl_ariadne_pick, cvcgl_ariadne_node_pick and cvcgl_tf_editor set.

macOS: PRs skip the macOS package lanes, so the same commit is also pushed to ci/full/imgui-overlay-macos-mods: CI/CD run 45577628329. There, cvcgl_imgui_overlay_keys runs with ImGui's default, so Mac behaviours are on from __APPLE__ and the test forces them both ways. No one has pressed Cmd+Z on a real Mac yet.

Don't merge this without Joe's OK.

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.
transfix added a commit that referenced this pull request Nov 26, 2026
#1539)

Includes #1536 (the native fix), which #1539 was stacked on.

- VTK's own window: its Cocoa view sets one control flag for Cmd or Ctrl. Under ImGui's Mac behaviours that flag now goes in as ImGuiMod_Super, which ImGui swaps to its shortcut key. Sent as Ctrl, Cmd+Z did not undo and Cmd+C typed a "c".
- cvcGL's SDL window carries the GUI key as SdlRenderWindowInteractor::GetSuperKey(), and the overlay hands ImGui Ctrl and Super as they are.
- In a browser (no __APPLE__), the overlay turns on Mac behaviours from the page's platform; ?mackeys=1|0 overrules it.
- A Mac sends no key-up for a key let go while Cmd is down. Under Cmd a press is now a tap, and Cmd's release lets go of any key still down.
- Tests: cvcgl_imgui_overlay_keys (no GL, no display), cvcgl_sdl_attach's Cmd/Ctrl checks, cvcgl_imgui_key_names' platform names, and arigl_web_mac_keys.mjs in CI's arigl-web job.
@transfix

Copy link
Copy Markdown
Owner Author

Included in #1539, which was stacked on this PR and squash-merged to master as 7ded735 with Joe's OK ("merge 1539"). That commit has both of this PR's commits: the native Cmd/Ctrl fix and the Windows ImGui-context test fix. On the ci/full runs, the new tests passed on all four macOS lanes; the only macOS failures there were cvcgl_imgui_context_menu and cvcgl_ari_golden, which #1526 fixed. master's own push run will check macOS on the merged code. Closing as included.

@transfix transfix closed this Nov 26, 2026
@transfix
transfix deleted the fix/imgui-overlay-macos-mods branch November 26, 2026 06:11
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