]> repos.lx-s.de Git - winmute.git/commitdiff
use new trayicon version
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:45:39 +0000 (14:45 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:45:39 +0000 (14:45 +0200)
WinMute/TrayIcon.cpp
WinMute/WinMute.cpp

index 4bca8d4a73cea50cda8f0cc568f1cc5da48e9fa9..460c015b5d21e9a9847ee30ca5f5410b18136e9f 100644 (file)
@@ -107,7 +107,6 @@ void TrayIcon::ChangeIcon(HICON hNewIcon)
     if (oldIconVisible) {
         NOTIFYICONDATA tnid{0};
         tnid.cbSize = sizeof(NOTIFYICONDATA);
-        tnid.uVersion = NOTIFYICON_VERSION_4;
         tnid.hWnd = hWnd_;
         tnid.uID = trayID_;
         tnid.hIcon = hIcon_;
@@ -142,13 +141,11 @@ void TrayIcon::ShowPopup(const std::wstring& title,
     }
     NOTIFYICONDATAW tnid{0};
     tnid.cbSize = sizeof(tnid);
-    tnid.uVersion = NOTIFYICON_VERSION_4;
     tnid.hWnd = hWnd_;
     tnid.uID = trayID_;
     tnid.uFlags = NIF_INFO | NIF_SHOWTIP;
     tnid.dwInfoFlags =
         NIIF_INFO | NIIF_NOSOUND | NIIF_LARGE_ICON | NIIF_RESPECT_QUIET_TIME;
-    tnid.uTimeout = 10 * 1000;
     StringCchCopy(tnid.szInfoTitle, ARRAY_SIZE(tnid.szInfoTitle),
                   title.c_str());
     StringCchCopy(tnid.szInfo, ARRAY_SIZE(tnid.szInfo), text.c_str());
@@ -178,11 +175,13 @@ bool TrayIcon::AddNotifyIcon()
     if (SUCCEEDED(StringCchCopy(tnid.szTip, ARRAY_SIZE(tnid.szTip),
                                 tooltip_.c_str())))
     {
-        DWORD result = Shell_NotifyIconW(NIM_ADD, &tnid);
-        if (result == 0) {
+        BOOL result = Shell_NotifyIconW(NIM_ADD, &tnid);
+        if (result) {
+            // Opt in to NOTIFYICON_VERSION_4 message semantics; uVersion is
+            // only honored by NIM_SETVERSION.
             result = Shell_NotifyIconW(NIM_SETVERSION, &tnid);
         }
-        return result != 0;
+        return result != FALSE;
     }
     return false;
 }
@@ -191,7 +190,6 @@ bool TrayIcon::RemoveNotifyIcon()
 {
     NOTIFYICONDATAW tnid{0};
     tnid.cbSize = sizeof(tnid);
-    tnid.uVersion = NOTIFYICON_VERSION_4;
     tnid.hWnd = hWnd_;
     tnid.uID = trayID_;
 
@@ -202,7 +200,6 @@ bool TrayIcon::ChangeText()
 {
     NOTIFYICONDATAW tnid{0};
     tnid.cbSize = sizeof(tnid);
-    tnid.uVersion = NOTIFYICON_VERSION_4;
     tnid.hWnd = hWnd_;
     tnid.uID = trayID_;
     tnid.uFlags = NIF_TIP;
index 1eb796b9ac83e414c538574701cdf257e9d2b963..154bd04f6875a04c846041754985aad4e39c920a 100644 (file)
@@ -339,7 +339,7 @@ bool WinMute::LoadSettings()
       } else {
          muteCtrl_.SetMuteOnBluetoothDisconnect(true);
          const bool muteOnWithDeviceList = settings_.QueryValue(SettingsKey::MUTE_ON_BLUETOOTH_DEVICELIST);
-         btDetector_.SetDeviceList(settings_.GetBluetoothDevicesA(), muteOnWithDeviceList);
+         btDetector_.SetDeviceList(settings_.GetBluetoothDevices(), muteOnWithDeviceList);
       }
    }
 
@@ -564,13 +564,15 @@ LRESULT WinMute::OnCommand(HWND hWnd, WPARAM wParam, LPARAM)
    return 0;
 }
 
-LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM, LPARAM lParam)
+LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM wParam, LPARAM lParam)
 {
-   if (LOWORD(lParam) == WM_CONTEXTMENU ||
-       lParam == WM_LBUTTONUP ||
-       lParam == WM_RBUTTONUP) {
-      POINT p = { 0 };
-      GetCursorPos(&p);
+   // NOTIFYICON_VERSION_4 semantics: LOWORD(lParam) carries the event,
+   // HIWORD(lParam) the icon ID and wParam the anchor coordinates.
+   const UINT event = LOWORD(lParam);
+   if (event == WM_CONTEXTMENU ||
+       event == NIN_SELECT ||
+       event == NIN_KEYSELECT) {
+      const POINT p{ GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam) };
       SetForegroundWindow(hWnd);
       TrackPopupMenuEx(
          GetSubMenu(hTrayMenu_, 0),
@@ -582,7 +584,9 @@ LRESULT WinMute::OnTrayIcon(HWND hWnd, WPARAM, LPARAM lParam)
 
 LRESULT WinMute::OnUpdatePopup(HWND hWnd, WPARAM, LPARAM lParam)
 {
-   if (lParam == NIN_BALLOONUSERCLICK) {
+   // NOTIFYICON_VERSION_4 semantics: LOWORD(lParam) carries the event.
+   const UINT event = LOWORD(lParam);
+   if (event == NIN_BALLOONUSERCLICK) {
       const bool betaUpdates = settings_.QueryValue(SettingsKey::CHECK_FOR_BETA_UPDATE) != 0;
       if (betaUpdates && updateInfo_.beta.shouldUpdate) {
          LaunchBrowser(hWnd, updateInfo_.beta.downloadUrl);
@@ -590,7 +594,7 @@ LRESULT WinMute::OnUpdatePopup(HWND hWnd, WPARAM, LPARAM lParam)
          LaunchBrowser(hWnd, updateInfo_.stable.downloadUrl);
       }
    }
-   if (lParam == NIN_BALLOONHIDE || lParam == NIN_BALLOONTIMEOUT || lParam == NIN_BALLOONUSERCLICK) {
+   if (event == NIN_BALLOONHIDE || event == NIN_BALLOONTIMEOUT || event == NIN_BALLOONUSERCLICK) {
       updateTray_.Hide();
    }
    return 0;