onepad: add hot-plugging support

Note: pad to player mapping is done later

v2: remove the useless print
This commit is contained in:
Gregory Hainaut 2017-04-12 20:11:16 +02:00
parent 1b369520ed
commit c183de5662
2 changed files with 17 additions and 0 deletions

View File

@ -47,6 +47,8 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
SDL_JoystickEventState(SDL_QUERY);
SDL_GameControllerEventState(SDL_QUERY);
SDL_EventState(SDL_CONTROLLERDEVICEADDED, SDL_ENABLE);
SDL_EventState(SDL_CONTROLLERDEVICEREMOVED, SDL_ENABLE);
{ // Support as much Joystick as possible
GBytes *bytes = g_resource_lookup_data(onepad_res_get_resource(), "/onepad/res/game_controller_db.txt", G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr);

View File

@ -341,6 +341,21 @@ PADpoll(u8 value)
EXPORT_C_(keyEvent *)
PADkeyEvent()
{
#ifdef SDL_BUILD
// Take the opportunity to handle hot plugging here
SDL_Event events;
while (SDL_PollEvent(&events)) {
switch (events.type) {
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
GamePad::EnumerateGamePads(s_vgamePad);
break;
default:
break;
}
}
#endif
s_event = event;
event.evt = 0;
event.key = 0;