From: Alexander Steinhöfer Date: Fri, 29 Apr 2022 13:46:57 +0000 (+0200) Subject: Hopefully fixed rare glitch that UI thread starts hanging. X-Git-Tag: 2.0.0.0~3 X-Git-Url: https://repos.lx-s.de/gitweb/?a=commitdiff_plain;h=0eb11430a235cdc293d6a0ea70ed4b65d98f8873;p=winmute.git Hopefully fixed rare glitch that UI thread starts hanging. --- diff --git a/ScreensaverNotify/ScreensaverNotify.cpp b/ScreensaverNotify/ScreensaverNotify.cpp index 22aab10..95acc39 100644 --- a/ScreensaverNotify/ScreensaverNotify.cpp +++ b/ScreensaverNotify/ScreensaverNotify.cpp @@ -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(lParam); - if (msg->message == WM_SYSCOMMAND) { - if (msg->wParam == SC_SCREENSAVE) { - PostMessage(hNotifyWnd_, notifyWndMsgId_, wParam, lParam); + const LPMSG msg = reinterpret_cast(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); } /* ============================================================================= diff --git a/ScreensaverNotify/ScreensaverNotify.vcxproj.filters b/ScreensaverNotify/ScreensaverNotify.vcxproj.filters index 6104097..2248823 100644 --- a/ScreensaverNotify/ScreensaverNotify.vcxproj.filters +++ b/ScreensaverNotify/ScreensaverNotify.vcxproj.filters @@ -5,6 +5,9 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + {51f0faf5-9928-418a-bdf0-57133f81d6b5} + @@ -15,9 +18,13 @@ Source Files - + + Source Files + - + + Resource Files + \ No newline at end of file diff --git a/ScreensaverNotify32/ScreensaverNotify32.vcxproj.filters b/ScreensaverNotify32/ScreensaverNotify32.vcxproj.filters index 91df9d2..92452b8 100644 --- a/ScreensaverNotify32/ScreensaverNotify32.vcxproj.filters +++ b/ScreensaverNotify32/ScreensaverNotify32.vcxproj.filters @@ -5,6 +5,9 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + {240fe0a1-842e-48f1-bd9d-126731782b14} + @@ -15,9 +18,13 @@ Source Files - + + Source Files + - + + Resource Files + \ No newline at end of file diff --git a/ScreensaverProxy32/ScreensaverProxy32.vcxproj.filters b/ScreensaverProxy32/ScreensaverProxy32.vcxproj.filters index ca5a44a..3dbf6ae 100644 --- a/ScreensaverProxy32/ScreensaverProxy32.vcxproj.filters +++ b/ScreensaverProxy32/ScreensaverProxy32.vcxproj.filters @@ -5,6 +5,9 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + {256e848e-f08e-4891-a6d2-e72679385047} + @@ -18,9 +21,13 @@ Source Files - + + Source Files + - + + Resource Files + \ No newline at end of file diff --git a/WinMute/ScreensaverNotifier.cpp b/WinMute/ScreensaverNotifier.cpp index 0a11a81..1bfad0c 100644 --- a/WinMute/ScreensaverNotifier.cpp +++ b/WinMute/ScreensaverNotifier.cpp @@ -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; diff --git a/WinMute/ScreensaverNotifier.h b/WinMute/ScreensaverNotifier.h index ca8ec0e..6d1ebaf 100644 --- a/WinMute/ScreensaverNotifier.h +++ b/WinMute/ScreensaverNotifier.h @@ -71,7 +71,7 @@ private: RegisterHook regHook_; UnregisterHook unregHook_; - void StartScreensaverPollTimer(bool start = true); + void StartScreensaverPollTimer(bool start); bool IsScreensaverRunning(); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index c5c0f19..ccf9139 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -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: