Skip to content

feat(ui): hide-to-tray Cmd-W / Cmd-M / Esc shortcuts on main window#167

Open
hughesyadaddy wants to merge 2 commits into
TomBadash:masterfrom
hughesyadaddy:feat/qml-hide-to-tray-shortcuts
Open

feat(ui): hide-to-tray Cmd-W / Cmd-M / Esc shortcuts on main window#167
hughesyadaddy wants to merge 2 commits into
TomBadash:masterfrom
hughesyadaddy:feat/qml-hide-to-tray-shortcuts

Conversation

@hughesyadaddy
Copy link
Copy Markdown
Contributor

@hughesyadaddy hughesyadaddy commented May 14, 2026

Why

Mouser ships with start_minimized defaulting to true, and the
feat/macos-app-shell work turns it into a proper menu-bar app on
macOS. That's the right model — but the moment the main window is
open, the standard keyboard shortcuts users expect from menu-bar apps
do not work:

  • Cmd-W does nothing (or fights Qt's default close). Users assume
    it'll hide the window the way every other macOS menu-bar app
    behaves and end up quitting the app or hunting for the dock icon.
  • Cmd-M does nothing. The window minimises into the Dock under
    the hood, leaving the tray icon orphaned.
  • Esc dismisses popups only. The window itself stays modal-feeling
    even though the app is happy to live in the tray.

All three keystrokes already have a sensible target: route them
through the same dismiss() path the tray icon's "Hide" item uses.

What changed

ui/qml/Main.qml:

  • A dismiss() function consolidates the existing close paths
    (tray "Hide", window close button, etc).
  • Three new Shortcut blocks bind Cmd-W (StandardKey.Close),
    Cmd-M (Ctrl+M), and Esc to dismiss().
  • Shortcut.WindowShortcut scope is used so the bindings only fire
    while the main window is the active key window — they don't
    steal Cmd-W from any modal dialog that's open over the window.
  • The Esc shortcut is gated on !anyDialogOpen so it doesn't
    conflict with Popup.CloseOnEscape (which dismisses the popup
    first).

No behaviour change for users who don't press these keys, no new
config, no new strings.

Test plan

  • Launch app. Cmd-W → window hides to tray. Tray icon stays.
  • Re-open via tray. Cmd-M → same.
  • Re-open. Esc with no dialog open → same. With the
    device-list dialog open → dialog closes, window stays.
  • pytest tests/ green.

@hughesyadaddy hughesyadaddy force-pushed the feat/qml-hide-to-tray-shortcuts branch 2 times, most recently from 3bd506c to 18b097b Compare May 14, 2026 17:31
Mouser is configured as LSUIElement on macOS, so closing the main
window must keep the engine running. The existing onClosing handler
covered the red traffic light, but Cmd-W, Cmd-M, and Esc never
reached it because LSUIElement apps don't ship a platform menu bar
for Qt to bind StandardKey.Close against.

Route all four dismissal paths through a single dismiss() helper and
add explicit Shortcut blocks for Cmd-W (StandardKey.Close), Cmd-M
(Ctrl+M), and Esc. Cmd-W and Cmd-M use Qt.ApplicationShortcut; Esc
uses Qt.WindowShortcut so it stays scoped to the focused main
window. Modal dialogs continue to consume Esc first via their
Popup.CloseOnEscape policy.
- Make dismiss() idempotent when the window is already hidden so QApplication
  doesn't process a redundant hide() / visibilityChanged round-trip.
- Gate the three Shortcut bindings on root.visible so Cmd-W / Cmd-M never fire
  from background after the user has already tucked the window into the tray.
- Update comments to make the cross-platform contract explicit and document
  that modal Popups consume Esc via CloseOnEscape before the window shortcut
  has a chance to hide the main window.
@hughesyadaddy hughesyadaddy force-pushed the feat/qml-hide-to-tray-shortcuts branch from 77c1168 to 19938c8 Compare May 18, 2026 15:21
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