win32: do hotplugging detection 500ms after arrival/removal

This commit is contained in:
OV2 2018-04-22 20:19:09 +02:00
parent 47144176ff
commit f7c3117f5f
1 changed files with 15 additions and 7 deletions

View File

@ -297,7 +297,8 @@ void S9xDetectJoypads();
#define WM_CUSTKEYDOWN (WM_USER+50)
#define WM_CUSTKEYUP (WM_USER+51)
#define WM_SCANJOYPADS (WM_APP+10)
#define TIMER_SCANJOYPADS (99999)
#ifdef UNICODE
#define S9XW_SHARD_PATH SHARD_PATHW
@ -2682,11 +2683,18 @@ LRESULT CALLBACK WinProc(
break;
#endif
case WM_DEVICECHANGE:
if(wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE)
PostMessage(hWnd, WM_SCANJOYPADS, 0, 0);
if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
// trigger a joypad detect after 500ms - the multimedia functions do not like it if we trigger this right after arrival/removal
SetTimer(hWnd, TIMER_SCANJOYPADS, 500, NULL);
}
break;
case WM_SCANJOYPADS:
case WM_TIMER:
{
if (wParam == TIMER_SCANJOYPADS) {
S9xDetectJoypads();
KillTimer(hWnd, TIMER_SCANJOYPADS);
}
}
break;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);