mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Fixed a potential deadlock in resetMouseHook
Fixes a sporadic deadlock when alt-tabbing in Star Trek: Armada with the config overlay open.
This commit is contained in:
parent
ec686bfb69
commit
a442239ac1
@ -20,6 +20,7 @@
|
||||
namespace
|
||||
{
|
||||
const UINT WM_USER_EXECUTE = WM_USER;
|
||||
const UINT WM_USER_EXECUTE_ASYNC = WM_USER + 1;
|
||||
|
||||
struct EnumWindowsArgs
|
||||
{
|
||||
@ -185,6 +186,12 @@ namespace
|
||||
func();
|
||||
return 0;
|
||||
}
|
||||
if (WM_USER_EXECUTE_ASYNC == uMsg)
|
||||
{
|
||||
auto func = reinterpret_cast<void(*)()>(lParam);
|
||||
func();
|
||||
return 0;
|
||||
}
|
||||
return CALL_ORIG_FUNC(DefWindowProc)(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
@ -277,6 +284,11 @@ namespace Gdi
|
||||
PostMessage(hwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
void executeAsyncFunc(void(*func)())
|
||||
{
|
||||
PostMessage(g_messageWindow, WM_USER_EXECUTE_ASYNC, 0, reinterpret_cast<LPARAM>(func));
|
||||
}
|
||||
|
||||
void executeFunc(const std::function<void()>& func)
|
||||
{
|
||||
DWORD_PTR result = 0;
|
||||
|
@ -27,6 +27,7 @@ namespace Gdi
|
||||
|
||||
template <typename Func>
|
||||
void execute(const Func& func) { executeFunc(std::cref(func)); }
|
||||
void executeAsyncFunc(void(*func)());
|
||||
void executeFunc(const std::function<void()>& func);
|
||||
|
||||
bool isGuiThreadWindow(HWND hwnd);
|
||||
|
@ -268,33 +268,35 @@ namespace
|
||||
});
|
||||
}
|
||||
|
||||
void resetMouseHookFunc()
|
||||
{
|
||||
if (g_mouseHook)
|
||||
{
|
||||
UnhookWindowsHookEx(g_mouseHook);
|
||||
}
|
||||
|
||||
g_origCursorPos = { MAXLONG, MAXLONG };
|
||||
g_mouseHook = CALL_ORIG_FUNC(SetWindowsHookExA)(
|
||||
WH_MOUSE_LL, &lowLevelMouseProc, Dll::g_origDDrawModule, 0);
|
||||
|
||||
if (g_mouseHook)
|
||||
{
|
||||
INPUT inputs[2] = {};
|
||||
inputs[0].mi.dy = 1;
|
||||
inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE;
|
||||
inputs[1].mi.dx = 1;
|
||||
inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE;
|
||||
SendInput(2, inputs, sizeof(INPUT));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ONCE("ERROR: Failed to install low level mouse hook, error code: " << GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void resetMouseHook()
|
||||
{
|
||||
Gdi::GuiThread::execute([]()
|
||||
{
|
||||
if (g_mouseHook)
|
||||
{
|
||||
UnhookWindowsHookEx(g_mouseHook);
|
||||
}
|
||||
|
||||
g_origCursorPos = { MAXLONG, MAXLONG };
|
||||
g_mouseHook = CALL_ORIG_FUNC(SetWindowsHookExA)(
|
||||
WH_MOUSE_LL, &lowLevelMouseProc, Dll::g_origDDrawModule, 0);
|
||||
|
||||
if (g_mouseHook)
|
||||
{
|
||||
INPUT inputs[2] = {};
|
||||
inputs[0].mi.dy = 1;
|
||||
inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE;
|
||||
inputs[1].mi.dx = 1;
|
||||
inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE;
|
||||
SendInput(2, inputs, sizeof(INPUT));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ONCE("ERROR: Failed to install low level mouse hook, error code: " << GetLastError());
|
||||
}
|
||||
});
|
||||
Gdi::GuiThread::executeAsyncFunc(resetMouseHookFunc);
|
||||
}
|
||||
|
||||
BOOL WINAPI setCursorPos(int X, int Y)
|
||||
|
Loading…
x
Reference in New Issue
Block a user