-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add vertical mode for Nintendo Joy-Con #6303
Conversation
* Added support for vertical mode for Joy-Con controllers * Added the hint SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS for switching to this mode * Added support for SL/SR buttons in combined/vertical mode and L/ZL/R/ZR buttons in mini-gamepad mode
src/joystick/SDL_gamecontroller.c
Outdated
@@ -607,7 +607,7 @@ static ControllerMapping_t *SDL_CreateMappingForHIDAPIController(SDL_JoystickGUI | |||
break; | |||
default: | |||
/* Mini gamepad mode */ | |||
SDL_strlcat(mapping_string, "a:b0,b:b1,guide:b5,leftshoulder:b9,leftstick:b7,leftx:a0,lefty:a1,rightshoulder:b10,start:b6,x:b2,y:b3,", sizeof(mapping_string)); | |||
SDL_strlcat(mapping_string, "a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,misc1:b15,leftshoulder:b16,rightshoulder:b17,leftshoulder:b18,rightshoulder:b19,", sizeof(mapping_string)); |
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.
We shouldn't have entries in the map that aren't active. The mapping should probably depend on the value of the hint, and we should have some way of updating it if the hint changes.
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.
We shouldn't have entries in the map that aren't active. The mapping should probably depend on the value of the hint, and we should have some way of updating it if the hint changes.
It seems not easy to update the mapping when the hint changes. I use SDL_CreateMappingForHIDAPIController and SDL_PrivateLoadButtonMapping to update the mapping, and it works in my test. I'm not sure whether this is a proper way. Any suggestion?
src/joystick/SDL_gamecontroller.c
Outdated
|
||
Uint16 vendor; | ||
Uint16 product; | ||
for (SDL_GameController *controller = SDL_gamecontrollers; controller; controller = controller->next) { |
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.
Please lose this C99'ism (that for loop initial declaration)
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.
This would work, but isn't thread-safe and would override any custom controller mapping. For now let's remove this code and say this hint is only read at initialization and call it good.
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.
This would work, but isn't thread-safe and would override any custom controller mapping. For now let's remove this code and say this hint is only read at initialization and call it good.
Updating of the mapping has been removed.
I added a couple more commits moving the additional controls to the paddles as mapped positionally for the Xbox Elite controller and Steam Controller |
* Added support for vertical mode for Joy-Con controllers * Added the hint SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS for switching to this mode * Added support for SL/SR buttons in combined/vertical mode and L/ZL/R/ZR buttons in mini-gamepad mode
Description
For now, joy-cons are in mini-gamepad mode when a single joy-con is connected, or a pair of joy-cons are connected with the combine hint disabled (SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS = 0). In the mini-gamepad mode (also called the horizontal mode), left stick and a/b/x/y are targeted for either Joy-Con(L) or Joy-Con(R). However, in practice, there is demand for a vertical mode of joy-cons (e.g., playing Just Dance in yuzu emulator by a single player), which is not supported now. In the vertical mode, each joy-con should work as a half part of a standard controller, similar to the combine mode: left stick and dpup/dpdown/dpleft/dpright are targeted for Joy-Con(L), while right stick and a/b/x/y are targeted for Joy-Con(R).
This pull request provides a new hint (SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS) for switching to this mode. When it is enabled, the mini-gamepad mode is replaced by the vertical mode. There are two differences between the combine mode and the vertical mode: 1) When there is only one single joy-con connected, the combine mode is unavailable, while the vertical mode is available. 2) When there are a pair of joy-cons connected, the combine mode regards them as one controller, while the vertical mode (with combine hint disabled) regards them as two controllers.
Besides, as discussed in #6095, L/ZL/R/ZR are not in used in mini-gamepad mode, as same as SL/SR in combine mode. This pull request adds support for them. The mapping chains are:
The mapping from aX/bX to Xshoulder/Xtrigger can be customized by gamecontrollerdb.txt or SDL_HINT_GAMECONTROLLERCONFIG.
@slouken @TellowKrinkle