only reinit when HID devices are attached

This commit is contained in:
radius 2017-12-27 15:34:18 -05:00
parent 61b7b2e590
commit c3e6ac96aa
3 changed files with 31 additions and 6 deletions

View File

@ -9,4 +9,9 @@
"editor.tabSize": 3, "editor.tabSize": 3,
"editor.renderWhitespace": "all", "editor.renderWhitespace": "all",
"editor.insertSpaces": true, "editor.insertSpaces": true,
"files.associations": {
"frontend_driver.h": "c",
"*.in": "c",
"*.rh": "c"
},
} }

View File

@ -22,6 +22,7 @@
#include "win32_common.h" #include "win32_common.h"
#include "gdi_common.h" #include "gdi_common.h"
#include "dbt.h"
#include "../../frontend/frontend_driver.h" #include "../../frontend/frontend_driver.h"
#include "../../configuration.h" #include "../../configuration.h"
#include "../../verbosity.h" #include "../../verbosity.h"
@ -69,6 +70,9 @@
#define DragQueryFileR DragQueryFileW #define DragQueryFileR DragQueryFileW
#endif #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); extern LRESULT win32_menu_loop(HWND owner, WPARAM wparam);
#if defined(HAVE_D3D9) || defined(HAVE_D3D8) #if defined(HAVE_D3D9) || defined(HAVE_D3D8)
@ -759,6 +763,16 @@ bool win32_window_create(void *data, unsigned style,
if (!main_window.hwnd) if (!main_window.hwnd)
return false; return false;
DEV_BROADCAST_DEVICEINTERFACE notification_filter;
ZeroMemory( &notification_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, &notification_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_type_set(RARCH_DISPLAY_WIN32);
video_driver_display_set(0); video_driver_display_set(0);
video_driver_window_set((uintptr_t)main_window.hwnd); video_driver_window_set((uintptr_t)main_window.hwnd);
@ -1145,6 +1159,7 @@ void win32_destroy_window(void)
#ifndef _XBOX #ifndef _XBOX
UnregisterClass("RetroArch", GetModuleHandle(NULL)); UnregisterClass("RetroArch", GetModuleHandle(NULL));
#endif #endif
UnregisterDeviceNotification(notification_handler);
main_window.hwnd = NULL; main_window.hwnd = NULL;
} }

View File

@ -21,8 +21,6 @@
#undef DIRECTINPUT_VERSION #undef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x0800 #define DIRECTINPUT_VERSION 0x0800
#define DBT_DEVNODES_CHANGED 0x0007
#ifndef WM_MOUSEHWHEEL #ifndef WM_MOUSEHWHEEL
#define WM_MOUSEHWHEEL 0x20e #define WM_MOUSEHWHEEL 0x20e
#endif #endif
@ -32,6 +30,7 @@
#endif #endif
#include <dinput.h> #include <dinput.h>
#include <dbt.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
@ -804,11 +803,17 @@ bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lPa
return true; return true;
} }
case WM_DEVICECHANGE: case WM_DEVICECHANGE:
if (wParam == DBT_DEVNODES_CHANGED) if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE)
{ {
if (di->joypad) PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
di->joypad->destroy(); if( pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
di->joypad = input_joypad_init_driver(di->joypad_driver_name, di); {
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; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL: