]> repos.lx-s.de Git - winmute.git/commitdiff
Hopefully fixed rare glitch that UI thread starts hanging.
authorAlexander Steinhöfer <kontakt@lx-s.de>
Fri, 29 Apr 2022 13:46:57 +0000 (15:46 +0200)
committerAlexander Steinhöfer <kontakt@lx-s.de>
Fri, 29 Apr 2022 13:46:57 +0000 (15:46 +0200)
ScreensaverNotify/ScreensaverNotify.cpp
ScreensaverNotify/ScreensaverNotify.vcxproj.filters
ScreensaverNotify32/ScreensaverNotify32.vcxproj.filters
ScreensaverProxy32/ScreensaverProxy32.vcxproj.filters
WinMute/ScreensaverNotifier.cpp
WinMute/ScreensaverNotifier.h
WinMute/WinMute.cpp

index 22aab1090ffe741d93a3c541b73769addc658154..95acc39baaf069f561bcdeb5c8d12edf18a5b464 100644 (file)
@@ -55,15 +55,17 @@ static HINSTANCE hglobInstance_ = nullptr;
       Hook Function
    ========================================================================== */
 
-static LRESULT CALLBACK MsgHookProc(UINT code, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK MsgHookProc(UINT nCode, WPARAM wParam, LPARAM lParam)
 {
-   MSG const* const msg = reinterpret_cast<LPMSG>(lParam);
-   if (msg->message == WM_SYSCOMMAND) {
-      if (msg->wParam == SC_SCREENSAVE) {
-         PostMessage(hNotifyWnd_, notifyWndMsgId_, wParam, lParam);
+   const LPMSG msg = reinterpret_cast<LPMSG>(lParam);
+   if (nCode == HC_ACTION) {
+      if (msg->message == WM_SYSCOMMAND) {
+         if (msg->wParam == SC_SCREENSAVE) {
+            PostMessage(hNotifyWnd_, notifyWndMsgId_, wParam, lParam);
+         }
       }
    }
-   return CallNextHookEx(hook_, code, wParam, lParam);
+   return CallNextHookEx(hook_, nCode, wParam, lParam);
 }
 
 /* =============================================================================
index 61040973cfec836535ee03277f2fa702dc01b016..224882371f76ae7d09a928b0b1469b9d78be6e74 100644 (file)
@@ -5,6 +5,9 @@
       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
       <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{51f0faf5-9928-418a-bdf0-57133f81d6b5}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="ScreensaverNotify.cpp">
     <ClInclude Include="ScreensaverNotify.h">
       <Filter>Source Files</Filter>
     </ClInclude>
-    <ClInclude Include="resource.h" />
+    <ClInclude Include="resource.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ResourceCompile Include="ScreensaverNotify.rc" />
+    <ResourceCompile Include="ScreensaverNotify.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 91df9d21ee16021c9e51ac81540f85f7e4f84aed..92452b86181557da5cb9a4070136b7ebbb18fc71 100644 (file)
@@ -5,6 +5,9 @@
       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
       <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{240fe0a1-842e-48f1-bd9d-126731782b14}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\ScreensaverNotify\ScreensaverNotify.cpp">
     <ClInclude Include="..\ScreensaverNotify\ScreensaverNotify.h">
       <Filter>Source Files</Filter>
     </ClInclude>
-    <ClInclude Include="resource.h" />
+    <ClInclude Include="resource.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ResourceCompile Include="ScreensaverNotify32.rc" />
+    <ResourceCompile Include="ScreensaverNotify32.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index ca5a44a1191c7310e57140846623ba2d17266ab6..3dbf6aebca7822428ad595ede81a6f5b18f41d5c 100644 (file)
@@ -5,6 +5,9 @@
       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
       <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     </Filter>
+    <Filter Include="Resource Files">
+      <UniqueIdentifier>{256e848e-f08e-4891-a6d2-e72679385047}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="ScreensaverNotifierProxy.cpp">
     <ClInclude Include="ScreensaverNotifierProxy.h">
       <Filter>Source Files</Filter>
     </ClInclude>
-    <ClInclude Include="resource.h" />
+    <ClInclude Include="resource.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ResourceCompile Include="ScreensaverProxy32.rc" />
+    <ResourceCompile Include="ScreensaverProxy32.rc">
+      <Filter>Resource Files</Filter>
+    </ResourceCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 0a11a8106a0074a125145e844d9279c6cf254f64..1bfad0c9a5ee4043dbb84dbf35b4d01d7ef6c39f 100644 (file)
@@ -318,11 +318,8 @@ LRESULT CALLBACK ScreensaverNotifier::WindowProc(
    static UINT uTaskbarRestart = 0;
    switch (msg) {
    case WM_CREATE:
-   {
       return TRUE;
-   }
    case WM_TIMER:
-   {
       if (wParam == SCRSV_TIMER_ID) {
          if (!IsScreensaverRunning()) {
             StartScreensaverPollTimer(false);
@@ -331,9 +328,8 @@ LRESULT CALLBACK ScreensaverNotifier::WindowProc(
          }
       }
       return 0;
-   }
    default:
-      if (hookWndMsg_ != 0 && msg == hookWndMsg_) {
+      if (hookWndMsg_ != 0 && msg == hookWndMsg_ && !alreadyNotified_) {
          /* Windows sends SC_SCREENSAVE when it tries to start a screensaver.
             If screensaver is set to "none" or if another application cancels
             this event, we would falsely mute windows.
@@ -344,11 +340,9 @@ LRESULT CALLBACK ScreensaverNotifier::WindowProc(
          Sleep(500);
          if (IsScreensaverRunning()) {
             /* SC_SCREENSAVE might be fired multiple times */
-            if (!alreadyNotified_) {
-               alreadyNotified_ = true;
-               SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_START, 0);
-               StartScreensaverPollTimer();
-            }
+            alreadyNotified_ = true;
+            SendMessage(hNotifyWnd_, WM_SCRNSAVE_CHANGE, SCRNSAVE_START, 0);
+            StartScreensaverPollTimer(true);
          }
       }
       break;
index ca8ec0e7749fcc1df917fc91e1506e0af613aa3b..6d1ebafa61515dae362802b255210334d1959743 100644 (file)
@@ -71,7 +71,7 @@ private:
    RegisterHook regHook_;
    UnregisterHook unregHook_;
 
-   void StartScreensaverPollTimer(bool start = true);
+   void StartScreensaverPollTimer(bool start);
 
    bool IsScreensaverRunning();
 
index c5c0f1933e6431f99fc3dec1b9f726dbbca0414d..ccf91394b0892c38c19227b79a563064eb677dd4 100644 (file)
@@ -476,7 +476,6 @@ LRESULT CALLBACK WinMute::WindowProc(
          SetForegroundWindow(hWnd);
          TrackPopupMenuEx(GetSubMenu(hTrayMenu_, 0), TPM_NONOTIFY | TPM_TOPALIGN
             | TPM_LEFTALIGN, p.x, p.y, hWnd_, nullptr);
-         PostMessage(hWnd, WM_NULL, 0, 0);
          break;
       }
       default: