Commit Graph

2099 Commits

Author SHA1 Message Date
Sam Lantinga 4961af4569 SDL_GetJoysticks() follows the SDL_GetStringRule 2024-07-19 12:22:03 -07:00
Sam Lantinga bb96320cc4 Make sure we always copy the data returned using SDL_GetStringRule
This prevents race conditions where calling an API from one thread returns the data and it's freed by updates on another thread
2024-07-19 12:22:03 -07:00
Amir 5db08b86ca Fix warning for Android NDK compiler: "function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]"
https://stackoverflow.com/questions/42125/warning-error-function-declaration-isnt-a-prototype
In C int foo() and int foo(void) are different functions. int foo() accepts an arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing.
2024-07-17 14:09:11 -07:00
Ryan C. Gordon 4dda785c69 gamepad: Several gamepad mapping functions now follow the SDL_GetStringRule.
Reference Issue #10229.
2024-07-16 16:44:36 -04:00
Sam Lantinga 54366181c3 Rename functions in SDL_system.h to match SDL 3.0 naming convention
Fixes https://github.com/libsdl-org/SDL/issues/10277
2024-07-15 16:27:48 -07:00
Sam Lantinga 5c875e1183 Renamed *FromID() to *ForID()
While it makes sense to get an object pointer from an object ID, you want to get object attributes for an ID, otherwise e.g. GetNameFromID() sounds like it's a name ID, not an object ID. This is also consistent with the function naming convention in SDL2.
2024-07-14 15:56:50 -07:00
Sam Lantinga d154b37b41 Renamed *FromInstanceID() to *FromID() 2024-07-14 13:01:53 -07:00
Sam Lantinga e90060d07f Renamed functions to get information from device IDs
Fixes https://github.com/libsdl-org/SDL/issues/10237
2024-07-14 09:03:59 -07:00
ceski 68cf17d0d4 Add a Windows mapping for SplitFish Game Controller 2024-07-12 19:48:40 -07:00
Sam Lantinga 4ba2e9f4f4 Improved detection of Nintendo Switch Pro controller report mode
Fixes https://github.com/libsdl-org/SDL/issues/10182
2024-07-06 05:29:12 -07:00
Sam Lantinga 2d05dcc1f7 The same VID/PID is used for the FlyDigi Apex 4 2024-07-05 10:04:59 -07:00
Max Maisel 607b1f225c Drain HIDAPI buffer in SDL_hidapi_steamdeck.c.
Add a loop around SDL_hid_read() in the Steam Deck HIDAPI driver as it
is done in other HIDAPI drivers. This loop reads data from the device and
processes it until the input buffer is empty which ensures that clients
always get the latest data.

This fixes an input latency issue if the application polls the events
slower than the hardware generates them.
2024-07-05 08:25:52 -07:00
Sam Lantinga a04596c9a7 Added support for the ROG RAIKIRI 2024-07-03 13:54:00 -07:00
Sam Lantinga 0f8054cf87 Only use the default gamepad mapping if an automatic mapping isn't available
Fixes https://github.com/libsdl-org/SDL/issues/10162
2024-07-03 11:44:20 -07:00
Sam Lantinga 0ae4fd0ec9 Make sure we don't try to use the XInput DLL after it's unloaded
Steam ran into a crash SDL_XINPUT_JoystickDetect() with XINPUTGETCAPABILITIES being NULL. I'm not sure how that happened, and there may still be a race condition if this is a multi-threaded issue, but at least this is more correct.
2024-06-26 15:44:03 -07:00
Sam Lantinga ef9bd8b609 Add the raw platform specific key code to SDL_Keysym
This allows applications to handle keys that SDL doesn't recognize, in a platform dependent way.

Fixes https://github.com/libsdl-org/SDL/issues/6390
2024-06-21 22:06:08 -07:00
Sam Lantinga 6e53a36414 Fixed Y + right shoulder button combination on third party Switch controllers 2024-06-20 14:39:04 -07:00
Sam Lantinga 421326b6da Fixed controllers not being seen as gamepads after adding a mapping 2024-06-19 08:32:18 -07:00
Hubert Maier 90b7097a90
JANITORIAL: Fix ammount typos (#10060) 2024-06-19 07:27:19 -07:00
Hubert Maier 3acdb8a90b
JANITORIAL: Fix typos in comments in various files (#10058) 2024-06-19 07:13:46 -07:00
Sam Lantinga 361cae0874 Pass through the original name used by the Steam Virtual Gamepad
Proton uses this on Linux to determine what the XInput slot is for the gamepad. Other applications will get the real controller name and VID/PID by virtue of the code in SDL_steam_virtual_gamepad.c
2024-06-17 12:14:44 -07:00
Sam Lantinga 6821fb2fe4 Fixed the right trigger on the Nintendo SNES Controller in simple report mode 2024-06-13 11:35:29 -07:00
Sam Lantinga a3cc900157 Fixed Nintendo Switch triggers when in simple report mode 2024-06-13 11:25:27 -07:00
Sam Lantinga bf27269952 Re-enable full controller reports for Joy-Con controllers
When they are in simple report mode, the thumbstick gets turned into a digital hat, so let's use them in full report mode.
2024-06-12 23:36:16 -07:00
Sam Lantinga 6619de8f24 Try to guess the type of a Nintendo Switch controller if we can't read the device info 2024-06-12 23:22:44 -07:00
Sam Lantinga 5ee9a840b1 Ignore spurious reply packets when reading Nintendo Switch controller reports 2024-06-12 23:03:50 -07:00
Sam Lantinga fcd2a3a6ad Fixed mapping for Joy-Con controllers in simple report mode 2024-06-12 22:28:47 -07:00
Sam Lantinga b2ccfc0b6f Log whether a controller is Bluetooth or not 2024-06-12 17:22:52 -07:00
Sam Lantinga 3e70376bce Enabled HIDAPI debug logging for diagnostic purposes 2024-06-12 15:03:41 -07:00
Anonymous Maarten 32907a9606 Rename SDL_Swap(16|32|64)(LE|BE) to SDL_Swap(LE|BE)(16|32|64) 2024-06-12 02:29:39 +02:00
Sam Lantinga 4fc68a48f2 Keep track of whether a controller was a gamepad
Fixes https://github.com/libsdl-org/SDL/issues/9996
2024-06-09 17:45:20 -07:00
Oleg 7529b4bed5 Added VRS DirectForce Pro wheelbase VID/PID to wheel devices list 2024-06-06 09:53:39 -07:00
Sam Lantinga b6d7adfec1 Fixed PlayStation detection interrupting input for the Logitech K400 keyboard
Also added the Logitech Chillstream to the list of PS3 controllers and fixed the right shoulder axis.
2024-06-05 19:11:10 -07:00
Sam Lantinga f879411627 Added support for gamepad rumble on Android
Tested with the DualSense controller over Bluetooth on Android 12

Fixes https://github.com/libsdl-org/SDL/issues/7847
2024-06-05 09:53:56 -07:00
Sam Lantinga 470cfc2755 Make sure we set the initial report interval value 2024-06-04 07:47:34 -07:00
meyraud705 4c9a91b62e Update gamepad sensor rate
SDL_HINT_JOYSTICK_HIDAPI_PS4_REPORT_INTERVAL allows to change sensor rate. Make SDL_GetGamepadSensorDataRate() returns the updated value.
2024-06-04 07:38:48 -07:00
Anonymous Maarten a919774fe4
Build with -Wfloat-conversion + fix all warnings 2024-06-03 21:33:29 +00:00
Ryan C. Gordon e23257307e Introduce formal policy for APIs that return strings.
This declares that any `const char *` returned from SDL is owned by SDL, and
promises to be valid _at least_ until the next time the event queue runs, or
SDL_Quit() is called, even if the thing that owns the string gets destroyed
or changed before then.

This is noted in the headers as "the SDL_GetStringRule", so this will both be
greppable to find a detailed explaination in docs/README-strings.md and
wikiheaders will automatically turn it into a link we can point at the
appropriate documentation.

Fixes #9902.

(and several FIXMEs, both known and yet-undocumented.)
2024-06-03 14:20:49 -04:00
Sam Lantinga b0e93e4e63 Prevent crashes if freed objects are passed to SDL API functions
Instead of using the magic tag in the object, we'll actually keep track of valid objects

Fixes https://github.com/libsdl-org/SDL/issues/9869
Fixes https://github.com/libsdl-org/SDL/issues/9235
2024-06-03 08:54:46 -07:00
Sam Lantinga e3beaa1972 Added support for the Razer Kitsune in PS5 mode 2024-05-31 15:18:15 -07:00
Sam Lantinga a3ab46b707 Fixed mapping the touchpad for the Qanba PS5 controllers like the Qanba Drone 2 Arcade Joystick
These controllers are autodetected by the HIDAPI driver, so SDL_GetGamepadTypeFromGUID() should be used to pull the gamepad type out of the GUID.
2024-05-23 16:48:04 -07:00
Sam Lantinga 98a9ca5e32 Added Linux bindings for the Qanba Drone 2 Arcade Joystick 2024-05-23 15:34:38 -07:00
Ryan C. Gordon 0ec716819e thread: Reworked SDL_CreateThread to be consistent across platforms.
Also documented missing and weird bits, rename typedefs to fit SDL standards.
2024-05-22 11:39:43 -04:00
Sam Lantinga f9260a8470 Added an entry for the 8Bitdo Ultimate Wired Controller 2024-05-20 16:44:45 -07:00
Sam Lantinga c24f860c4d Fixed warning C4244: '=': conversion from 'int' to 'Uint8', possible loss of data 2024-05-16 11:28:02 -07:00
Sam Lantinga abfd0dc683 Added SDL_HINT_JOYSTICK_HIDAPI_PS4_REPORT_INTERVAL 2024-05-16 11:23:29 -07:00
Oleg 79cabeef18 Added Moza wheelbases VID/PID to wheel devices list 2024-05-15 19:37:30 -07:00
Oleg dc9d9dd85a Added Simucube wheelbases VID/PID to wheel devices list 2024-05-15 19:37:30 -07:00
Oleg ce9177b64f Added Cammus C5 wheelbase VID/PID to wheel devices list 2024-05-15 19:37:30 -07:00
Sam Lantinga 8582bdaab8 Fixed warning C4244: 'function': conversion from 'Uint16' to 'Uint8', possible loss of data 2024-05-10 16:09:11 -07:00
Sam Lantinga a87fa020ac Don't enable enhanced report mode for Bluetooth Nintendo Switch controllers by default
This breaks applications using them in DirectInput mode, which isn't worth just getting battery status. We'll turn on enhanced mode if the application enables sensors.
2024-05-10 12:17:28 -07:00
Sam Lantinga c1ba31118b Added ball, touchpad, and sensor support for virtual joysticks
Fixes https://github.com/libsdl-org/SDL/issues/9542
2024-05-09 18:25:22 -07:00
Sam Lantinga bcbf09acde Renamed SDL_AttachVirtualJoystickEx() to SDL_AttachVirtualJoystick()
The shorthand version of this function didn't allow specifying a controller name, which seems pretty important. It seems like anyone actually implementing a virtual joystick is going to want to use some of the extended functionality.
2024-05-09 14:05:58 -07:00
Ozkan Sezer e909c0360f remove most of SDL_OutOfMemory() calls where SDL is the allocator.
Since commit 447b508a77, SDL_malloc,
SDL_calloc, and SDL_realloc already calls SDL_OutOfMemory().
2024-05-08 20:00:50 +03:00
Sam Lantinga 01d560df50 Added a Windows mapping for the SPEEDLINK STRIKE Gamepad
Fixes https://github.com/libsdl-org/SDL/issues/9705
2024-05-06 10:11:26 -07:00
Tyson Whitehead 0ab5a8a413 Initialize udev before joystick manual scan so class lookup works
LINUX_JoystickInit does a manual scan first so devices are sorted.
If SDL_UDEV_Init hasn't run by then, then the product info cannot
be looked up by SDL_UDEV_GetProductInfo and the initial-plugged-
in-device classification falls back to heuristic guessing.

(cherry picked from commit 0963c11af8)
2024-04-26 12:16:24 -07:00
Sam Lantinga ac5a61cd60 Fixed build error (thanks @sezero!) 2024-04-25 09:45:10 -07:00
Tyson Whitehead 391b8c0c07 Avoid opening non-joystick devices if possible to speedup scanning
Closing a device file takes 0.01 to 0.5s, which can add up to
significant startup delays. The udev classification does not
require opening the actual device files, so, use it if possible,
and only fall back to opening the device and probing otherwise.

(cherry picked from commit 45b804c158)
2024-04-25 08:49:48 -07:00
yassineimounachen 5ffb2f47d1 Add USB IDs for the Thrustmaster TS-XW racing wheel
To be of use, this depends on https://github.com/berarma/oversteer/pull/200 and https://github.com/Kimplul/hid-tmff2/pull/94.
2024-04-22 11:35:31 -07:00
Ryan C. Gordon d252a8fe12
joystick: SDL_VirtualJoystickDesc no longer takes a struct version.
If we need to extend this in the future, we'll make a second struct and
a second SDL_AttachVirtualJoystickEx-style function that uses it.

Just zero the struct and don't set a version.

Fixes #9489.
2024-04-13 14:16:12 -04:00
Sam Lantinga 85b7f131b0 Fixed warning C4701: potentially uninitialized local variable 'percent' used 2024-04-01 14:27:19 -07:00
Sam Lantinga 8847b35244 Separate joystick power state into battery status and percentage
This allows you to see battery percentage while the controller is charging
2024-04-01 13:59:00 -07:00
Sam Lantinga 43b8e9f681 Fixed spacing 2024-03-25 11:41:51 -07:00
Sam Lantinga 5e8486bb29 Don't fail joystick initialization if udev isn't available 2024-03-25 11:29:18 -07:00
Sam Lantinga 977285ef6a Send joystick added events on portable handheld platforms
The IDs on these drivers are hard-coded as device_index + 1, so that's the ID we will send during initialization.
2024-03-25 07:14:00 -07:00
Sam Lantinga b391e6477e The joystick instance ID is already set in the open call 2024-03-25 06:57:02 -07:00
Alynne 2b4c75690c Add Yawman Arrow flightstick controller 2024-03-25 06:34:54 -07:00
Sam Lantinga 35756593d6 Use the correct device ID (global or default or specific) based on context 2024-03-23 16:31:00 -07:00
Sam Lantinga 2fe1a6a279 Initial support for hotplugging mice and keyboards 2024-03-23 16:31:00 -07:00
Marcel Hild 67e425bcf8 Add support for MadCatz Saitek Side Panel Control Deck
Signed-off-by: Marcel Hild <hild@b4mad.net>
2024-03-22 09:15:39 -07:00
Sam Lantinga 70b0d33106 Poll for the initial controller state when using DirectInput
This fixes getting a deflected axis as the first buffered input reading on a generic USB controller (G-Shark GS-GP702)
2024-03-20 10:45:11 -07:00
Anonymous Maarten f59dbf6a12 cmake: add -Wimplicit-fallthrough warning 2024-03-18 20:34:50 +01:00
rofl0r 12245e4c75 PSP/Joystick: fix formatting
(cherry picked from commit c17d2246fb)
2024-03-17 13:23:51 -07:00
rofl0r 7169db1e62 PSP: don't block on joystick event query
using the blocking sceCtrlReadBufferPositive() effectively turns SDL_PollEvent() into WaitForVblank(), because the functions does exactly that if no input is buffered.
due to this, calling SDL_PollEvent() once per frame averaged in 7 ms delay out of the available 16ms budget to get a frame calculated and drawn to achieve 60 fps.

(cherry picked from commit 86f223d664)
2024-03-17 13:23:51 -07:00
Sam Lantinga d972244d3a Added a mapping for the Defender Joystick Cobra R4 (thanks @kotenok2000!) 2024-03-17 12:13:21 -07:00
Sam Lantinga 4697153d1e Use the CRC as part of the unique key for mappings 2024-03-17 12:13:21 -07:00
Sam Lantinga 41e187be4f Adjust Steam button names to match SDL 2024-03-15 16:05:19 -07:00
Ryan C. Gordon 6776b6108a
iostream: "free*" params should be "closeio". 2024-03-14 23:14:46 -04:00
Ryan C. Gordon 3a344cf877
rwops: Fixed some SDL2 symbols that got missed. 2024-03-14 21:57:21 -04:00
Ryan C. Gordon fc7afa9cbf
rwops: Renamed SDL_RWops to SDL_IOStream, and other related symbols. 2024-03-14 19:38:12 -04:00
Sam Lantinga 30e93b40c2 If a mapping specifies a crc, don't match for controllers that don't have that CRC
The CRC is used to distinguish between different controllers that have the same VID/PID, so if the CRC doesn't match, it's probably a different controller that we don't know about.

Fixes https://github.com/libsdl-org/SDL/issues/9265
2024-03-14 13:26:56 -07:00
Sam Lantinga d79f865251 Removed incorrect mapping for a HORI controller
This broke support for the Hori Fighting Stick EX2, which gets a good mapping if the automatic mapping is allowed to create one.

If the original controller needs a mapping, it should be added with a crc, since that VID/PID combination is used by several HORI controllers.
2024-03-11 17:11:20 -07:00
Sam Lantinga efbbafb3f1 Re-added balls to the SDL joystick API
It turns out these were being used on Linux and at least one virtual driver was making use of them (thanks @mrfixit2001!)
2024-03-10 21:30:14 -07:00
Sam Lantinga 53e86be22f Minor cleanup with the new PS3 driver for windows 2024-03-10 20:12:11 -07:00
Riccardo Marcangelo 6534029691
Add DualShock 3 HIDAPI support on Windows (#9144)
This adds HIDAPI support for DualShock 3 controllers on Windows, addressing the current absence of this feature in SDL. To utilize this functionality, the official Sony driver 'sixaxis.sys' must be installed. HID offers several advantages over DirectInput, including rumble support and the ability to control the LED lights that display the controller number.
2024-03-10 20:08:36 -07:00
Sam Lantinga e3cf2e4794 Turn HIDAPI joystick support off by default on mobile platforms
On Android, HIDAPI prompts for permissions and acquires exclusive access to the device, and on Apple mobile platforms it doesn't do anything except for handling Bluetooth Steam Controllers.

Fixes https://github.com/libsdl-org/SDL/issues/9241
2024-03-10 15:00:49 -07:00
Simon McVittie 76defc5c82 joystick: Remove redundant CHECK_JOYSTICK_MAGIC in SDL_GetJoystickName
Since commit 0dfdf1f3 "Fixed crash if joystick functions are passed a
NULL joystick", we've already done this check by the time we get to
this point.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-03-09 08:40:04 -08:00
Mingjie Shen 19b3ddac2f Fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow
an attacker to modify the file between the two operations. (CWE-367)
Fix by using fstat() instead of stat().
2024-03-08 15:52:04 -08:00
Sam Lantinga cde793b0f5 Added support for the 6-button SEGA Mega Drive Control Pad for Nintendo Online
Closes https://github.com/libsdl-org/SDL/pull/9225
2024-03-08 12:33:54 -08:00
Sam Lantinga 33eaddc565 Cleaned up various type conversion issues
This makes sure SDL_PixelFormatEnum flows through the internal code correctly, as well as fixing a number of other minor issues.
2024-03-07 06:58:43 -08:00
Sam Lantinga 57a160c9ab Fixed mapping for the Sanwa Supply JY-P76USV controller 2024-03-06 20:53:48 -08:00
Sam Lantinga 65a718f8c6 Disable warning C4113 in SDL_windows_gaming_input.c
- A new version of warning C4028 added in VS 2022.
2024-03-06 13:33:20 -08:00
Sam Lantinga 9be35d4603 Convert mappings using labeled buttons to positional buttons
We were accidentally skipping all of the mappings that used the SDL_GAMECONTROLLER_USE_BUTTON_LABELS hint, because they used the '!' negate operator with a default hint value of 1. Instead we just want to use that hint to determine whether the mapping has positional buttons or not, and swap the buttons as needed.

Fixes https://github.com/libsdl-org/SDL/issues/9190
2024-03-03 14:17:03 -08:00
Sam Lantinga ccd309c433 Added a mapping for the Sanwa Supply JY-P76USV controller
Fixes https://github.com/libsdl-org/SDL/issues/8644
2024-03-03 12:23:00 -08:00
Sam Lantinga 8d8076263e Removed the mapping for the G-Shark GS-GP702
This uses the same chipset as the DragonRise Inc. Generic USB Joystick, which many manufacturers use for different products with different mappings.

In order to add a mapping for a controller using this chipset, we need a unique crc for the device name.
2024-03-03 12:18:57 -08:00
Sam Lantinga 1b86a1c684 SDL_GetGamepadAppleSFSymbolsNameForAxis() returns NULL if the symbol isn't found 2024-03-03 11:55:40 -08:00
Sam Lantinga c1da39a245 SDL_GetGamepadAppleSFSymbolsNameForButton() returns NULL if the symbol isn't found
Fixes https://github.com/libsdl-org/SDL/issues/9071
2024-03-03 11:07:39 -08:00
meyraud705 c6ec999869 Set udev class for accelerometer 2024-03-03 08:40:24 -08:00
Sam Lantinga 7117d545a3 Fixed crash if the controller product name is NULL
This happens when the Razer Synapse software emulates a controller with a keyboard
2024-02-28 11:43:22 -08:00
Sam Lantinga 376ef4e418 Fixed the WGI driver picking up Xbox controllers handled by RAWINPUT
The WGI driver will see them first, but the RAWINPUT driver has higher priority, so we'll defer to that when it's available.

Fixes https://github.com/libsdl-org/SDL/issues/9091
2024-02-20 06:20:32 -08:00