diff --git a/.vscode/settings.json b/.vscode/settings.json index 1fdc2bf309..e90ca77e4a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,4 +9,9 @@ "editor.tabSize": 3, "editor.renderWhitespace": "all", "editor.insertSpaces": true, + "files.associations": { + "frontend_driver.h": "c", + "*.in": "c", + "*.rh": "c" + }, } \ No newline at end of file diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index b4d13a401b..dfb384d824 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -22,6 +22,7 @@ #include "win32_common.h" #include "gdi_common.h" +#include "dbt.h" #include "../../frontend/frontend_driver.h" #include "../../configuration.h" #include "../../verbosity.h" @@ -69,6 +70,9 @@ #define DragQueryFileR DragQueryFileW #endif +const GUID GUID_DEVINTERFACE_HID = { 0x4d1e55b2, 0xf16f, 0x11Cf, { 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } }; +HDEVNOTIFY notification_handler; + extern LRESULT win32_menu_loop(HWND owner, WPARAM wparam); #if defined(HAVE_D3D9) || defined(HAVE_D3D8) @@ -759,6 +763,16 @@ bool win32_window_create(void *data, unsigned style, if (!main_window.hwnd) return false; + DEV_BROADCAST_DEVICEINTERFACE notification_filter; + ZeroMemory( ¬ification_filter, sizeof(notification_filter) ); + notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); + notification_filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; + notification_filter.dbcc_classguid = GUID_DEVINTERFACE_HID; + notification_handler = RegisterDeviceNotification(main_window.hwnd, ¬ification_filter, DEVICE_NOTIFY_WINDOW_HANDLE); + + if (notification_handler) + RARCH_ERR("Error registering for notifications\n"); + video_driver_display_type_set(RARCH_DISPLAY_WIN32); video_driver_display_set(0); video_driver_window_set((uintptr_t)main_window.hwnd); @@ -1145,6 +1159,7 @@ void win32_destroy_window(void) #ifndef _XBOX UnregisterClass("RetroArch", GetModuleHandle(NULL)); #endif + UnregisterDeviceNotification(notification_handler); main_window.hwnd = NULL; } diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 95947e6366..1c6518bd05 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -21,8 +21,6 @@ #undef DIRECTINPUT_VERSION #define DIRECTINPUT_VERSION 0x0800 -#define DBT_DEVNODES_CHANGED 0x0007 - #ifndef WM_MOUSEHWHEEL #define WM_MOUSEHWHEEL 0x20e #endif @@ -32,6 +30,7 @@ #endif #include +#include #include #include @@ -804,11 +803,17 @@ bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lPa return true; } case WM_DEVICECHANGE: - if (wParam == DBT_DEVNODES_CHANGED) + if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { - if (di->joypad) - di->joypad->destroy(); - di->joypad = input_joypad_init_driver(di->joypad_driver_name, di); + PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam; + if( pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + { + PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr; + /* To-Do: Don't destroy everything, lets just handle new devices gracefully */ + if (di->joypad) + di->joypad->destroy(); + di->joypad = input_joypad_init_driver(di->joypad_driver_name, di); + } } break; case WM_MOUSEWHEEL: