Commit Graph

789 Commits (d079130c24221d25a89b57f40f6452d62780cb17)

Author SHA1 Message Date
Sam Lantinga 4fbefbe20d Sort the raw input axes by usage, so X comes before Y, etc. 2020-11-27 11:33:53 -08:00
Sam Lantinga 4ddac485db Backed out minor optimization that prevented correlation_id from being set 2020-11-27 11:33:51 -08:00
Sam Lantinga 8973a25849 Enable dispatching of WM_INPUT_DEVICE_CHANGE events directly, in case the application hasn't created a window with the normal message loop 2020-11-27 10:44:56 -08:00
Sam Lantinga e8adc64810 Enable dispatching of WM_INPUT events directly, in case the application hasn't created a window with the normal message loop 2020-11-27 10:44:55 -08:00
Sam Lantinga 0252235e82 Recheck devices if another API queries raw input for a new device 2020-11-27 10:44:53 -08:00
Sam Lantinga a7dede7e36 Re-enable axis correlation for raw input controllers, for twin stick shooters that don't need face buttons 2020-11-27 10:44:51 -08:00
Sam Lantinga ce77966da8 Fixed RAWINPUT_IsDevicePresent() not returning TRUE for Xbox One controllers 2020-11-27 10:44:49 -08:00
Sam Lantinga 8a449de20d Fixed Xbox 360 wireless controller being picked up by WGI when it's being managed by RAWINPUT 2020-11-27 10:44:47 -08:00
Sam Lantinga 37c9e4afa3 Fixed processing WM_INPUT_DEVICE_CHANGE at startup 2020-11-27 06:03:15 -08:00
Sam Lantinga 248fc75bd2 Correlate just based on buttons, joystick axes are not as precise and could potentially cause incorrect uncorrelation.
It's okay if the triggers aren't precise until someone presses a button on their controller.
2020-11-27 05:53:56 -08:00
Sam Lantinga e7e615de26 Removed extraneous windows message pumping
Most of the raw input events are dispatched in the main windows message loop. We only dispatch device change messages separately when we need them to be completely up to date.
2020-11-27 05:53:54 -08:00
Sam Lantinga 2931eccd84 Fixed detecting Bluetooth raw input devices, which have device names longer than 128 characters 2020-11-27 05:53:52 -08:00
Sam Lantinga 849ce80376 Renamed SDL_JOYSTICK_RAWINPUT_GAMING_INPUT to SDL_JOYSTICK_RAWINPUT_WGI 2020-11-27 05:53:50 -08:00
Sam Lantinga 219a28dd8a Fixed D-pad uncorrelating raw input controllers (thanks Jimbly!) 2020-11-27 03:45:05 -08:00
Ozkan Sezer 3fbff2a45b SDL_rawinputjoystick.c: fix ambiguous 'else' warning
src/joystick/windows/SDL_rawinputjoystick.c: In function 'RAWINPUT_HandleStatePacket':
src/joystick/windows/SDL_rawinputjoystick.c:1343:9: warning: suggest explicit braces to avoid ambiguous 'else'
2020-11-26 10:47:33 +03:00
Sam Lantinga 845b903324 Implemented trigger rumble for raw input controllers 2020-11-25 16:46:42 -08:00
Sam Lantinga 517be80822 Implemented battery status for Bluetooth Xbox One controllers
Also switched the rumble loop count to 0xEB (one hour) to match Windows driver
2020-11-25 16:05:19 -08:00
Sam Lantinga 6a7f29cdbb Fixed compiling on tvOS 2020-11-25 11:31:17 -08:00
Sam Lantinga 9ec2cf5629 Fixed building with Windows.Gaming.Input enabled 2020-11-25 10:31:59 -08:00
Sam Lantinga 3c07dd12f0 Strip an extra '.' off of the HORI manufacturer name 2020-11-25 10:28:48 -08:00
Sam Lantinga 159d1b3df5 Don't set the serial number after the controller is opened
We'll use the USB value instead so it's available as soon as it's opened.
2020-11-25 01:35:45 -08:00
Sam Lantinga 7d92b14f46 Simplified Xbox One controller initialization state, and don't query for the serial number. 2020-11-25 01:18:18 -08:00
Sam Lantinga 9fc4a4c92c Revamped Xbox One HIDAPI init sequence
Added support for querying the controller serial number on newer firmware
2020-11-24 22:25:26 -08:00
Sam Lantinga e4b7d9a221 Removed usage of TARGET_OS_OSX for building with older SDKs 2020-11-24 07:56:59 -08:00
Sam Lantinga a5cde4cb0c Fixed trying to use @available() on older SDK 2020-11-24 07:29:55 -08:00
Sam Lantinga 97782e6c64 Don't try to call IOS_SupportedHIDDevice() if it's not defined 2020-11-24 07:11:49 -08:00
Sam Lantinga a063b9fbfb Fixed compiler warning 2020-11-24 07:06:31 -08:00
Sam Lantinga c63bbb06e9 Including SDL_config_iphoneos.h enables MFI controller code 2020-11-24 06:55:33 -08:00
Sam Lantinga 7a05dbf4b9 Fixed building on FreeBSD
Alex S

Looks like we have a collision with https://hg.libsdl.org/SDL/rev/cd774daff9f6. (Again, the headers in the base system are intended for drivers and should not be used for compiling non-base applications. At least that's the policy for now: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=240964#c19.)
2020-11-24 06:42:53 -08:00
Sam Lantinga feab9d42c1 5363 - Memory leak of joystick->sensors in SDL_JoystickClose
Mathieu Eyraud

Joystick->sensors is never freed.
2020-11-24 06:40:13 -08:00
Sam Lantinga 34bea84a54 Fixed bug 5335 - Patch: enable joystick/haptic/evdev support by default on FreeBSD
Alex S

Ah, that's not quite enough. You need to:
  1. rename src/joystick/bsd/SDL_sysjoystick.c to something;
  2. regenerate configure.
2020-11-23 23:03:55 -08:00
Sam Lantinga 1e943e2ad2 Fixed building with an older SDK and macOS target 2020-11-23 22:59:22 -08:00
Sam Lantinga e44bf8a080 Fixed bug 5359 - Incorrect sensor data from DualShock4
multiply gyro values by sensitivity

When the hardware calibration fails, values read from sensors need to be multiplied by default sensitivity (16 for gyro, 1 for accelerometer).
2020-11-23 21:18:37 -08:00
Sam Lantinga c8c818d7a4 Fixed bug 5360 - non-libudev joystick detection doesn't see controllers that were already connected
Simon McVittie

When watching for hotplug events we can poll the inotify fd, but we
still need to scan /dev/input once per process, otherwise we'll fail
to detect devices that were already connected.
2020-11-23 21:14:37 -08:00
Simon McVittie 8e2746cfb6 joystick: Don't use udev in Flatpak or pressure-vessel container
Flatpak[1] and pressure-vessel[2] are known to use user namespaces,
therefore udev event notification via netlink won't work reliably.
Both frameworks provide a filesystem API that libraries can use to
detect them. Do that, and automatically fall back from udev-based
device discovery to the inotify-based fallback introduced in Bug #5337.

[1] <https://flatpak.org/>
[2] <https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/tree/master/pressure-vessel>

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-11-23 21:10:48 -08:00
Sam Lantinga e9869e07bf Fixed bug 5335 - enable joystick/haptic/evdev support by default on FreeBSD
Alex S

Evdev headers aren't actually included in the base system (well, it has a private copy), they are available through the devel/evdev-proto port instead. We also have devel/libinotify and devel/libudev-devd shims, I didn't verify whether they work with SDL.
2020-11-23 21:08:19 -08:00
Sam Lantinga 62e39b5fa7 Fixed building with an older SDK and macOS target 2020-11-23 20:57:14 -08:00
Sam Lantinga 268aa45645 Fixed compiling with SDL_JOYSTICK_RAWINPUT disabled 2020-11-23 20:26:28 -08:00
Ryan C. Gordon eaa53a1979 joystick: On Linux, don't try to close an invalid inotify file descriptor. 2020-11-23 22:16:07 -05:00
Ryan C. Gordon 5c9577476f joystick: Fix up Linux joystick code to (mostly) compile on FreeBSD. 2020-11-23 22:14:22 -05:00
Sam Lantinga 179bd66581 Don't enable PS5 controller support if DS4Windows is running - they conflict. 2020-11-23 18:27:43 -08:00
Sam Lantinga 5b3616c325 Generalized the raw input controller driver and moved XInput/WGI detection into it for XInput devices
This fixes bad report parsing for various newer Xbox controllers, and this driver is now preferred over XInput, since it handles more than 4 controllers.
2020-11-23 18:24:05 -08:00
Sam Lantinga fd89446782 Fixed building on Mac OS X on the command line and with an older macOS SDK 2020-11-21 14:13:26 -08:00
Sam Lantinga 1df593fb16 Fixed bug 5355 - Add GameController Framework support to macOS
C.W. Betts

This patch adds support to the GameController framework on macOS Big Sur and later, adding support for MFi controllers as well as rumble support for PS4 and Xbox One. There is some code to make sure that the IOKit joystick handler doesn't include two controllers at once.

While the GameController framework is present in earlier versions of macOS, there was no public, approved way of checking if a specific IOHIDDevice is a controller that GameController could handle. This was changed in Big Sur.
2020-11-21 13:15:33 -08:00
Sam Lantinga 870841c414 Reset the LED state after Bluetooth connection has completed on the PS5 controller 2020-11-21 11:59:01 -08:00
Sam Lantinga 2e8e3854b8 Fixed compile warning 2020-11-21 17:59:15 -08:00
Sam Lantinga 549010f2a0 It takes 2 packets to stop audio haptics and start emulated rumble on the PS5 controller 2020-11-20 13:24:49 -08:00
Sam Lantinga bf7d198d48 The HORI Fighting Commander should only show up as an XInput Switch Controller on Windows 2020-11-19 19:09:42 -08:00
Sam Lantinga 6cb7f9e39a Respect SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS for Nintendo Switch Pro controllers using the HIDAPI driver 2020-11-19 19:09:40 -08:00
Sam Lantinga 9980766533 Respect SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS for the Nintendo Switch Pro controller on Linux 2020-11-19 19:09:38 -08:00
Sam Lantinga 7366693f3b Added support for a few more controllers on Linux 2020-11-19 19:09:36 -08:00
Sam Lantinga ffb4d960b2 Disabled Xbox protocol debugging 2020-11-19 19:09:34 -08:00
Sam Lantinga c9b097e659 Clarify the meaning of the rumble enable bits for the PS5 controller 2020-11-19 13:31:16 -08:00
Sam Lantinga c85623d790 Re-enable haptic audio after rumble on PS5 controller
Also make sure we don't set any other state when we're not intending to, and added more interesting effects which are currently not exposed via API
2020-11-19 13:10:14 -08:00
Sam Lantinga 8c3196da60 Fixed some compiler warnings 2020-11-18 21:33:11 -08:00
Sam Lantinga 45f1437549 Experimenting with requesting the serial number on an Xbox One controller 2020-11-18 20:34:12 -08:00
Sam Lantinga 963d8b3f40 Fixed bits in the initial Xbox One protocol ack 2020-11-18 20:34:10 -08:00
Sam Lantinga cd51a51f00 Updated with a better understanding of the Xbox One controller protocol 2020-11-18 20:34:08 -08:00
Sam Lantinga 51ea6a6d44 Don't send controller gyro and accelerometer updates if the values haven't changed.
This keeps SDL_PollEvent() from returning data continuously when polling controller state.
2020-11-17 22:09:52 -08:00
Sam Lantinga 463d84a860 Added support for the PS5 controller gyro and accelerometer 2020-11-17 10:56:56 -08:00
Sam Lantinga fcb21aa883 Added API for sensors on game controllers
Added support for the PS4 controller gyro and accelerometer on iOS and HIDAPI drivers

Also fixed an issue with the accelerometer on iOS having inverted axes
2020-11-17 10:30:20 -08:00
Sam Lantinga d140d88744 Added SDL_JoystickGetSerial() and SDL_GameControllerGetSerial() 2020-11-16 17:36:47 -08:00
Sam Lantinga 7bbea0bb94 Fixed build warning 2020-11-16 15:10:02 -08:00
Sam Lantinga 71e32f5e1b Added SDL_crc32() 2020-11-16 15:00:15 -08:00
Sam Lantinga 3d48fc05c3 Added notes about the pad lights on the PS5 controller 2020-11-16 13:21:02 -08:00
Sam Lantinga 4514ad573e Fixed updating LED state when starting application with Bluetooth PS5 controller connected 2020-11-16 13:07:11 -08:00
Sam Lantinga a37e3ae218 Implemented PS5 effects over Bluetooth 2020-11-16 11:21:58 -08:00
Sam Lantinga c6c116e847 Implemented setting the LED color on the PS5 controller 2020-11-16 10:51:13 -08:00
Sam Lantinga aa7c3eae19 Fixed size of rumble packet 2020-11-16 09:16:01 -08:00
Sam Lantinga f28c01a4fb Fixed rumble order on PS5 2020-11-16 09:11:15 -08:00
Sam Lantinga eb94c19a63 SDL: fix iOS build 2020-11-16 08:09:15 -08:00
Sam Lantinga 8243bd1dc6 SDL: Plumb PS5 rumble to output report 2020-11-16 08:09:13 -08:00
Ozkan Sezer c0f7325b85 SDL_PrivateJoystickForceRecentering: fix wrong loop counter usage.
The typo seems to have been added by commit c7782fd6142b
2020-11-15 17:10:15 +03:00
Sam Lantinga 5c34c973e6 Clarify that we're using button indices, not using gamepad button names 2020-11-13 19:40:25 -08:00
Sam Lantinga 9f51fad361 Added support for the touchpad on PS4 and PS5 controllers 2020-11-13 18:01:29 -08:00
Sam Lantinga 78422fa3c8 Added more detail on the PS5 controller state packet and enable full reports over Bluetooth 2020-11-13 13:17:07 -08:00
Sam Lantinga 8cd4f364db Mapped the touchpad click as SDL_CONTROLLER_BUTTON_MISC1 on the PS5 controller 2020-11-12 20:02:31 -08:00
Sam Lantinga 8e312a6a59 Fixed detecting Bluetooth XInput controllers on Windows 2020-11-12 15:56:33 -08:00
Sam Lantinga e0018d0869 Fixed Windows build 2020-11-12 14:23:56 -08:00
Sam Lantinga 5b0d432942 Implemented trigger rumble in the HIDAPI Xbox One driver 2020-11-12 07:53:03 -08:00
Ozkan Sezer c122e9b9ce linux/SDL_sysjoystick.c (MaybeRemoveDevice): remove SDL_USE_LIBUDEV guards
fixes bug #5349.
2020-11-12 14:11:50 +03:00
Sam Lantinga 83b653d55d Fixed build warning 2020-11-11 20:09:56 -08:00
Sam Lantinga 76bd6cd2d9 Fixed bug 5326 - Logitech Extreme 3D joystick is listed as gamepad in linux section of SDL_gamecontrollerdb.h
Spooky

For some reason the Logitech Extreme 3D joystick was added to SDL_gamecontrollerdb.h  in the linux section only.

This breaks the joystick in linux as it is not a gamepad.  I am unable to correctly use or map the Logitech Exteme 3D joystick in games that use SDL2 in linux.

Please remove Logitech Extreme 3D from SDL_gamecontrollerdb.h  Linux section.  It is a joystick not a gamepad.
2020-11-11 19:45:56 -08:00
Sam Lantinga 3160c7d66f Fixed bug 5327 - When direct input fails to load, but a controlller is plugged in through another api, an access violation happens.
Bart van der Werf

When directinput fails to load, but a controlller is plugged in, an access violation happens.
This is due to IEventHandler_CRawGameControllerVtbl_InvokeAdded calling SDL_DINPUT_JoystickPresent which does not check if dinput is assigned signalling initialization of directinput.
2020-11-11 19:43:02 -08:00
Sam Lantinga 502cfe314a Fixed bug 5332 - WGI: Fix wrong level of indirection and implicit truncating cast.
Joel Linn

This fixes two types of MSVC compiler warnings.

- One parameter in the function signatures of two WGI event handlers had one level of indirection too much (and did not match Windows SDK headers). The indirection was cast away so it still worked.
- size_t was implicitly cast to UINT32 for a number of (constant) string lengths.
2020-11-11 19:39:46 -08:00
Sam Lantinga 320a7587d7 Fixed compiler warnings 2020-11-11 19:26:59 -08:00
Simon McVittie b0eba1c55d joystick: Use inotify to detect joystick unplug if not using udev
This improves SDL's ability to detect joystick hotplug in a container
environment.

We cannot reliably receive events from udev in a container, because they
are delivered as netlink events, which are authenticated by their uid
being 0. However, in a user namespace created by an unprivileged user
(for example bubblewrap, as used by Flatpak and Steam's
pressure-vessel-wrap), the kernel does not allow us to map uid 0, and
the netlink events appear to be from the kernel's overflowuid (typically
65534/nobody), meaning libudev cannot distinguish between genuine uevents
from udevd and an attack by a malicious local user.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-11-11 19:15:32 -08:00
Simon McVittie fdd945f2af joystick: Use a better heuristic to guess what is a joystick
Previously we only checked for at least one button or key and at least
the X and Y absolute axes, but this has both false positives and false
negatives.

Graphics tablets, trackpads and touchscreens all have buttons and
absolute X and Y axes, but we don't want to detect those as joysticks.
On normal Linux systems ordinary users do not have access to these
device nodes, but members of the 'input' group do.

Conversely, some game controllers only have digital buttons and no
analogue axes (the Nintendo Wiimote is an example), and some have axes
and no buttons (steering wheels or flight simulator rudders might not
have buttons).

Use the more elaborate heuristic factored out from SDL's udev code path
to handle these cases.

In an ideal world we could use exactly the same heuristic as udev's
input_id builtin, but that isn't under a suitable license for inclusion
in SDL, so we have to use a parallel implementation of something
vaguely similar.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-11-11 19:14:52 -08:00
Simon McVittie 8db3171b98 udev: Factor out SDL_EVDEV_GuessDeviceClass
This works on capability bitfields that can either come from udev or
from ioctls, so it is equally applicable to both udev and non-udev
input device detection.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-11-11 19:14:34 -08:00
Simon McVittie 13e7d1a958 joystick: Allow libudev to be disabled at runtime
Device enumeration via libudev can fail in a container for two reasons:

* the netlink protocol between udevd and libudev is considered private,
  so there is no API guarantee that the version of libudev in a container
  will understand netlink messages from a dissimilar version of udevd
  on the host system;
* the netlink protocol between udevd and libudev relies for security on
  being able to check the uid of each message, but in a container with
  a user namespace where host uid 0 is not mapped, the libudev client
  cannot distinguish between messages from host uid 0 and messages from
  a different, malicious user on the host

To make this easier to experiment with, always compile the fallback
code path even if libudev is disabled. libudev remains the default if
enabled at compile time, but the fallback code path can be forced.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-11-11 19:14:11 -08:00
Sam Lantinga 1e2caac58b Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers() 2020-11-11 18:57:37 -08:00
John "Nielk1" Klein 067630aef3 Fix hidapi for unhandled DS4 headset microphone data corrupting controller state 2020-11-11 03:47:08 -06:00
Sam Lantinga b6238c87e4 Don't try to build the RAWINPUT driver if HIDAPI is disabled 2020-11-11 14:48:23 -08:00
Sam Lantinga d1e10c313e Removed debug output 2020-11-11 14:38:14 -08:00
Sam Lantinga e12457d8bf Added support for the Xbox Series X controller to the HIDAPI driver 2020-11-10 12:26:30 -08:00
Sam Lantinga c3dea23120 Added support for reading the paddles on a Xbox Elite Series 2 controller in Bluetooth mode 2020-11-09 22:39:33 -08:00
Sam Lantinga fb4a406af2 Don't put 'm' in the GUID for Xbox and PS4 controllers on iOS 2020-11-09 18:45:22 -08:00
Sam Lantinga f8b8bd0ba1 ControllerList: recategorize controller as swtich pro and not switch input-only controller 2020-11-09 10:12:02 -08:00
Sam Lantinga f76ca05729 ControllerList: add unknown xbox controller from minidumps 2020-11-09 10:11:59 -08:00
Sam Lantinga 1577366c36 Fixed duplicated switch statement processing Xbox controller dpad state 2020-11-08 23:49:03 -08:00