Skip to content

Catch Cmd+W on macOS before the input method swallows it - #260

Merged
huacnlee merged 1 commit into
mainfrom
fix/macos-close-chord-before-ime
Sep 20, 2026
Merged

huacnlee merged 1 commit into
mainfrom
fix/macos-close-chord-before-ime

Conversation

@huacnlee

Copy link
Copy Markdown
Owner

Release Notes

  • Cmd+W on macOS now closes the window even while an input method (pinyin and the like) has uncommitted text in a field.

Why

#214 fixed the shortcut context, and offscreen the close chord works from every app context, with the app menu, a tooltip, a focused compose field or the calendar up (new tests cover the first two). What remained is a path below Qt: Cocoa delivers Cmd+W through keyDown:, and QNSView handleKeyEvent: only tries the key as a shortcut when m_composingText is empty. During an IME composition the chord is handed to the input method and either dropped or delivered as plain text, so the QML Shortcut never fires. A native app's Close is a menu key equivalent and is handled before the input method.

What changed

  • window_macos.mm: a local NSEvent monitor takes Cmd+W (Command only, watched window is key) off the stream and calls the host; other platforms keep a no-op stub.
  • ApplicationHost gains requestClose() / closeRequested(); Main.qml relays it to mailApp.requestClose(), so the window still hides through the host and the process stays alive for the Dock.
  • Tests: HostFixture exposes closeRequested; tst_standalone_composition covers the host relay plus the open-menu and visible-tooltip cases.

No visual change, so no screenshots.

Verification

  • QT_QPA_PLATFORM=offscreen ctest --test-dir app/build 7/7, python3 app/tests/test_qml_inventory.py, bash tests/test_source.sh, python3 tests/test_qml_names.py.
  • Not verified here: this was written on Linux, so window_macos.mm has not been compiled. Please run make app-run on macOS, type a few uncommitted pinyin letters in the search field, press Cmd+W, and confirm the window hides.

🤖 Generated with Claude Code

Cocoa hands Cmd+W to Qt through keyDown:, and QNSView tries it as a
shortcut only while no input method composition is pending. With a
pinyin or other IME mid-composition the chord goes to the input method
instead and the window stays open. A native Close is a menu key
equivalent and wins ahead of that; a local NSEvent monitor on the
composition window restores the same order and relays the chord to the
host, which asks the window to leave the way the QML Shortcut does.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@huacnlee
huacnlee enabled auto-merge (squash) September 20, 2026 12:20
@huacnlee
huacnlee merged commit 958ed54 into main Sep 20, 2026
14 checks passed
@huacnlee
huacnlee deleted the fix/macos-close-chord-before-ime branch September 20, 2026 12:20
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