We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5523

Summary: Xbox Series X controller detected wrong by HIDAPI in MacOS
Product: SDL Reporter: Brian Torres-Gil <bugzilla>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: cameron.gutman
Version: 2.0.14   
Hardware: x86   
OS: macOS 10.15   
Attachments: Test script to detect controller
Patch

Description Brian Torres-Gil 2021-01-31 19:38:24 UTC
Created attachment 4745 [details]
Test script to detect controller

The new Xbox Series X Controller (aka Xbox Core Controller) does not work in SDL2 2.0.14. It does work in 2.0.12 but without haptics.

This is the exact controller:
https://www.microsoft.com/en-us/p/xbox-wireless-controller/8XN59CRBSQGZ/JBFJ

Controller firmware is the current latest: 5.5.2641.0

I attached a test script (sdl2-joystick.c) to illustrate the problem.

Compile/run the script with SDL 2.0.12 you'll get this output. The controller will work (without haptics) in 2.0.12.

    030000005e040000130b000005050000 "Microsoft Xbox Wireless Controller 441622734CB8" axes:6 buttons:16 hats:1 balls:0

Compile/run the script with SDL 2.0.14 you'll get this output. The controller will not work in 2.0.14 (no inputs recognized).

    030000005e040000130b000005056800 "Xbox One Series X Controller" axes:6 buttons:15 hats:0 balls:0

If you run the script with 2.0.14 with SDL_JOYSTICK_HIDAPI=0, then you get the same output as 2.0.12 and the controller works. So it seems like HIDAPI has been enabled in 2.0.14 but is detecting the controller incorrectly. When HIDAPI is disabled then the 2.0.12 behavior is used and it works.
Comment 1 Sam Lantinga 2021-02-01 03:15:20 UTC
Does it work with the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

If not, what version of OS are you running on?
Comment 2 Brian Torres-Gil 2021-02-01 04:27:44 UTC
(In reply to Sam Lantinga from comment #1)
> Does it work with the latest SDL snapshot?
> http://www.libsdl.org/tmp/SDL-2.0.zip
> 
> If not, what version of OS are you running on?

Hi Sam, thanks for the quick reply.

I just tested with the .zip file you provided. I used my test script and also jstest-sdl. (https://github.com/meleu/jstest-sdl)

First, I compiled the SDL2 library in the .zip with ./configure and make.

Next, I compiled and linked the test scripts against 2.0.14 and confirmed the issue is there as usual.

Then, I compiled and linked these scripts the same way against the 2.0.15-14845 version in the .zip file and confirmed the same behavior is unchanged from 2.0.14.

The main test where the issue is visible is `jstest-sdl -e 0` which prints all events from the controller. Other controllers produce events, but this controller doesn't produce any unless SDL_JOYSTICK_HIDAPI=0 is set.

Let me know if I can collect any other info for you.
Comment 3 Brian Torres-Gil 2021-02-01 04:34:15 UTC
I'm running MacOS 10.15.7 (19H2) on a MacBook Pro 2019.
Comment 4 Cameron Gutman 2021-02-02 16:17:03 UTC
I can also reproduce this on an Intel MacBook Pro 13" 2020 running macOS 11.1.

SDL recognizes the controller but no input is ever received from it as long as HIDAPI is enabled. With HIDAPI disabled, it works fine (except rumble, of course).
Comment 5 Sam Lantinga 2021-02-02 21:16:05 UTC
Can you guys debug this? I'm not seeing Xbox controllers show up at all on my Mac Pro running 10.15.7.
Comment 6 Cameron Gutman 2021-02-04 00:07:18 UTC
Created attachment 4757 [details]
Patch

This issue was that the IsBluetoothXboxOneController() function in SDL_hidapi_xbox360.c was missing the addition of USB_PRODUCT_XBOX_ONE_SERIES_X_BLUETOOTH which was present in the SDL_hidapi_xboxone.c version of the same function.

It was only broken on macOS because macOS has the special codepath for wired Xbox One controllers to be handled by SDL_hidapi_xbox360 (for 360Controller).

I moved the correct version of that function to a central location where both SDL_hidapi_xboxone.c and SDL_hidapi_xbox360.c can use it, so this mismatch won't happen again.
Comment 7 Brian Torres-Gil 2021-02-04 19:13:23 UTC
I applied Cameron's patch to the SDL-2.0.zip file provided earlier and tested again with jstest-sdl. I'm now getting events when the buttons are pushed! So the fix is verified.

Thank you very much for the attention to this issue. I'm very grateful.
Comment 8 Sam Lantinga 2021-02-04 20:06:34 UTC
Looks good, thanks!
https://hg.libsdl.org/SDL/rev/540762271974