diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index 6efb1a5aa0..04bb22f342 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -117,6 +117,11 @@ extern bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam); #endif +#if !defined(_XBOX) +extern bool winraw_handle_message(UINT message, + WPARAM wParam, LPARAM lParam); +#endif + typedef struct DISPLAYCONFIG_RATIONAL_CUSTOM { UINT32 Numerator; @@ -1033,7 +1038,6 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, case WM_POINTERDOWN: case WM_POINTERUP: case WM_POINTERUPDATE: - case WM_DEVICECHANGE: case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: case WM_NCLBUTTONDBLCLK: @@ -1072,6 +1076,12 @@ static LRESULT CALLBACK wnd_proc_common_internal(HWND hwnd, case WM_DISPLAYCHANGE: /* fix size after display mode switch when using SR */ win32_resize_after_display_change(hwnd); break; + case WM_DEVICECHANGE: +#if !defined(_XBOX) + if (winraw_handle_message(message, wparam, lparam)) + return 0; +#endif + break; } return DefWindowProc(hwnd, message, wparam, lparam); diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 69bb1a4c66..e7244c7121 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -21,6 +21,10 @@ extern "C" { #include +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ +#include +#endif + #ifdef CXX_BUILD } #endif @@ -931,6 +935,31 @@ static int16_t winraw_input_state( return 0; } +#if !defined(_XBOX) +bool winraw_handle_message(UINT message, + WPARAM wParam, LPARAM lParam) +{ + winraw_input_t *wr = (winraw_input_t*)(LONG_PTR) + GetWindowLongPtr(main_window.hwnd, GWLP_USERDATA); + + switch (message) + { + case WM_DEVICECHANGE: +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ + if (wParam == DBT_DEVICEARRIVAL || + wParam == DBT_DEVICEREMOVECOMPLETE) + { + PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam; + if (pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + joypad_driver_reinit(wr, NULL); + } +#endif + break; + } + return false; +} +#endif + static void winraw_free(void *data) { winraw_input_t *wr = (winraw_input_t*)data;