From 03aece5452a821798f7dd7fa455e786a2893b0b2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 23 Dec 2013 15:10:03 -0800 Subject: [PATCH] Generate SDL_CONTROLLERDEVICEADDED events for controllers connected at startup --- src/joystick/SDL_gamecontroller.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index edcf5e41eb276..6aa80cb7e21d1 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -866,8 +866,7 @@ SDL_GameControllerInit(void) const char *pMappingString = NULL; s_pSupportedControllers = NULL; pMappingString = s_ControllerMappings[i]; - while ( pMappingString ) - { + while ( pMappingString ) { SDL_GameControllerAddMapping( pMappingString ); i++; @@ -880,6 +879,16 @@ SDL_GameControllerInit(void) /* watch for joy events and fire controller ones if needed */ SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL ); + /* Send added events for controllers currently attached */ + for (i = 0; i < SDL_NumJoysticks(); ++i) { + if (SDL_IsGameController(i)) { + SDL_Event deviceevent; + deviceevent.type = SDL_CONTROLLERDEVICEADDED; + deviceevent.cdevice.which = i; + SDL_PushEvent(&deviceevent); + } + } + return (0); }