From c88666580e4270901c3ee0400d5dcb813ef1d3b5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 15 Aug 2018 19:53:30 -0700 Subject: [PATCH] Catch device removal as well as device arrival on Windows --- src/joystick/hidapi/SDL_hidapijoystick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index b339ae8cb2b0d..016c089e22d0b 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -142,6 +142,7 @@ typedef struct _DEV_BROADCAST_DEVICEINTERFACE_A typedef struct _DEV_BROADCAST_HDR DEV_BROADCAST_HDR; #define DBT_DEVICEARRIVAL 0x8000 /* system detected a new device */ +#define DBT_DEVICEREMOVECOMPLETE 0x8004 /* device was removed from the system */ #define DBT_DEVTYP_DEVICEINTERFACE 0x00000005 /* device interface class */ #define DBT_DEVNODES_CHANGED 0x0007 #define DBT_CONFIGCHANGED 0x0018 @@ -157,12 +158,13 @@ static LRESULT CALLBACK ControllerWndProc(HWND hwnd, UINT message, WPARAM wParam case WM_DEVICECHANGE: switch (wParam) { case DBT_DEVICEARRIVAL: + case DBT_DEVICEREMOVECOMPLETE: if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE; } break; } - return 0; + return TRUE; } return DefWindowProc(hwnd, message, wParam, lParam);