Commit graph

181 commits

Author SHA1 Message Date
Sam Lantinga 5fded632d6 Added support for the Turtle Beach REACT-R and Recon Xbox controllers 2023-02-06 20:14:12 -08:00
Sam Lantinga 22bafe8729 Removed debug code accidentally committed 2023-02-06 11:23:53 -08:00
Sam Lantinga f8b41919da Fixed warning running a command queue without any vertex operations 2023-02-06 11:22:00 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Sam Lantinga e85839cd56 Fixed line wrapping for HID packet dump 2023-01-03 15:12:47 -08:00
Sam Lantinga dacdb1c310 Added support for the ThrustMaster eSwap PRO Controller Xbox 2023-01-03 15:12:18 -08:00
Sam Lantinga ab2d007982 More gamepad renaming 2022-12-27 11:31:54 -08:00
Sam Lantinga 659abc721a SDL API renaming: SDL_gamecontroller.h
SDL_gamecontroller.h has been renamed SDL_gamepad.h, and all APIs have been renamed to match.

Fixes https://github.com/libsdl-org/SDL/issues/6885
2022-12-27 09:47:24 -08:00
Sam Lantinga fc478c1bc0 SDL API renaming: SDL_joystick.h
Fixes https://github.com/libsdl-org/SDL/issues/6881
2022-12-27 05:50:46 -08:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Sam Lantinga 5c29b58e95 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:53:39 -08:00
Pierre Wendling 3c501b963d
Clang-Tidy fixes (#6725) 2022-12-01 13:07:03 -08:00
Sam Lantinga 5750bcb174
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
2022-11-30 12:51:59 -08:00
Sam Lantinga c5790359fd
Added precompiled header support for Visual Studio and Xcode (#6710)
Fixes https://github.com/libsdl-org/SDL/issues/6704
2022-11-29 18:34:15 -08:00
Sam Lantinga 5efca283d3 Add 8BitDo to the list of Xbox 360 third party vendors
Allows detection of the 8BitDo Ultimate Wired Controller
2022-11-28 14:54:36 -08:00
Sylvain Becker 6a2200823c
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
2022-11-27 08:38:43 -08:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -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
Sam Lantinga b6f96b69aa Initial HIDAPI driver support for the PS3 controller 2022-08-23 22:45:37 -07:00
Sam Lantinga 277b033e78 Refactor joystick GUID creation 2022-08-22 19:44:14 -07:00
Sam Lantinga c1e0873940 Added the CRC of the joystick name to the GUID
This will make it possible to have mappings for different controllers
that have the same VID/PID. This happens frequently with some generic
controller boards that have been reused in many products.

Fixes https://github.com/libsdl-org/SDL/issues/6004
2022-08-22 18:22:35 -07:00
Sam Lantinga 52b6899a6b Added hints for more fine grained control over HIDAPI Xbox controller support 2022-08-19 11:11:23 -07:00
Sam Lantinga 9670d2bb9e Make sure we hold the joystick lock when disconnecting a HIDAPI joystick
This prevents crashes when calling SDL joystick API functions from a different thread while disconnection is happening.

See https://github.com/libsdl-org/SDL/issues/6063 for a more thorough review of joystick locking.
2022-08-15 17:28:50 -07:00
Sam Lantinga 9ff498e78e Make HIDAPI_JoystickOpen() more robust against internal logic errors
Fixes https://github.com/libsdl-org/SDL/issues/6030
2022-08-10 06:00:30 -07:00
Sam Lantinga 1db7d33dc4 Recover from Bluetooth devices temporarily out of range 2022-08-09 17:04:26 -07:00
Sam Lantinga 6d012b2a5d Better fix for rescanning devices after read failure 2022-08-09 16:54:11 -07:00
Sam Lantinga 5d63a3d435 Re-enumerate devices if a read fails
This allows combined Joy-Con devices to immediately separate if one of them is disconnected
2022-08-09 14:06:49 -07:00
Sam Lantinga 878259722f Added SDL_GameControllerType enumeration for Nintendo Switch Joy-Con controllers 2022-08-08 08:22:20 -07:00
Sam Lantinga 29cdb2c9c9 Added support for the Nintendo Switch Joy-Con Charging Grip 2022-08-03 18:01:10 -07:00