Skip to content

Commit

Permalink
Use the first available joystick with Axes/Buttons for GUI control, i…
Browse files Browse the repository at this point in the history
…nstead of Joystick 0 always
  • Loading branch information
midwan committed Dec 9, 2019
1 parent c40fad4 commit 269afdd
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/osdep/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void checkInput()
break;
}
}
}
}
break;

case SDL_KEYDOWN:
Expand Down Expand Up @@ -778,18 +778,24 @@ void checkInput()

void amiberry_gui_run()
{
if (gui_joystick_control && SDL_NumJoysticks() > 0)
if (gui_joystick_control)
{
gui_joystick = SDL_JoystickOpen(0);
// Some joysticks have no axes or buttons (e.g. Wii Remote IR), skip those
if (SDL_JoystickNumAxes(gui_joystick) > 0 && SDL_JoystickNumButtons(gui_joystick) > 0)
{
joypad_axis_state.assign(SDL_JoystickNumAxes(gui_joystick), 0);
}
else
const auto available_joysticks = SDL_NumJoysticks();
if (available_joysticks > 0)
{
SDL_JoystickClose(gui_joystick);
gui_joystick = nullptr;
for (auto j = 0; j <= available_joysticks; j++)
{
gui_joystick = SDL_JoystickOpen(j);
// Some joysticks have no axes or buttons (e.g. Wii Remote IR), skip those
if (SDL_JoystickNumAxes(gui_joystick) > 0 && SDL_JoystickNumButtons(gui_joystick) > 0)
{
joypad_axis_state.assign(SDL_JoystickNumAxes(gui_joystick), 0);
break;
}

SDL_JoystickClose(gui_joystick);
gui_joystick = nullptr;
}
}
}

Expand Down

0 comments on commit 269afdd

Please sign in to comment.