Commit graph

192 commits

Author SHA1 Message Date
Dimitriy Ryazantcev
33843b0933 Use existing XUSB driver software PID 0x02a1 instead of PID 0x02fe
0x02fe is actually PID of Xbox Wireless Adapter for Windows 10 (Model 1790) and creates confusion.

Here is USB descriptor dump: https://github.com/DJm00n/ControllersInfo/blob/master/xboxone/DescriptorDump_Adapter%20(Xbox%20Wireless%20Adapter%20for%20Windows).txt

(cherry picked from commit c790572674)
2023-12-11 11:49:28 -08:00
Sam Lantinga
8d47e3bb82 Added support for the NACON Revolution 5 Pro controller
(cherry picked from commit f0e47f8ee0)
2023-11-27 12:12:25 -08:00
Sam Lantinga
4a0bd06d58 Added support for the GameSir-G7 Controller for Xbox
(cherry picked from commit 2e6c48dcb4)
2023-11-10 17:32:11 -08:00
Sylvain Becker
a14b948b6c
[SDL2] pointer boolean (#8523) 2023-11-10 06:30:56 -08:00
Sam Lantinga
1db0bd3fc0 Added support for the HP HyperX Clutch Gladiate controller
(cherry picked from commit f52b330ed8)
2023-10-25 09:01:46 -07:00
Cameron Gutman
4aab2342e9 Check for device disconnection in HIDAPI_JoystickOpen()
HIDAPI joystick drivers may call HIDAPI_JoystickDisconnected() in their
UpdateDevice() function during HIDAPI_JoystickOpen(). If they do this
today, the opened joystick will end up partially initialized (no name,
path, mapping GUID, etc.) because HIDAPI_GetDeviceByIndex() will no
longer be able to find the SDL_HIDAPI_Device for the removed joystick.

Worse still, joystick->hwdata->device becomes a dangling freed pointer
the next time HIDAPI_UpdateDeviceList() is called. This leads to a UAF
when the application or SDL calls SDL_JoystickClose() on this joystick.

Fix all this by checking if the device no longer has any associated
joysticks after calling UpdateDevice() and failing the open call if so.

(cherry picked from commit 435e7ce663)
2023-10-17 22:18:52 -05:00
Sam Lantinga
3a5abee512 Removed unused function
(cherry picked from commit 73927b0948)
2023-06-14 15:16:44 -07:00
Sam Lantinga
271e03f0d7 Added support for the PowerA Fusion Pro Wireless Controller in Bluetooth mode
This controller shows up with a VID/PID of 0, but has full functionality over Bluetooth

(cherry picked from commit cdfc0c5a33)
2023-06-14 15:12:56 -07:00
Sam Lantinga
30b4d90f1c Only update the serial number if it hasn't already been set
This fixes the serial number for Nintendo Switch Pro, which is queried from the hardware in device initialization, and was later clobbered by the USB string which isn't correct.

(cherry picked from commit 2042e9c4e3)
2023-06-09 17:36:06 -07:00
Sam Lantinga
3f1fd5abff Updated source to match SDL function prototype style 2023-05-23 10:59:03 -07:00
Sam Lantinga
e8ec8ba1d4 Added support for the Astro C40 in Xbox 360 mode
(cherry picked from commit a4b4dff4a2)
2023-05-19 14:23:57 -07:00
Sam Lantinga
7ec9a4385a More defensive coding against dangling device pointers
(cherry picked from commit acadb6f873)
2023-04-06 13:21:44 -07:00
Sam Lantinga
f6363fde9a Fixed crash if joystick->hwdata != NULL && device->driver == NULL
This should never happen, but we're seeing it in the wild, so make sure that we can never call into a NULL device driver.

(cherry picked from commit e13b74ccf0)
2023-04-05 11:24:55 -07:00
Ozkan Sezer
f633915443 fix build after commit 22685556e5. 2023-04-05 02:10:56 +03:00
Sam Lantinga
22685556e5 Don't probe for PlayStation controllers when we already know the controller type
Fixes https://github.com/libsdl-org/SDL/issues/7556

(cherry picked from commit 655a07bdd8)
2023-04-04 12:35:20 -07:00
Sam Lantinga
1e6ffc6294 Removed a duplicate delay accidentally added during code refactor
(cherry picked from commit 926db1bd54)
2023-03-09 16:13:19 -08:00
Sam Lantinga
c0fb092425 Fixed locking up the Logitech F310 with the PlayStation controller detection
(cherry picked from commit da134a3039)
2023-02-28 08:37:18 -08:00
Sam Lantinga
3dff5d3cbe Added support for the Turtle Beach REACT-R and Recon Xbox controllers
(cherry picked from commit 5fded632d6)
2023-02-21 11:29:45 -08:00
Sam Lantinga
e86f494317 Hold the joystick lock while opening the HID device on non-Android platforms
On Windows the main thread can be enumerating DirectInput devices while the Windows.Gaming.Input thread is calling back with a new controller available, and in this case HIDAPI_IsDevicePresent() returned false since the controller initialization hadn't completed yet, creating a duplicate controller.

Fixes https://github.com/libsdl-org/SDL/issues/7304

(cherry picked from commit ece8a7bb8e)
2023-02-16 09:53:33 -08:00
Sam Lantinga
2518e32de8 Dynamically update the serial number if it isn't available at first
This happens for Xbox One controllers using newer firmware connected over NDIS

(cherry picked from commit d1c72bb0bc)
2023-02-08 14:31:01 -08:00
Sam Lantinga
0479df53ca Updated copyright for 2023 2023-01-09 09:48:21 -08:00
Sam Lantinga
988866ca4a Fixed line wrapping for HID packet dump
(cherry picked from commit e85839cd56)
2023-01-03 15:14:00 -08:00
Sam Lantinga
2cb7a0a0bb Added support for the ThrustMaster eSwap PRO Controller Xbox
(cherry picked from commit dacdb1c310)
2023-01-03 15:13:50 -08:00
Sam Lantinga
d59caffe2c Added support for clang thread-safety analysis
The annotations have been added to SDL_mutex.h and have been made public so applications can enable this for their own code.

Clang assumes that locking and unlocking can't fail, but SDL has the concept of a NULL mutex, so the mutex functions have been changed not to report errors if a mutex hasn't been initialized. We do have mutexes that might be accessed when they are NULL, notably in the event system, so this is an important change.

This commit cleans up a bunch of rare race conditions in the joystick and game controller code so now everything should be completely protected by the joystick lock.

To test this, change the compiler to "clang -Wthread-safety -Werror=thread-safety -DSDL_THREAD_SAFETY_ANALYSIS"
2022-12-14 09:29:19 -08:00
Pierre Wendling
d0bbfdbfb8 Clang-Tidy fixes (#6725)
(cherry picked from commit 3c501b963d)
2022-12-01 13:08:50 -08:00
Sam Lantinga
b8d85c6939 Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
2022-11-30 12:57:41 -08:00
Sam Lantinga
a937b5c4ad Add 8BitDo to the list of Xbox 360 third party vendors
Allows detection of the 8BitDo Ultimate Wired Controller
2022-11-28 13:47:30 -08:00
Sylvain Becker
fb0ce375f0 Cleanup add brace (#6545)
* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line

(cherry picked from commit 6a2200823c to reduce conflicts merging between SDL2 and SDL3)
2022-11-28 12:33:03 -08:00
Sam Lantinga
c70e675900 Wait a bit for devices to initialize before trying to enumerate and open them.
This works around udev event nodes arriving before hidraw nodes and the controller being opened twice - once using the Linux driver and once by the HIDAPI driver.

This also fixes a kernel panic on Steam Link hardware due to trying to open the hidraw device node too early.

A delay of 10 ms seems to be a good value, tested on Steam Link hardware.
2022-11-03 12:37:54 -07:00
Sam Lantinga
b75d318776 Sometimes the HID open doesn't succeed immediately after being notified about the device
Tested on Steam Link hardware with the Nintendo Switch Pro controller, which will occasionally take 2 attempts to open.
2022-10-31 13:33:53 -07:00
Sam Lantinga
72f6e216dc Disabled debug logging 2022-10-25 12:25:57 -07:00
Sam Lantinga
da478d1f66 Fixed build 2022-10-25 10:30:56 -07:00
Sam Lantinga
a6018ae57f Added support for the NVIDIA SHIELD controller v1.03 to the HIDAPI driver 2022-10-25 10:23:51 -07:00
Sam Lantinga
333935ff3f Make sure we completely unlock joysticks when opening HIDAPI devices
Also lock the joysticks when adding and removing Android joysticks
2022-10-17 11:10:53 -07:00
Sam Lantinga
33050fea39 Only open HID devices that might have a HIDAPI driver available
This prevents an OS prompt for every connected device when running on Android
2022-10-07 11:29:49 -07:00
Sam Lantinga
fc720321b3 Fix rare deadlock when opening a HID controller on Android
Fixes https://github.com/libsdl-org/SDL/issues/6347
2022-10-06 18:23:07 -07:00
Sam Lantinga
0672dc8d8f Fixed combined Joy-Cons after aa2e2f4843 (thanks @happyharryh!) 2022-10-02 08:50:11 -07:00
Sam Lantinga
18046b9aa3 Fixed crash with a NULL serial number 2022-09-26 20:53:50 -07:00
Sam Lantinga
b7fddb4c0e Minor tweaks 2022-09-26 14:39:51 -07:00
Sam Lantinga
39adcc0a6b Prefer USB input over Bluetooth for PS5/PS5/Switch controllers
Nintendo Switch controllers will automatically turn off Bluetooth when connected over USB, but this takes care of that a little more quickly.

PS4 and PS5 controllers will happily send reports over both Bluetooth and USB, so we'll prefer USB if connected and switch back to Bluetooth if USB is disconnected.
2022-09-26 14:20:34 -07:00
Sam Lantinga
51fefd1c35 Added support for third party PS3 controllers to the HIDAPI driver 2022-09-23 02:39:35 -07:00
Sam Lantinga
b7940c29cc Allow HIDAPI controllers to override the default joystick type 2022-09-23 00:15:40 -07:00
Sam Lantinga
fa2063fb44 Improved detection of third party PS4 and PS5 controllers 2022-09-22 23:42:25 -07:00
Sam Lantinga
aa2e2f4843 Make sure HID devices can be opened before making them available to the application
This prevents a number of issues where devices are enumerated but not actually able to be opened, like https://github.com/libsdl-org/SDL/issues/5781.

We currently leave the devices open, allowing us to more easily do controller feature detection, protocol negotiation, detect dropped Bluetooth connections, etc. with the expectation that the application is likely to open the controllers shortly.
2022-09-22 18:27:38 -07:00
Sam Lantinga
7df571ffc6 HIDAPI_DumpPacket() takes a const memory pointer 2022-09-02 11:37:16 -07:00
Sam Lantinga
8381e008ea Handle hotplugging of Wii controller extensions 2022-09-01 21:13:16 -07:00
Sam Lantinga
c72e14e8f4 Added initial support for Wii controllers (thanks @tellowkrinkle!) 2022-09-01 15:29:41 -07:00
Sam Lantinga
cdaafcec0d The Kinvoca Joy-Cons are handled by the Joy-Con driver, not the Switch Pro driver. 2022-08-30 14:56:11 -07:00
Sam Lantinga
b2c3237b75 Added support for the Kinvoca Joy-Cons
These report their VID/PID as a Nintendo Switch Pro controller, but they are actually left/right Joy-Cons. We'll fix up the joystick GUID so applications can handle them appropriately.
2022-08-30 14:14:38 -07:00
Ludovico de Nittis
e8cb4da71f Add utility function to detect if SDL is inside a sandbox
Refactor the previous sandbox check in a standalone function that also
includes Snap support.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
2022-08-29 06:30:40 -07:00