mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Fixed potential deadlocks during WM_ACTIVATEAPP
This commit is contained in:
parent
7785133d02
commit
cd674d54c8
@ -1,3 +1,5 @@
|
|||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include <ddraw.h>
|
#include <ddraw.h>
|
||||||
|
|
||||||
#include "Common/Hook.h"
|
#include "Common/Hook.h"
|
||||||
@ -12,6 +14,8 @@ namespace
|
|||||||
{
|
{
|
||||||
Win32::FontSmoothing::SystemSettings g_fontSmoothingSettings = {};
|
Win32::FontSmoothing::SystemSettings g_fontSmoothingSettings = {};
|
||||||
WNDPROC g_origDdWndProc = nullptr;
|
WNDPROC g_origDdWndProc = nullptr;
|
||||||
|
std::atomic<DWORD> g_activateAppThreadId = 0;
|
||||||
|
HWND g_delayedFocusWnd = nullptr;
|
||||||
|
|
||||||
void activateApp()
|
void activateApp()
|
||||||
{
|
{
|
||||||
@ -43,7 +47,16 @@ namespace
|
|||||||
{
|
{
|
||||||
deactivateApp();
|
deactivateApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_activateAppThreadId = GetCurrentThreadId();
|
||||||
|
g_delayedFocusWnd = nullptr;
|
||||||
LRESULT result = g_origDdWndProc(hwnd, uMsg, wParam, lParam);
|
LRESULT result = g_origDdWndProc(hwnd, uMsg, wParam, lParam);
|
||||||
|
g_activateAppThreadId = 0;
|
||||||
|
if (g_delayedFocusWnd)
|
||||||
|
{
|
||||||
|
CALL_ORIG_FUNC(SetFocus)(g_delayedFocusWnd);
|
||||||
|
}
|
||||||
|
|
||||||
isDisplayChangeNotificationEnabled = true;
|
isDisplayChangeNotificationEnabled = true;
|
||||||
DDraw::RealPrimarySurface::enableUpdates();
|
DDraw::RealPrimarySurface::enableUpdates();
|
||||||
return LOG_RESULT(result);
|
return LOG_RESULT(result);
|
||||||
@ -62,12 +75,39 @@ namespace
|
|||||||
|
|
||||||
return LOG_RESULT(g_origDdWndProc(hwnd, uMsg, wParam, lParam));
|
return LOG_RESULT(g_origDdWndProc(hwnd, uMsg, wParam, lParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HWND WINAPI setFocus(HWND hWnd)
|
||||||
|
{
|
||||||
|
if (GetCurrentThreadId() == g_activateAppThreadId && IsWindow(hWnd))
|
||||||
|
{
|
||||||
|
g_delayedFocusWnd = hWnd;
|
||||||
|
return GetFocus();
|
||||||
|
}
|
||||||
|
return CALL_ORIG_FUNC(SetFocus)(hWnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL WINAPI showWindow(HWND hWnd, int nCmdShow)
|
||||||
|
{
|
||||||
|
if (GetCurrentThreadId() == g_activateAppThreadId && IsWindow(hWnd))
|
||||||
|
{
|
||||||
|
BOOL result = IsWindowVisible(hWnd);
|
||||||
|
ShowWindowAsync(hWnd, nCmdShow);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return CALL_ORIG_FUNC(ShowWindow)(hWnd, nCmdShow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DDraw
|
namespace DDraw
|
||||||
{
|
{
|
||||||
namespace ActivateAppHandler
|
namespace ActivateAppHandler
|
||||||
{
|
{
|
||||||
|
void installHooks()
|
||||||
|
{
|
||||||
|
HOOK_FUNCTION(user32, SetFocus, setFocus);
|
||||||
|
HOOK_FUNCTION(user32, ShowWindow, showWindow);
|
||||||
|
}
|
||||||
|
|
||||||
void setCooperativeLevel(HWND hwnd, DWORD flags)
|
void setCooperativeLevel(HWND hwnd, DWORD flags)
|
||||||
{
|
{
|
||||||
static bool isDdWndProcHooked = false;
|
static bool isDdWndProcHooked = false;
|
||||||
|
@ -8,6 +8,7 @@ namespace DDraw
|
|||||||
{
|
{
|
||||||
namespace ActivateAppHandler
|
namespace ActivateAppHandler
|
||||||
{
|
{
|
||||||
|
void installHooks();
|
||||||
void setCooperativeLevel(HWND hwnd, DWORD flags);
|
void setCooperativeLevel(HWND hwnd, DWORD flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ namespace DDraw
|
|||||||
void installHooks()
|
void installHooks()
|
||||||
{
|
{
|
||||||
RealPrimarySurface::init();
|
RealPrimarySurface::init();
|
||||||
|
ActivateAppHandler::installHooks();
|
||||||
|
|
||||||
Win32::Registry::unsetValue(
|
Win32::Registry::unsetValue(
|
||||||
HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectDraw", "EmulationOnly");
|
HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectDraw", "EmulationOnly");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user