Simple, proper Joy-Con Support

Hi! I’d really like to see Joy-Cons supported properly. In controller_type.h we have this:

// We currently don't support using a pair of Switch Joy-Con's as a single
// controller and we don't want to support using them individually for the
// time being, so these should be disabled until one of the above is true

It seems to me that putting off proper Joy-Con support until there’s a way to combine controllers is putting the cart before the horse. If SDL had Joy-Con support but not controller-combining, a user who’s happy to do controller combining on their end can make good use of it. Many devs are already doing something like this in single-player games where the player accepts input from multiple devices (and kinds of devices) at once. And as long as users are able to query whether a given device is a Joy-Con (and whether it’s left or right), they can easily do any special-case handling they might need.

Joy-Cons communicate almost identically to the Switch Pro Controller, with essentially the only difference being the axes for the motion sensors (which can easily be fixed). It should be very easy to treat them as Pro Controllers with few exceptions (getting the controller name, re-arranging motion axes if and when Switch controllers support the Sensor functions).

Now I must acknowledge that I’m an SDL newbie, but my background is having created another controller reading tool specifically for PlayStation and Switch controllers and providing good support for their motion features (gyro in particular). SDL supports far more controllers than my library does, and this is one of very few holes that need to be plugged up for SDL to meet all the needs of my library’s users (which would be great!).

Of course, since Joy-Cons are already crudely supported in a different way (held sideways and with the sticks reporting as pov hats :grimacing:), for backwards compatibility reasons we can’t just change it. I’m not great at names, but I propose:

  • A hint to enable better Joy-Con support: SDL_SetHint(SDL_HINT_GAMECONTROLLER_HIDAPI_JOY_CONS, “1”);
  • A way to check if the controller is only partial (although SDL_GameControllerHasButton could do the trick, or checking the names, since for now there are really very few partial controllers out there)
  • Joy-Con motion axes re-orientated as if held in a pair. (It’s trivial for the user to re-arrange these again for single-Joy-Con sideways play, and consistency across devices is a very appealing feature of SDL).

I’ve created a patch that has something like this working. It’s attached to this bug report here:

It’s not complete, though. I’ve added a hint SDL_JOYSTICK_HIDAPI_JOY_CONS to opt in to having Joy-Cons detected and treated like Switch Pro Controllers are treated. This includes button and stick mappings, and gyro and accelerometer read with the sensor function.

I’ve made it opt-in since Joy-Cons are already supported in a more limited way that behaves differently – a single Joy-Con is mapped to be held on its side, and the stick reports as a d-pad. I don’t know if anyone’s relying on this behaviour, but my guess is it’s probably preferred that the default behaviour remains default.

In that case, I need help with this patch. This adds all the behaviour I was hoping for when SDL_JOYSTICK_HIDAPI_JOY_CONS is enabled, but when it’s disabled, I’m not getting the Joy-Cons at all.

The only change I can think of that could cause this is that I uncommented the lines:

{ MAKE_CONTROLLER_ID( 0x057e, 0x2006 ), k_eControllerType_SwitchJoyConLeft, NULL },    // Nintendo Switch Joy-Con (Left)
{ MAKE_CONTROLLER_ID( 0x057e, 0x2007 ), k_eControllerType_SwitchJoyConRight, NULL },   // Nintendo Switch Joy-Con (Right)

in controller_type.h. This is so I can detect them as HIDAPI devices. Then when these devices are detected and SDL_GetJoystickGameControllerType wants to figure out what to do with them, I have them return SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO when the new Joy-Con hint is enabled (Joy-Con specific logic is handled in SDL_hidapi_switch.c), but if the hint is not enabled I have them return SDL_CONTROLLER_TYPE_UNKNOWN. This was in the hopes they’d revert to their previous behaviour, but this hasn’t been the case with my tests.

Is someone able to help me with this? Or nip this in the bud if there’s no future for this proposed patch?