-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Change SDL2 backend to use controller events. #8329
Change SDL2 backend to use controller events. #8329
Conversation
--HG-- branch : backend-sdl2-gamecontroller-events-hg
--HG-- branch : backend-sdl2-gamecontroller-events-hg
…s directly, use events instead; removed ImGui_ImplSDL2_SetGamepadMode(). --HG-- branch : backend-sdl2-gamecontroller-events-hg
Your PR removes This PR also has undesirable behavior changes. In particular: Forcing everyone to manually handle |
How about a compromise, with a new mode, |
The opening and closing of gamepads is an SDL-exclusive concept. None of the other backends need to think about it in the first place so this isn't really relevant.
I'm not saying it's a huge burden to handle to handle those events, it's about breaking things that were already working all because...some dude had strong opinions about the way it worked before and it wasn't his preferred solution?
Again it's more about forcing change than forcing the actual code. Your app has unusual requirements, it's not unreasonable to say the burden for accommodating those unusual requirements should fall on you.* Either way, you don't need to maintain an array if you really don't want to. You can call Heck, you could probably even just toggle (*This isn't to say that Dear ImGui shouldn't handle this better. Maybe this situation exists on other platforms with soft keyboards and it's worth solving generally, but I don't think a general solution would look anything like yours.)
Controllers in SDL are reference-counted, the backend opening and closing them has no bearing on your controllers. If you're seeing crashes from this it's a bug in the SDL port you're using.
This would just make the implementation of the backend unnecessarily convoluted. |
Yes it seems like either of those solutions would work for you and be less intrusive. A possible third option is we implement |
…etGamepadMode()/ImGui_ImplSDL3_SetGamepadMode() with ImGui_ImplSDL2_GamepadMode_Manual/ImGui_ImplSDL3_GamepadMode_Manual and an empty array. (#8329)
I believe the underlying issue was that |
As suggested your PR also does too many other things, ones mentioned above, and swapping raw buttons on My understanding is that you can solve your stated problem by calling |
Daniel could you confirm that my assumption that you can fix your problem entirely with this is correct? |
I could "fix" the problem way before this PR, by just disabling gamepad navigation. If the current design is intentional, there's no reason to change it. |
Disabling keyboard navigation was indeed a possible workaround but it would still mean passing inputs that other key polling systems shouldn't see, so I suppose the new lower-level solution is better. Thanks for your help! |
This changes the SDL2 backend to use
SDL_CONTROLLER*
events instead of peeking into an array of controllers.ImGui_ImplSDL2_SetGamepadMode()
was removed.Explanation
Having the backend peek into the controller state from inside
ImGui_ImplSDL2_NewFrame()
(as opposed toImGui_ImplSDL2_ProcessEvent()
) was causing me trouble when using the on-screen keyboard on the Wii U. Currently, the SDL2 port does not handle the keyboard, so I have to manually feed it input events; and to avoid conflicts with ImGui, any event sent to the on-screen keyboard has to NOT be sent to ImGui, or it starts interpreting dpad up/down (as the user navigates through the keyboard keys) and touch events as an attempt to focus away from anInput*
widget. The logic I have to implement is:I can bypass
_ProcessEvent()
when the on-screen keyboard is visible, but that's pointless when the controllers are being read from within_NewFrame()
.Because controller events are now being handled in
_ProcessEvent()
, there's no use for a controller array to be kept around in the backend. Games/apps will open/close controllers as they're attached/detached, and manage it themselves, possibly wrapping them in C++ classes; so it's obnoxious having to keep an array of controllers just to feed to the SDL2 backend throughImGui_ImplSDL2_SetGamepadMode()
.I've updated most of the SDL2 examples, to open/close the controllers as they're attached/detached. I'll wait for your feedback before doing the same for the SDL3 backend and examples.