src/joystick/SDL_gamecontroller.c


Log

Author Commit Date CI Message
Sam Lantinga e12457d8 2020-11-10T12:26:30 Added support for the Xbox Series X controller to the HIDAPI driver
Sam Lantinga 009b62f1 2020-11-07T02:22:15 Be explicit about mapping the new game controller paddle buttons
Sam Lantinga 3a3aaac2 2020-11-06T11:30:52 Added 4 auxiliary buttons to the game controller API Xbox Elite controllers use AUX1-AUX4 to represent the paddle buttons when using the HIDAPI driver PS4 and PS5 controllers use AUX1 to represent the touchpad button Nintendo Switch Pro controllers use AUX1 to represent the capture button
Sam Lantinga e555d453 2020-11-05T11:07:54 Added SDL_JoystickHasLED Currently, this is only supported by the PS4 HIDAPI driver.
Sam Lantinga 99ed0d7a 2020-10-16T12:40:12 Map the guide button by default on Android 11
Sam Lantinga cab1a715 2020-07-15T10:15:52 Fixed bug 5233 - PS3 Gamepad Motion Control not correctly ignored on Linux Igor Morgado PS3 Controller motion sensor string is being reported as `Gasia Co.,Ltd PS(R) Gamepad Motion Sensors` But `src/joystick/SDL_gamecontroller.c` line1690 only ignores if matches the string `Controller Motion Sensors`. ``` #if defined(__LINUX__) if (name && SDL_strstr(name, "Controller Motion Sensors")) { /* Don't treat the PS3 and PS4 motion controls as a separate game controller */ return SDL_TRUE; } #endif ``` Therefore, SDL is mapping 2 Game controllers instead one. Maybe reduce the substring to match `Motion Sensors` instead. A simple log from my application is shown below: INFO: Game controller device 0 - PS3 Controller:PS3 Controller found. INFO: Controller 0: Player 0: 054c:0268:8111 - PS3 Controller - PS3 Controller - Gasia Co.,Ltd PS(R) Gamepad INFO: Game controller device 1 - PS3 Controller:PS3 Controller found. INFO: Controller 1: Player 1: 054c:0268:8111 - PS3 Controller - PS3 Controller - Gasia Co.,Ltd PS(R) Gamepad Motion Sensors
Sam Lantinga 39c958bb 2020-05-29T14:48:39 Initialize the raw_map before getting controller mappings from the driver
Sam Lantinga 345b4d7e 2020-05-29T13:37:21 Fixed bug 5161 - Autodetect controller mappings based on the Linux Gamepad Specification Jan Bujak I wrote a new driver for my gamepad on Linux. I'd like SDL to support it out-of-box, as currently it just treats it as a generic joystick instead of a gamepad. From what I can see the only way to do that is to either 1) pick one of the already supported controllers' PID, VID and button layouts and have my driver send that (effectively lying that it's something else), or 2) submit a preconfigured, hardcoded mapping to SDL. Both of those, in my opinion, are silly when we already have the Linux Gamepad Specification which standarizes this: https://www.kernel.org/doc/html/v4.15/input/gamepad.html Unfortunately SDL doesn't make use of it currently. So I've took it upon myself to add it; patch is in the attachments. Basically what the patch does is that if SDL finds no built-it controller mappings for a given joystick it then asks the joystick backend to autodetect it, and that uses the relevant evdev bits to figure out which button/axis is which. (See the specs for more details.) With this patch applied my own driver for my controller works out-of-box with SDL with no extra configuration and is correctly recognized as a gamepad; this is also going to be the case for any other driver which follows the Linux Gamepad Specification.
Ethan Lee 83cddd2e 2020-04-30T11:57:29 Add SDL_JoystickSetLED. Currently, this is only supported by the PS4 HIDAPI driver.
Ryan C. Gordon 67760f0e 2020-04-20T18:58:18 joystick: Don't report duplicate recentering events for game controllers.
Ryan C. Gordon c5f2a1ce 2020-04-20T16:01:36 joystick: On disconnect, recenter all game controller inputs. The joystick layer can't necessarily give us perfect centering, but we know that the game controller level has logical absolute idle positions that have nothing to do with the physical device. So send game controller events to make it look like the device is completely untouched before sending the final removal event.
Sam Lantinga aba27928 2020-04-18T21:41:37 Added a Windows Gaming Input joystick driver This driver supports the Razer Atrox Arcade Stick Some of the quirks of this driver, inherent in Windows Gaming Input: * There will never appear to be controllers connected at startup. You must support hot-plugging in order to see these controllers. * You can't read the state of the guide button * You can't get controller events in the background
Ryan C. Gordon 8c165add 2020-04-07T23:17:27 joystick: Remove force_centering flag; we handle this on disconnect now.
Sam Lantinga 4dea340c 2020-03-16T12:23:38 Fixed bug 4477 - Support more than 4 XInput-capable devices on Windows Jimb Esser Add new RawInput controller API, and improved correlation with XInput/WGI Reorder joystick init so drivers can ask the others if they handle a device reliably Do not poll disconnected XInput devices (major perf issue) Fix various cases where incorrect correlation could happen Simple mechanism for propagating unhandled Guide button presses even before guaranteed correlation Correlate by axis motion as well as button presses Fix failing to zero other trigger Fix SDL_HINT_JOYSTICK_HIDAPI not working if set before calling SDL_Init() Add missing device to device names Disable RawInput if we have a mismatch of XInput-capable but not RawInput-capable devices Updated to SDL 2.0.13 code with the following notes: New HID driver: xbox360w - no idea what that is, hopefully urelated SDL_hidapijoystick.c had been refactored to couple data handling logic with device opening logic and device lists caused some problems, yields slightly uglier integration than previously when the 360 HID device driver was just handling the data. SDL_hidapijoystick.c now often pulls the device off of the joystick_hwdata structure for some rumble logic, but it appears that code path is never reached, so probably not a problem. Looks like joystick_hwdata was refactored to not include a mutex in other drivers, maintainers may want to do the same refactor here if that's useful for some reason. Something changed in how devices get names, so getting generic names. Had to fix a (new?) bug where removing an XInput controller caused existing controllers (that moved to a new XInput index) to get identified as 0x045e/0x02fd ("it's probably Bluetooth" in code), rendering the existing HIDAPI_IsDevicePresent and new RAWINPUT_IsDevicePresent unreliable.
Sam Lantinga db3b3a1d 2020-03-12T19:47:28 Added support for SDL hints in the game controller mapping database
Sam Lantinga ad225047 2020-02-17T14:15:47 Added Android SDK conditionals to game controller mappings The Nintendo Switch Pro controller has a different mapping on Android 10 and newer
Sam Lantinga dc1d3c29 2020-02-04T18:36:23 Catch both PS3 and PS4 motion controls and don't treat them as a game controller
Sam Lantinga a8780c6a 2020-01-16T20:49:25 Updated copyright date for 2020
Sam Lantinga 46e1377d 2019-12-20T20:12:03 Automatically assign player indexes to game controllers, and allow changing the player index for game controllers and joysticks. Added the functions SDL_JoystickFromPlayerIndex(), SDL_JoystickSetPlayerIndex(), SDL_GameControllerFromPlayerIndex(), and SDL_GameControllerSetPlayerIndex()
Sam Lantinga 733f2525 2019-11-22T14:09:24 Fixed build
Sam Lantinga b5aff9d7 2019-11-22T13:12:12 Added SDL_GameControllerTypeForIndex() and SDL_GameControllerGetType() to return the type of controller attached.
Sylvain Becker 60d3965e 2019-10-30T15:36:17 Readability: remove redundant return, continue, enum declaration
Sylvain Becker 0f871c03 2019-10-23T09:53:23 Fixed bug 4843 - Passing NULL to memset in SDL_PrivateLoadButtonMapping (Thanks!)
Ozkan Sezer 7a47c292 2019-07-31T01:22:02 Fix bug 4746 - introduce SDL_zeroa macro.
Jimb Esser 0f148eb6 2019-03-16T18:12:26 Fix polling left trigger reporting right trigger's values.
Sylvain Becker 82b2c849 2019-01-21T23:41:43 Fixed bug 4024 - GameController error "Unexpected controller element" If mapping string is terminated with a comma, there is no more values to parse.
Sam Lantinga 7b354dda 2019-01-20T13:53:16 Fixed compiler warning
Sylvain Becker ede0fc4f 2019-01-16T14:03:35 Fixed bug 4024 - remove trailing comma of Controller mappings because it reports an error "Unexpected controller element"
Sam Lantinga 5e13087b 2019-01-04T22:01:14 Updated copyright for 2019
Sam Lantinga 98829d37 2018-12-11T19:50:58 Handle both "Sony Interactive Intertainment" and "Sony Computer Entertainment" when ignoring motion sensors
Sam Lantinga 70ce0f2e 2018-12-07T12:02:08 Added the hint SDL_HINT_GAMECONTROLLERCONFIG_FILE to specify a file to load at initialization containing SDL game controller mappings
Sam Lantinga db320e46 2018-12-04T14:21:29 Fixed the PS4 motion controls showing up as a separate game controller on Linux
Ryan C. Gordon 62494a2e 2018-10-31T15:03:41 Merge SDL-ryan-batching-renderer branch to default.
Sam Lantinga 14329256 2018-10-25T16:53:14 Generalized the XInput user index into a player index
Ryan C. Gordon b262b0eb 2018-10-22T20:50:32 Small stack allocations fall back to malloc if they're unexpectedly large.
Sam Lantinga 41ee51b9 2018-10-04T15:23:42 Fixed updating bindings for controllers using the wildcard mappings
Sam Lantinga 5febdfce 2018-09-24T11:49:25 Fixed whitespace
Sam Lantinga 59a2d12c 2018-09-17T11:35:22 Fixed creating an Android game controller mapping for HIDAPI devices on initialization
Sam Lantinga 6a7b0c27 2018-09-14T12:41:29 Fixed crash launching under Steam on Mac OS X
Sam Lantinga 96259f1f 2018-09-05T12:16:01 Don't overwrite the default binding when changing the binding for a controller that was using the default.
Sam Lantinga d2042e1e 2018-08-09T16:00:17 Added HIDAPI joystick drivers for more consistent support for Xbox, PS4 and Nintendo Switch Pro controller support across platforms. Added SDL_GameControllerRumble() and SDL_JoystickRumble() for simple force feedback outside of the SDL haptics API
Sam Lantinga 361043a5 2018-05-23T17:15:33 Actually left trigger is motion axis 17 and right trigger is motion axis 18, which will map in that order to SDL axes.
Sam Lantinga c07656db 2018-05-23T16:00:19 Fixed default mapping for Android controller triggers (they were reversed)
Sam Lantinga 999af809 2018-05-18T13:09:30 Merged latest changes from Steam Link app
Sam Lantinga b41b9d34 2018-03-19T14:52:53 Fixed return value
Sam Lantinga 8e062f69 2018-03-19T14:42:51 Generalized the handling of instantaneous guide button presses so there's a minimum of 100 ms between guide button press and release. This happens with at least the following controllers: All Apple MFI controllers, ASUS Gamepad, XiaoMi Bluetooth Controller
Sam Lantinga a8ac5885 2018-03-07T13:30:40 Added SDL_GameControllerMappingForDeviceIndex() to get the mapping for a controller before it's opened
Sam Lantinga 9e651b69 2018-03-06T14:51:50 Try to dynamically create a default Android game controller mapping based on the buttons and axes on the controller. Include the controller USB VID/PID in the GUID where possible, as we do on other platforms.
Sam Lantinga 003c0dce 2018-03-02T10:56:21 Use the real controller name for game controllers on iOS and Apple TV
Sam Lantinga e3cc5b2c 2018-01-03T10:03:25 Updated copyright for 2018
Sam Lantinga fee2469c 2017-12-19T10:48:29 Fixed bug 4005 - Android, SDL_IsGameController() crashes is index is out of range Sylvain On Android, if you give an invalid index to SDL_IsGameController(), it will crash in SDL_SYS_IsDPAD_DeviceIndex().
Sam Lantinga e5cfa241 2017-12-16T10:40:47 Fixed default Android D-PAD mapping so the back button is treated as B
Sam Lantinga a7d2d12c 2017-11-01T10:07:04 Fixed building on non-Android platforms
Sam Lantinga a90be440 2017-11-01T10:06:58 Added controller mapping for Android TV remotes Also fixed the back button on the remote exiting the application
Sam Lantinga d90fce3c 2017-10-10T11:10:15 Exposed the joystick locking functions for multi-threaded access to the joystick API
Sam Lantinga 2657dfae 2017-10-09T11:45:15 Fixed crash in SDL_IsGameController() on Windows if called when a controller is being removed
Sam Lantinga d8286479 2017-09-22T08:30:52 Added stubs for simple Steam Controller support
Sam Lantinga de91b124 2017-08-14T06:28:21 Fixed bug 3745 - specify SDLCALL as the calling convention for API callbacks Patches contributed by Ozkan Sezer
Sam Lantinga ca5c3048 2017-08-13T21:06:52 Fixed bug 3744 - missing SDLCALL in several functions Ozkan Sezer The attached patch adds missing SDLCALL to several functions, so that they properly match the headers as intended.
Sam Lantinga ea9bc659 2017-08-13T20:39:00 Added check for XBOX in addition to Xbox and X-Box
Sam Lantinga b425050b 2017-08-12T00:04:46 Fixed compiler warnings on Visual Studio 2013
Sam Lantinga 03250690 2017-08-09T12:38:20 Added a private hint for Steam to bypass the controller filtering for the Steam virtual gamepad
Sam Lantinga f15dbc8f 2017-08-09T12:11:59 Fixed Linux build
Sam Lantinga c49fa37c 2017-08-09T11:59:29 Added SDL hints to filter the set of game controllers reported by SDL
Ryan C. Gordon ca0bf151 2017-03-03T16:38:17 Fix some more compiler warnings on armcc.
Philipp Wiesemann 1e482095 2017-01-14T21:36:06 Fixed comments.
Sam Lantinga 45b774e3 2017-01-01T18:33:28 Updated copyright for 2017
Philipp Wiesemann af263798 2016-12-28T20:10:48 Fixed crash if allocating memory for game controller failed.
Sam Lantinga cb8685c0 2016-12-27T02:04:38 Fixed comment style
Sam Lantinga 6d7da088 2016-12-27T01:39:07 Split controller axes into positive and negative sides so each can be bound independently. Using this a D-Pad can be mapped to a thumbstick and vice versa. Also added support for inverted axes, improving trigger binding support
Sam Lantinga b4e069e7 2016-12-26T02:12:21 Fixed bug 3517 - Compiler warnings with gcc -Wstrict-prototypes felix Compiling even a simple SDL2 'hello world' program with gcc -Wstrict-prototypes (GCC 6.2.1) results in warnings like: /usr/include/SDL2/SDL_gamecontroller.h:143:1: attention : function declaration isn't a prototype [-Wstrict-prototypes] extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(); ^~~~~~ It seems there is a missing 'void' between the parentheses.
Sam Lantinga ca019dad 2016-12-22T17:33:45 Fixed issue where the throttle and other axes on racing wheels don't start at zero and show up as immediate input when the wheel is turned for the first time. Wait until they are actually moved before generating input from them.
Sam Lantinga a5250171 2016-12-08T10:13:45 Protect the game controller API the same way the joystick API is protected from multi-threaded access
Sam Lantinga d834c08a 2016-11-29T22:02:37 Add the controller mappings to the linked list in order
Sam Lantinga dd5d85a4 2016-11-29T06:36:57 Added an API to iterate over game controller mappings
Philipp Wiesemann eb9cc030 2016-11-19T23:27:37 Fixed two memory leaks if added game controller mapping has lower priority. Found by buildbot.
Sam Lantinga 57d01d7d 2016-11-13T22:57:41 Patch from Sylvain to fix clang warnings
Sam Lantinga 23c01c18 2016-11-11T13:29:23 Fixed bug 3079 - Allow non destructive SDL_GameControllerAddMappingsFromFile x414e54 It is a bit of a pain to update the library or rely on whatever version the user has on their computer for default mappings. So providing an easily updatable text file via SDL_GameControllerAddMappingsFromFile is still currently the most viable way. However using this replaces all mappings provided by the SDL_HINT_GAMECONTROLLERCONFIG environment variable which may have come from the user's custom Steam mapping. There should be an easy way for games to supply extra game controller mappings to fill in the differences between SDL versions without it clobbering the SDL_HINT_GAMECONTROLLERCONFIG environment variable. Internally the mappings could use a priority system and if the priority is lower then it will not overwrite the mappings. For now it just assumes SDL_HINT_GAMECONTROLLERCONFIG is the highest priority, the default hardcoded are the lowest and anything set via the API is medium.
Sam Lantinga 160e7194 2016-11-11T04:35:06 Fixed whitespace and added code to support older game controller GUIDs
Sam Lantinga ac74e16c 2016-11-10T17:19:34 Standardized the format of the SDL joystick GUID and added functions to retrieve the USB VID/PID from a joystick and game controller.
Sam Lantinga 89abbbfe 2016-10-07T18:24:34 Fixed bug 3438 - SDL_GameControllerEventWatcher: Log on event with value >= k_nMaxReverseEntries
Sam Lantinga 8bc5c57d 2016-10-07T16:13:37 Fixed recentering triggers when the application doesn't have focus
Sam Lantinga 72164985 2016-10-07T16:04:15 Fixed bug 2823 - Release events for triggers receive wrong centered value Ryochan7 I have been using SDL 2 for a little project that I have been developing for a while. My project is called antimicro and it takes gamepad input and then translates gamepad events into keyboard and mouse events. SDL is used to read the input from an XInput gamepad and it works great for the most part. However, there is one glaring problem that I have encountered. When a device is unplugged and SDL sends the centered value release events for all axes, buttons, and hats, SDL does not use the proper centered value for the triggers. It pushes an SDL_JOYAXISMOTION event onto the queue with a value of 0 for all axes. That value is converted to around 16,000 for a Game Controller. That value is incorrect for triggers and, in my program, that causes any bindings that are assigned to the triggers to get activated. With most profiles, that will typically mean that a mouse right click and left click will be activated before the device is finally seen as removed and then those bindings are released by antimicro.
Sam Lantinga c2e25651 2016-10-01T13:02:20 Fixed bug 3424 - SDL_GameController: Increase k_nMaxReverseEntries ny00 On Android, the keycodes KEYCODE_BUTTON_1..16 (actual values 188-203) are translated to SDL_Joystick buttons no. 20-35. These are currently ignored in SDL_gamecontroller.c. The attached patch fixes this, by increasing k_nMaxReverseEntries from 20 to another arbitrary bound of 48. Side-note: Maybe some log should be emitted in case of going over any such bound?
Sam Lantinga ad1bfea5 2016-08-26T12:18:08 Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved() Updated the removal code to iterate over all joystick add messages instead of just the first one.
Sam Lantinga c69bce67 2016-08-26T11:16:44 commit 1170112da3776fdb06425f62d57b63144c33dc51 Author: James Zipperer <james.zipperer@synapse.com> Date: Sun Aug 21 01:19:19 2016 -0700 bugfix for controller / joystick add / remove being in the event queue at the same time
Ethan Lee 2a754ca7 2016-03-07T08:22:55 Allow mappings to be added before GameControllerInit
Sam Lantinga 42065e78 2016-01-02T10:10:34 Updated copyright to 2016
Sam Lantinga d1e6a2eb 2015-12-09T12:11:40 Added broad support for wireless XBox 360 controllers on Linux
Ryan C. Gordon e6ad29ae 2015-11-14T12:35:45 Added SDL_JoystickFromInstanceID() and SDL_GameControllerFromInstanceID().
Philipp Wiesemann 0e45984f 2015-06-21T17:33:46 Fixed crash if initialization of EGL failed but was tried again later. The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly uninitialized data structure if loading the library first failed. A later try to use EGL then skipped initialization and assumed it was previously successful because the data structure now already existed. This led to at least one crash in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was dereferenced to make a call to eglBindAPI().
Sam Lantinga 2c4a6ea0 2015-05-26T06:27:46 Updated the copyright year to 2015
Sam Lantinga 094c4a16 2015-05-13T22:37:26 Added generic xinput fallback for XBox compatible controllers on Linux
Ryan C. Gordon b72938c8 2015-04-20T12:22:44 Windows: Always set the system timer resolution to 1ms by default. An existing hint lets apps that don't need the timer resolution changed avoid this, to save battery, etc, but this fixes several problems in timing, audio callbacks not firing fast enough, etc. Fixes Bugzilla #2944.
Alex Szpakowski fe6c797c 2015-04-10T23:30:31 Fixed an iOS view orientation issue when SDL_GL_CreateContext or SDL_CreateRenderer is called.
Edward Rudd b88ca1b4 2015-02-10T16:28:56 the last parameter of XChangeProperty is the number of elements.. and when the element format is 32.. the element is "long" so we have 5 long elements here. Yes this seems confusing as on mac+linux Long is either 32 or 64bits depending on the architecture, but this is how the X11 protocol is defined. Thus 5 is the correct value for the nelts here. Not 5 or 10 depending on the architecture. More info on the confusion https://bugs.freedesktop.org/show_bug.cgi?id=16802
Philipp Wiesemann b48e54aa 2015-01-26T22:00:29 Fixed bug 2802 - [patch] Fix android build compiling in wrong filesystem implementation Jonas Kulla The configure script didn't differentiate between Linux and Android, unconditionally compiling in the unix implementation of SDL_sysfilesystem.c. I'm probably one of the very few people building SDL for android using classic configure + standalone toolchain, so this has gone undetected all along.
Ryan C. Gordon fe40a172 2014-12-18T00:19:52 Initial merge of Emscripten port! With this commit, you can compile SDL2 with Emscripten ( http://emscripten.org/ ), and make your SDL-based C/C++ program into a web app. This port was due to the efforts of several people, including: Charlie Birks, Sathyanarayanan Gunasekaran, Jukka Jyl?nki, Alon Zakai, Edward Rudd, Bruce Mitchener, and Martin Gerhardy. (Thanks, everyone!)
David Ludwig 70438be2 2014-12-03T10:55:23 WinRT: fixed bug whereby SDL would override an app's default orientation WinRT apps can set a default, preferred orientation via a .appxmanifest file. SDL was overriding this on app startup, and making the app use all possible orientations (landscape and portrait). Thanks to Eric Wing for the heads up on this!
Philipp Wiesemann 9c398852 2014-11-22T22:20:40 Corrected header file documentation comment.