Skip to content

feat(port): mute on window focus loss#237

Open
Zorkats wants to merge 2 commits into
JRickey:mainfrom
Zorkats:feat/window-focus-controls
Open

feat(port): mute on window focus loss#237
Zorkats wants to merge 2 commits into
JRickey:mainfrom
Zorkats:feat/window-focus-controls

Conversation

@Zorkats

@Zorkats Zorkats commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What

One independent behavior, off-by-default-friendly and independently toggled from Settings > Audio > Focus Behavior:

Setting CVar Default
Mute on Focus Loss gSettings.FocusControl.MuteOnFocusLoss Off

Mute: when the window loses focus and the CVar is enabled, gSettings.Audio.MasterVolume is saved and set to 0.0f. On refocus, the saved value is restored. Volume-save state uses a sentinel of -1.0f so a double focus-loss doesn't corrupt the saved value.

Implementation

  • port/focus.h / port/focus.cppssb64::RegisterFocusListener() registers a WindowFocusEvent listener via REGISTER_LISTENER. No global listener object; the listener ID is fire-and-forget (unregistered on shutdown via the event system teardown).
  • port/hooks/Events.h — adds #include "ship/events/WindowEvents.h" so WindowFocusEvent is available to all port TUs that include Events.h.
  • port/hooks/Events.cpp — adds REGISTER_EVENT(WindowFocusEvent) to PortRegisterEvents().
  • port/port.cpp — calls ssb64::RegisterFocusListener() immediately after PortRegisterEvents().
  • port/gui/PortMenu.cpp — adds "Focus Behavior" separator and one checkbox in the Audio sidebar, after the voice volume slider.

focus.cpp is picked up by file(GLOB_RECURSE SSB64_SRC_PORT "port/*.cpp" ...) in CMakeLists.txt; no CMake edit was needed.

Depends on PR#7 of libultraship.

Test plan

  • Build succeeds on Windows (MSVC/Ninja) and Linux (CachyOS, Linux GCC 16.1.1)
  • "Mute on Focus Loss" checked: audio silences on alt-tab, restores on refocus
  • "Mute on Focus Loss" unchecked: audio unaffected by alt-tab
  • Rapid alt-tab (focus-lost/gained in quick succession): volume sentinel prevents double-save corruption
  • Settings > Audio shows "Focus Behavior" section with checkbox and tooltip.

@Zorkats Zorkats changed the title Feat/window focus controls feat(port): mute on window focus loss Jun 20, 2026
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