]> repos.lx-s.de Git - winmute.git/commitdiff
Update 'mute now' check according to the mute state of the managed devices
authorlx-s <lx-s@users.noreply.github.com>
Tue, 18 Aug 2026 07:54:36 +0000 (09:54 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Tue, 18 Aug 2026 07:54:36 +0000 (09:54 +0200)
WinMute/MuteControl.cpp
WinMute/MuteControl.h
WinMute/WinMute.cpp
WinMute/WinMute.h

index dcb456a07298cbd4d542755c8b21e6df0d29643e..b2bc003402085e79bd0bbff909f23763ffee2e35 100644 (file)
@@ -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;
 }
index f3b7f915ec87d27df215ff117bb2798a7c934232..61c8051ac6af3113ef788a5a983345970bb2b27b 100644 (file)
@@ -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);
index 2c422a44621d798bfacc526cc27cd4e8f9479c18..d4e35735b46930c032a426720aff2c0865bbe2f7 100644 (file)
@@ -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<UINT, std::wstring> 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,
index 2ffe5a1b4781f305cd7fbd76444a3842b838b433..d790b7dda692129c72b0013fbdfa0d6a015c6b1e 100644 (file)
@@ -105,6 +105,7 @@ class WinMute {
 
     void ToggleMenuCheck(UINT item, bool* setting) noexcept;
     void ToggleMute();
+    void UpdateMuteMenuCheck(bool muted) noexcept;
 
     void LoadMainMenuText();
     void LoadGlobalHotkeys();