-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sdl_joypad: fix hotplug, order ports #13527
Conversation
Is there a particular reason this PR has sat dormant? Hotplugging does not work on Steam Deck. Emudeck configures SDL as the gamepad backend because the normal user doesn't have the permissions necessary for the udev backend to work. This seems like a particularly relevant fix for Deck. |
@sonninnos @LibretroAdmin @Myaats Any thoughts? (including Mats due to Steam/Deck angle) |
@@ -55,10 +56,10 @@ static const char *sdl_joypad_name(unsigned pad) | |||
|
|||
#ifdef HAVE_SDL2 | |||
if (sdl_pads[pad].controller) | |||
return SDL_GameControllerNameForIndex(pad); | |||
return SDL_JoystickNameForIndex(pad); | |||
return SDL_GameControllerNameForIndex(sdl_pads[pad].sdl_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really needed, but we could likely use SDL_GameControllerName here.
return SDL_GameControllerNameForIndex(sdl_pads[pad].sdl_id); | |
return SDL_GameControllerName(sdl_pads[pad].controller); |
@@ -447,10 +475,20 @@ static void sdl_joypad_poll(void) | |||
switch (event.type) | |||
{ | |||
case SDL_JOYDEVICEADDED: | |||
RARCH_WARN("[SDL_JOYPAD] hotplug added: %d\n", event.jdevice.which); | |||
sdl_pad_connect(event.jdevice.which); | |||
break; | |||
case SDL_JOYDEVICEREMOVED: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider implementing SDL_ControllerDeviceEvents SDL_CONTROLLERDEVICEADDED
and SDL_CONTROLLERDEVICEREMOVED
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a solid change and clean up to SDL's gamepad control system.
Most of those loggings don't really seem like "warnings" but rather regular "info".. |
Thanks for the review, @RobLoach. I would love to see this merged in time for the next release. |
|
||
for (int i = 0; i < MAX_USERS; i++) { | ||
if (sdl_pads[i].joypad != NULL && sdl_pads[i].sdl_id == id) { | ||
RARCH_WARN("[SDL_JOYPAD]: %d already registered on port %d\n", id, i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD]: %d already registered on port %d\n", id, i); | |
RARCH_LOG("[SDL_JOYPAD]: %d already registered on port %d\n", id, i); |
|
||
for (int i = 0; i < MAX_USERS; i++) { | ||
if (sdl_pads[i].joypad == NULL) { | ||
RARCH_WARN("[SDL_JOYPAD]: using port: %d\n", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD]: using port: %d\n", i); | |
RARCH_LOG("[SDL_JOYPAD]: using port: %d\n", i); |
@@ -104,6 +123,7 @@ static void sdl_pad_connect(unsigned id) | |||
|
|||
if (SDL_IsGameController(id)) | |||
{ | |||
RARCH_WARN("[SDL_JOYSTICK]: opening #%d as GameController\n", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYSTICK]: opening #%d as GameController\n", id); | |
RARCH_LOG("[SDL_JOYSTICK]: opening #%d as GameController\n", id); |
@@ -112,6 +132,7 @@ static void sdl_pad_connect(unsigned id) | |||
else | |||
#endif | |||
{ | |||
RARCH_WARN("[SDL_JOYSTICK]: opening #%d as Joystick\n", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYSTICK]: opening #%d as Joystick\n", id); | |
RARCH_LOG("[SDL_JOYSTICK]: opening #%d as Joystick\n", id); |
RARCH_WARN("[SDL_JOYPAD]: Ignoring pad #%d (vendor: %d; product: %d)\n", id, vendor, product); | ||
if (pad->joypad) | ||
SDL_JoystickClose(pad->joypad); | ||
RARCH_WARN("[SDL_JOYPAD]: Ignoring pad #%d (vendor: %04x; product: %04x)\n", id, vendor, product); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD]: Ignoring pad #%d (vendor: %04x; product: %04x)\n", id, vendor, product); | |
RARCH_LOG("[SDL_JOYPAD]: Ignoring pad #%d (vendor: %04x; product: %04x)\n", id, vendor, product); |
return; | ||
} | ||
#endif | ||
#endif | ||
|
||
pad->sdl_id = id; | ||
|
||
RARCH_WARN("[SDL_JOYPAD]: registering %d as port %d\n", id, port_num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD]: registering %d as port %d\n", id, port_num); | |
RARCH_LOG("[SDL_JOYPAD]: registering %d as port %d\n", id, port_num); |
@@ -447,10 +475,20 @@ static void sdl_joypad_poll(void) | |||
switch (event.type) | |||
{ | |||
case SDL_JOYDEVICEADDED: | |||
RARCH_WARN("[SDL_JOYPAD] hotplug added: %d\n", event.jdevice.which); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD] hotplug added: %d\n", event.jdevice.which); | |
RARCH_LOG("[SDL_JOYPAD] hotplug added: %d\n", event.jdevice.which); |
sdl_pad_connect(event.jdevice.which); | ||
break; | ||
case SDL_JOYDEVICEREMOVED: | ||
sdl_pad_disconnect(event.jdevice.which); | ||
RARCH_WARN("[SDL_JOYPAD] hotplug removed: %d\n", event.jdevice.which); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("[SDL_JOYPAD] hotplug removed: %d\n", event.jdevice.which); | |
RARCH_LOG("[SDL_JOYPAD] hotplug removed: %d\n", event.jdevice.which); |
|
||
for (int i = 0 ; i < MAX_USERS ; i++) { | ||
if (SDL_JoystickInstanceID(sdl_pads[i].joypad) == event.jdevice.which) { | ||
RARCH_WARN("Found joystick: %d\n", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RARCH_WARN("Found joystick: %d\n", i); | |
RARCH_LOG("[SDL_JOYPAD] Found joystick: %d\n", i); |
@Informatic If you can resolve latest suggested changes. Thank you. |
The changes represented here have been brought into #16941 . |
Description
Minor SDL joypad handling cleanup.
With joypad ignoring code used on webOS we were ending up with joypads registered at port 3+ on certain platforms. This also broke input port device index rebinding (Device Index list was always empty, even for devices on port 3+ which were working properly otherwise; not sure if missing reported devices is a violation of input device reporting API, or it's just a bug there)
This now properly attempts to store joypads continuously, by indexing them based on port number in an internal joypads state array.
Additionally, this fixes hotplug/unplug detection on SDL2.
event.jdevice.which
on unplug contains a Joystick Instance ID (monotonously increasing on every device connected/disconnected device), not Joystick Index used on open, thus a list of opened joysticks needs to be walked through and compared to received ID. Unplug detection would break after second replug before.Note: this has not been tested outside of webOS, especially on SDL1.
Related Issues
[Any issues this pull request may be addressing]
Related Pull Requests
[Any other PRs from related repositories that might be needed for this pull request to work]
Reviewers
[If possible @mention all the people that should review your pull request]