From 2465b0e278e14ef36b92c96d838d814eb2f21869 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 24 Dec 2020 12:29:09 +0100 Subject: [PATCH] USB: Pass a top-level window to DirectInput Fixes Force Feedback not initializing properly --- pcsx2/PAD/Windows/PAD.cpp | 4 +--- pcsx2/USB/usb-pad/dx/dinput.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/pcsx2/PAD/Windows/PAD.cpp b/pcsx2/PAD/Windows/PAD.cpp index adf3cfa64a..d1962a876b 100644 --- a/pcsx2/PAD/Windows/PAD.cpp +++ b/pcsx2/PAD/Windows/PAD.cpp @@ -1077,9 +1077,7 @@ s32 PADopen(void* pDsp) "Non-PAD Error", MB_OK | MB_ICONERROR); return -1; } - hWndTop = hWnd; - while (GetWindowLong(hWndTop, GWL_STYLE) & WS_CHILD) - hWndTop = GetParent(hWndTop); + hWndTop = GetAncestor(hWnd, GA_ROOT); if (!hWndGSProc.SetWndHandle(hWnd)) { diff --git a/pcsx2/USB/usb-pad/dx/dinput.cpp b/pcsx2/USB/usb-pad/dx/dinput.cpp index b4a926f7d6..d2484fc7c8 100644 --- a/pcsx2/USB/usb-pad/dx/dinput.cpp +++ b/pcsx2/USB/usb-pad/dx/dinput.cpp @@ -46,7 +46,6 @@ namespace usb_pad static std::atomic refCount(0); static bool useRamp = false; - HWND hWin = NULL; DWORD pid = 0; DWORD old = 0; @@ -903,12 +902,6 @@ namespace usb_pad return NULL; } - void GetID(TCHAR* name) - { - hWin = ::FindWindow(name, NULL); - ::GetWindowThreadProcessId(hWin, &pid); - } - bool FindFFDevice(int port) { InputMapped im; @@ -942,6 +935,8 @@ namespace usb_pad //use direct input void InitDI(int port, const char* dev_type) { + HWND hWin = nullptr; + if (gsWnd) { hWin = gsWnd; @@ -955,7 +950,8 @@ namespace usb_pad } } - InitDirectInput(hWin, port); + // DirectInput needs a top-level window + InitDirectInput(GetAncestor(hWin, GA_ROOT), port); LoadDInputConfig(port, dev_type); FindFFDevice(port); }