Skip to content

Commit

Permalink
Generate SDL_CONTROLLERDEVICEADDED events for controllers connected a…
Browse files Browse the repository at this point in the history
…t startup
  • Loading branch information
slouken committed Dec 23, 2013
1 parent 7469283 commit 03aece5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -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++;
Expand All @@ -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);
}

Expand Down

0 comments on commit 03aece5

Please sign in to comment.