src/joystick/windows/SDL_windows_gaming_input.c


Log

Author Commit Date CI Message
Pierre Wendling d0bbfdbf 2022-12-01T16:07:03 Clang-Tidy fixes (#6725) (cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd)
Sam Lantinga b8d85c69 2022-11-30T12:51:59 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 5750bcb174300011b91d1de20edb288fcca70f8c)
Sylvain Becker fb0ce375 2022-11-27T17:38:43 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 6a2200823c66e53bd3cda4a25f0206b834392652 to reduce conflicts merging between SDL2 and SDL3)
Sam Lantinga b7e65a81 2022-11-11T08:57:07 Fixed incorrect WGI controller state when the application loses focus Recenter the controller elements when WGI stops reporting valid state Fixes https://github.com/libsdl-org/SDL/issues/5261
Sam Lantinga 3607f831 2022-10-03T11:00:50 Find out if a controller is wireless using WGI (thanks @DJm00n!) Confirmed using an Xbox Series X controller over USB and Bluetooth Fixes https://github.com/libsdl-org/SDL/issues/6322
Sam Lantinga a3900a75 2022-09-08T13:59:25 Lock joysticks when removing a controller on the WGI thread
Shawn Hoffman 42d09a8f 2022-08-30T13:54:32 wgi: refcount the delegate objects
Shawn Hoffman ca915b18 2022-08-30T13:54:58 WGI_JoystickUpdate: bounds-check array sizes
Sam Lantinga 675d90c7 2022-08-30T12:09:07 Revert "wgi: refcount the delegate objects" This reverts commit ff233fe3060e51706937a7b366438403bce774a4. This doesn't compile cleanly with Visual Studio and I don't want to introduce any subtle issues because we're passing the wrong types of pointers to WGI functions.
Sam Lantinga 40bd4fee 2022-08-30T11:42:13 Revamped joystick locking This makes the joystick locking more robust by holding the lock while updating joysticks. The lock should be held when calling any SDL joystick function on a different thread than the one calling SDL_PumpEvents() and SDL_JoystickUpdate(). It is now possible to hold the lock while reinitializing the joystick subsystem, however any open joysticks will become invalid and potentially cause crashes if used afterwards. Fixes https://github.com/libsdl-org/SDL/issues/6063
Shawn Hoffman ff233fe3 2022-08-28T22:20:58 wgi: refcount the delegate objects assert if calls become unbalanced.
Cameron Gutman b7c1fbf9 2022-08-28T17:38:02 WGI: Fix a couple of reference leaks
Sam Lantinga 277b033e 2022-08-22T19:28:21 Refactor joystick GUID creation
Sam Lantinga c1e08739 2022-08-22T16:46:55 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
Shawn Hoffman 5aa438e8 2022-08-08T14:52:19 WGI: fix interop with applications that have their own WGI code QI for Added/Removed events need to handle IAgileObject
Sam Lantinga d2c4d74d 2022-05-27T15:49:35 Fixed build with MinGW-64 windows.devices.power.h The MinGW-64 header defines the parameters as ABI::Windows::Foundation::IReference<INT32 > **, but the Windows header defines the parameters as __FIReference_1_int**
Sam Lantinga bd22ca76 2022-05-27T15:40:50 Revert "Workaround for compiling with MinGW-w64" This reverts commit efdf43aa9b4f4d623ffba01f503d9793d5021330. The broken mingw headers aren't in an official release yet, so reporting this upstream.
Sam Lantinga efdf43aa 2022-05-27T15:34:45 Workaround for compiling with MinGW-w64 Fixes bug https://github.com/libsdl-org/SDL/issues/5589
Sam Lantinga e551384a 2022-04-26T14:54:14 Added functions to get the platform dependent name for a joystick or game controller
Cameron Gutman 145824f6 2022-04-21T01:38:53 WGI: Only call RoUninitialize() if RoInitialize() succeeded
Cameron Gutman 00b2e10a 2022-04-20T20:58:29 WGI: Keep a reference to the MTA to avoid crashing on COM teardown Fixes #5552 Fixes #5270
Sam Lantinga 8ebef12d 2022-04-01T14:58:33 Use RoInitialize/RoUninitialize for Windows.Gaming.Input Thanks @walbourn! Fixes https://github.com/libsdl-org/SDL/issues/5270
Sam Lantinga 006aafab 2022-03-22T20:23:09 Fixed freeing a constant string (thanks @gnrlwart)
Sam Lantinga b22ce2b5 2022-03-17T17:10:40 Workaround for bug in Microsoft WGI support Fixes https://github.com/libsdl-org/SDL/issues/5270
Ryan C. Gordon 43f0271b 2022-01-24T08:56:33 Revert "fix compiler warnings in SDL_windows_gaming_input.c" This reverts commit ca36cdb185f2f26241598068927821896f36b904. The older Windows SDK's headers are wrong, and this change would crash if you hotplug a device.
pionere d7110b44 2022-01-08T12:07:16 fix compiler warnings in SDL_windows_gaming_input.c
Sam Lantinga 120c76c8 2022-01-03T09:40:00 Updated copyright for 2022
Sam Lantinga dd2f9111 2021-11-27T20:18:29 Fixed warnings with Windows SDK 10.0.19041 Fixes https://github.com/libsdl-org/SDL/issues/4998 Also breaks https://github.com/libsdl-org/SDL/issues/4998 for older SDKs, but we're going to ignore them, they're just incorrect.
Sam Lantinga c2904c8c 2021-11-27T11:16:15 Fixed compile warnings and errors Fixes https://github.com/libsdl-org/SDL/issues/4998
Sam Lantinga 09b7ca27 2021-11-27T10:53:20 Get the current WGI controller list at startup On Win32 this list is empty and we always get controller added events. On UWP, this list is populated and we don't get controlle added events for currently connected controllers.
Sam Lantinga 12895eca 2021-11-27T10:52:58 Fixed WGI initialization on Win32
Sam Lantinga 110e4e13 2021-11-27T10:24:32 Use WGI instead of XInput for Windows 10 UWP apps Fixes https://github.com/libsdl-org/SDL/issues/5017
Sam Lantinga 2ca2ad76 2021-11-26T10:13:45 Fixed build warnings
Ozkan Sezer 3eb9bfac 2021-11-14T22:22:50 win32 rawinput & wgi joystick: avoid -Werror=declaration-after-statement
Cameron Gutman afccabb8 2021-11-11T12:12:05 joystick: Add capability flags for rumble and trigger rumble When API limitations force us to guess, we favor a false positive (reporting support when it doesn't exist) compared to a false negative.
Cameron Gutman 1ccfbf96 2021-11-11T11:13:08 joystick: Convert HasLED() into a generic GetCapabilities() function
Cameron Gutman f6dc47ca 2021-11-07T16:00:47 WGI/DInput: Fix SDL_IsXInputDevice() checks when RawInput is enabled Enabling the RawInput backend causes SDL_XINPUT_Enabled() to return false. That causes WGI and DInput backends to take ownership of XInput-compatible controllers, because they think there's no XInput-specific backend enabled. In WGI's case, it will actually race with RawInput to open the device. By properly excluding XInput devices from WGI, we can ensure that the sets of devices managed by WGI and RawInput don't intersect. This makes the race harmless, since they'll never both go after the same device.
Cameron Gutman b3e909dc 2021-11-07T13:51:34 WGI: Fix SDL_IsXInputDevice() for Xbox One controllers The Xbox One driver stack doesn't propagate the VID/PID down to the HID devices that end up in the GetRawInputDeviceList() output. This means we end up matching against the wrong VID/PID and can't properly exclude Xbox One controllers from WGI. Fortunately, it is possible to walk back up the device tree to find the parent with the matching VID/PID.
Cameron Gutman 6312aaea 2021-11-06T21:52:22 WGI: Add workaround for delayed callbacks after WGI_JoystickQuit()
Sam Lantinga 02223501 2021-08-02T16:40:58 Fixed crash if WGI didn't give us the name for a controller
Sam Lantinga 9d457aa4 2021-07-29T14:24:40 Don't uninitialize COM because of what appears to be a bug in Microsoft WGI reference counting. This fixes https://github.com/libsdl-org/SDL/issues/4488
Sam Lantinga d135c076 2021-07-08T13:22:41 Added SDL_GameControllerSendEffect() and SDL_JoystickSendEffect() to allow applications to send custom effects to the PS4 and PS5 controllers See testgamecontroller.c for an example of a custom PS5 trigger effect
Ozkan Sezer a594b850 2021-01-04T10:00:30 use WIN_StringToUTF8W macro instead of WIN_StringToUTF8, where needed: i.e. where the string is known guaranteed to be WCHAR*, in: - SDL_dinputjoystick.c (WIN_IsXInputDevice): VARIANT->var is BSTR (WCHAR*) - SDL_rawinputjoystick.c (RAWINPUT_AddDevice): string is WCHAR* - SDL_windows_gaming_input.c (IEventHandler_CRawGameControllerVtbl_InvokeAdded): string is WCHAR* There should be more of these..
Ozkan Sezer 398d2764 2021-01-04T01:23:50 RAWINPUT_InitWindowsGamingInput: change pNamespace from LPTSTR to PCWSTR because WindowsCreateStringReference specifically accepts const WCHAR * - WGI_JoystickInit(): ditto. cf. bug #5435.
Sam Lantinga 9130f7c3 2021-01-02T10:25:38 Updated copyright for 2021
Sam Lantinga 797a6910 2020-12-09T20:28:51 Fixed bug 5375 - WGI: Fix HSTRING memory leak. Joel Linn TLDR; https://godbolt.org/z/43fd8G Let's deduce this from C++ reference code: https://docs.microsoft.com/en-us/cpp/cppcx/wrl/how-to-activate-and-use-a-windows-runtime-component-using-wrl?view=msvc-160 At the bottom of the page there is this snippet: ``` int wmain() { /* ... more code ... */ // Get the domain part of the URI. HString domainName; hr = uri->get_Domain(domainName.GetAddressOf()); if (FAILED(hr)) { return PrintError(__LINE__, hr); } // Print the domain name and return. wprintf_s(L"Domain name: %s\n", domainName.GetRawBuffer(nullptr)); // All smart pointers and RAII objects go out of scope here. } ``` `HString` is defined in `corewrappers.h` and the call chain for the destructor is: `~HString() -> Release() -> ::WindowsDeleteString()` QED
Sam Lantinga f2fff217 2020-12-09T06:24:40 Fixed bug 5374 - WGI: Use fast-pass strings. Joel Linn Eliminate additional heap allocation for short-lived HSTRINGs. Uses `WindowsCreateStringReference()` to disable reference counting and memory management by the Window Runtime.
Sam Lantinga 8a449de2 2020-11-27T10:44:47 Fixed Xbox 360 wireless controller being picked up by WGI when it's being managed by RAWINPUT
Sam Lantinga 2931eccd 2020-11-27T05:53:52 Fixed detecting Bluetooth raw input devices, which have device names longer than 128 characters
Sam Lantinga 5b3616c3 2020-11-23T18:24:05 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.
Sam Lantinga fcb21aa8 2020-11-17T10:30:20 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
Sam Lantinga 502cfe31 2020-11-11T19:39:46 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.
Sam Lantinga 1e2caac5 2020-11-11T18:57:37 Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers()
Sam Lantinga 4ea1a10b 2020-11-07T02:49:22 Added stub controller LED functions for WGI and RAWINPUT (thanks meyraud!)
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.
Sam Lantinga 01fd8130 2020-04-23T11:13:02 Fixed compiler warning
Sam Lantinga 4727f794 2020-04-23T10:13:17 Don't use the WGI driver if another driver is already handling the joystick
Sam Lantinga 6ca7f510 2020-04-23T09:35:32 Fixed crash trying to get battery status on some devices
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