Skip to content
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

Merged
merged 3 commits into from
Oct 2, 2022
Merged

Conversation

happyharryh
Copy link
Contributor

  • 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:

  • In mini-gamepad mode:
    • Joy-Con(L):
      • L -> b16 -> leftshoulder
      • ZL -> a4 -> lefttrigger
    • Joy-Con(R):
      • R -> b19 -> rightshoulder
      • ZR -> a5 -> righttrigger
  • In combine/vertical mode:
    • Joy-Con(L):
      • SL -> b16 -> leftshoulder
      • SR -> b17 -> rightshoulder
    • Joy-Con(R):
      • SL -> b18 -> leftshoulder
      • SR -> b19 -> rightshoulder

The mapping from aX/bX to Xshoulder/Xtrigger can be customized by gamecontrollerdb.txt or SDL_HINT_GAMECONTROLLERCONFIG.

@slouken @TellowKrinkle

* 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
@@ -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));
Copy link
Collaborator

@slouken slouken Sep 29, 2022

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.

Copy link
Contributor Author

@happyharryh happyharryh Oct 1, 2022

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?


Uint16 vendor;
Uint16 product;
for (SDL_GameController *controller = SDL_gamecontrollers; controller; controller = controller->next) {
Copy link
Contributor

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)

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@slouken slouken merged commit 6c8bf3a into libsdl-org:main Oct 2, 2022
@slouken
Copy link
Collaborator

slouken commented Oct 2, 2022

I added a couple more commits moving the additional controls to the paddles as mapped positionally for the Xbox Elite controller and Steam Controller

@happyharryh happyharryh deleted the main branch October 3, 2022 00:26
PJB3005 pushed a commit to PJB3005/SDL that referenced this pull request Oct 5, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants