From 23335c58539f3940c3035b07fafd96457beb92dc Mon Sep 17 00:00:00 2001 From: lx-s Date: Tue, 18 Aug 2026 09:54:36 +0200 Subject: [PATCH] Update 'mute now' check according to the mute state of the managed devices --- WinMute/MuteControl.cpp | 7 ++++++- WinMute/MuteControl.h | 3 +++ WinMute/WinMute.cpp | 16 +++++++++++++--- WinMute/WinMute.h | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/WinMute/MuteControl.cpp b/WinMute/MuteControl.cpp index dcb456a..b2bc003 100644 --- a/WinMute/MuteControl.cpp +++ b/WinMute/MuteControl.cpp @@ -148,11 +148,16 @@ void MuteControl::SetMute(bool mute) winAudio_->SetMute(mute); } +bool MuteControl::IsMuted() +{ + return winAudio_->AllEndpointsMuted(); +} + bool MuteControl::ToggleMute() { // A partially muted setup counts as "not muted", so the first toggle // normalizes every managed endpoint to muted. - const bool mute = !winAudio_->AllEndpointsMuted(); + const bool mute = !IsMuted(); SetMute(mute); return mute; } diff --git a/WinMute/MuteControl.h b/WinMute/MuteControl.h index f3b7f91..61c8051 100644 --- a/WinMute/MuteControl.h +++ b/WinMute/MuteControl.h @@ -55,6 +55,9 @@ class MuteControl { // state that was set. bool ToggleMute(); + // True only if every managed endpoint is currently muted. + bool IsMuted(); + void SetRestoreVolume(bool enable); void SetMuteDelay(int delaySeconds); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index 2c422a4..d4e3573 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -207,7 +207,8 @@ bool WinMute::InitTrayMenu() } } - if (!CHECK_MENU_ITEM(MUTEONLOCK, muteCtrl_.GetMuteOnWorkstationLock()) || + if (!CHECK_MENU_ITEM(MUTE, muteCtrl_.IsMuted()) || + !CHECK_MENU_ITEM(MUTEONLOCK, muteCtrl_.GetMuteOnWorkstationLock()) || !CHECK_MENU_ITEM(RESTOREAUDIO, muteCtrl_.GetRestoreVolume()) || !CHECK_MENU_ITEM(MUTEONSUSPEND, muteCtrl_.GetMuteOnSuspend()) || !CHECK_MENU_ITEM(MUTEONSHUTDOWN, muteCtrl_.GetMuteOnShutdown()) || @@ -559,13 +560,17 @@ void WinMute::ToggleMenuCheck(UINT item, bool* setting) noexcept } } -void WinMute::ToggleMute() +void WinMute::UpdateMuteMenuCheck(bool muted) noexcept { - const bool muted = muteCtrl_.ToggleMute(); CheckMenuItem(hTrayMenu_, ID_TRAYMENU_MUTE, muted ? MF_CHECKED : MF_UNCHECKED); } +void WinMute::ToggleMute() +{ + UpdateMuteMenuCheck(muteCtrl_.ToggleMute()); +} + void WinMute::LoadMainMenuText() { std::map menuText; @@ -804,6 +809,11 @@ LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM wParam, LPARAM lParam) event == NIN_KEYSELECT) { const POINT p{GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam)}; + // Anything else can have changed the mute status in the meantime + // (a mute event, quiet hours, or the Windows volume mixer), so + // refresh the check right before the menu becomes visible. + // TPM_NONOTIFY suppresses WM_INITMENUPOPUP, hence doing it here. + UpdateMuteMenuCheck(muteCtrl_.IsMuted()); SetForegroundWindow(hWnd); TrackPopupMenuEx(GetSubMenu(hTrayMenu_, 0), TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN, p.x, p.y, diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index 2ffe5a1..d790b7d 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -105,6 +105,7 @@ class WinMute { void ToggleMenuCheck(UINT item, bool* setting) noexcept; void ToggleMute(); + void UpdateMuteMenuCheck(bool muted) noexcept; void LoadMainMenuText(); void LoadGlobalHotkeys(); -- 2.43.0