230 Commits

Author SHA1 Message Date
Sam Lantinga
3607f8316f 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
2022-10-03 11:02:23 -07:00
Sam Lantinga
a3900a751e Lock joysticks when removing a controller on the WGI thread 2022-09-08 13:59:25 -07:00
Sam Lantinga
0ad8d9d292 SDL_IsXInputDevice() shouldn't return true if XInput isn't enabled 2022-09-07 15:31:24 -07:00
Sam Lantinga
e5f161bda4 Restored accidentally removed code to guess XInput device 2022-08-30 19:12:22 -07:00
Ozkan Sezer
973a677a2d SDL_xinputjoystick.c: commented out GuessXInputDevice()
Not used since commit 277b033e78235d6ffad7525a1fb9acfef3a43433.
2022-08-31 02:32:28 +03:00
Shawn Hoffman
42d09a8f42 wgi: refcount the delegate objects 2022-08-30 15:01:31 -07:00
Shawn Hoffman
ca915b1884 WGI_JoystickUpdate: bounds-check array sizes 2022-08-30 14:59:38 -07:00
Sam Lantinga
92d3fc4883 Fixed deadlock when shutting down the Windows joystick system 2022-08-30 12:59:02 -07:00
Sam Lantinga
675d90c708 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.
2022-08-30 12:09:57 -07:00
Sam Lantinga
40bd4feedc 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
2022-08-30 11:42:13 -07:00
Shawn Hoffman
ff233fe306 wgi: refcount the delegate objects
assert if calls become unbalanced.
2022-08-30 10:48:10 -07:00
Cameron Gutman
b7c1fbf9f0 WGI: Fix a couple of reference leaks 2022-08-28 17:38:02 -05: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
Your Name
cfbeb438c1 fix a bug if XINPUTGETBATTERYINFORMATION is nullptr 2022-08-12 10:07:35 -04:00
Shawn Hoffman
5aa438e80a WGI: fix interop with applications that have their own WGI code
QI for Added/Removed events need to handle IAgileObject
2022-08-08 15:53:57 -07:00
Sam Lantinga
12aa4d5653 Added header needed for SDL_Delay() 2022-08-01 11:11:25 -07:00
Sam Lantinga
aeb275149a Poll DirectInput devices to get their initial state
Fixes https://github.com/libsdl-org/SDL/issues/3816
2022-08-01 10:39:56 -07:00
chalonverse
f317d619cc
Xbox GDKX support (#5869)
* Xbox GDK support (14 squashed commits)

* Added basic keyboard testing

* Update readme

* Code review fixes

* Fixed issue where controller add/removal wasn't working (since the device notification events don't work on Xbox, have to use the joystick thread to poll XInput)
2022-07-01 13:59:14 -07:00
Jade Macho
6a2e6c82a0 Add SDL_HINT_DIRECTINPUT_ENABLED (on by default) 2022-06-28 15:59:05 -07:00
Sam Lantinga
16f55fbdb4 Separate the controller protocol from the controller style
This allows us to handle controllers that use the Xbox protocol but look like Nintendo Switch or Playstation controllers, like the Qanba Dragon Arcade Stick in PC mode
2022-06-15 20:46:01 -07:00
Ozkan Sezer
714502d373 minor windows warning fixes. 2022-06-13 22:15:56 +03:00
Sam Lantinga
d2c4d74dd0 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**
2022-05-27 15:49:35 -07:00
Sam Lantinga
bd22ca762e 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.
2022-05-27 15:40:50 -07:00
Sam Lantinga
efdf43aa9b Workaround for compiling with MinGW-w64
Fixes bug https://github.com/libsdl-org/SDL/issues/5589
2022-05-27 15:34:45 -07:00
Sam Lantinga
b28d304b23 Only include controller_type.h in SDL_joystick.c
It has a huge array of controllers and we only want it instantiated once
2022-05-24 17:24:54 -07:00
Cameron Cawley
0cca71a846 Use SDLCALL for callbacks in public APIs 2022-05-18 15:01:27 -07:00
Ozkan Sezer
3f813cf1ef SDL_rawinputjoystick.c: fixed -Werror=declaration-after-statement 2022-05-04 10:05:56 +03:00
Jan200101
bb0b6dd42e Fixed using WGI without XInput 2022-05-02 11:33:55 -07:00
Sam Lantinga
e551384a99 Added functions to get the platform dependent name for a joystick or game controller 2022-04-26 14:54:14 -07:00
Dimitriy Ryazantcev
c39df2fb0c joystick: get HID top-level collection preparsed data directly from RawInput API. 2022-04-26 09:48:35 -07:00
Mathieu Eyraud
0b2a55ea7d Fix typo 2022-04-25 15:46:17 -07:00
meyraud705
0964c84d77 Always use SDL_PrivateJoystickBatteryLevel to update battery level
But do not use it for initialisation.
2022-04-25 15:46:17 -07:00
Sam Lantinga
04bf7c9434 Fixed build 2022-04-22 09:36:39 -07:00
Sam Lantinga
d9b5805ba5 Return a correlation error when trigger rumble is attempted without correlation 2022-04-22 09:13:40 -07:00
Cameron Gutman
145824f6ab WGI: Only call RoUninitialize() if RoInitialize() succeeded 2022-04-21 08:47:22 -07:00
Cameron Gutman
00b2e10a7a WGI: Keep a reference to the MTA to avoid crashing on COM teardown
Fixes #5552
Fixes #5270
2022-04-21 08:47:22 -07:00
Ozkan Sezer
312c899f4f attempt to fix uwp build 2022-04-02 03:32:10 +03:00
Sam Lantinga
8ebef12d31 Use RoInitialize/RoUninitialize for Windows.Gaming.Input
Thanks @walbourn!

Fixes https://github.com/libsdl-org/SDL/issues/5270
2022-04-01 14:59:45 -07:00
Sam Lantinga
006aafabcf Fixed freeing a constant string (thanks @gnrlwart) 2022-03-22 20:24:17 -07:00
Sam Lantinga
1868c5b521 Start rumbling once a raw input controller has been correlated
Fixes https://github.com/libsdl-org/SDL/issues/5351
2022-03-17 18:25:50 -07:00
Sam Lantinga
b22ce2b5a8 Workaround for bug in Microsoft WGI support
Fixes https://github.com/libsdl-org/SDL/issues/5270
2022-03-17 17:10:40 -07:00
Cameron Gutman
677dc1015c rawinput: Fix double detection of gamepads on some 3rd party X360 wireless receivers
The name that the Raw Input joystick driver pulls from the HID stack comes
from USB string descriptors contained on the device. For official wireless
receivers, this always contains "Xbox 360 Wireless Receiver for Windows"
which matches the friendly name that WGI provides.

3rd party Xbox 360 wireless receivers may have different strings in their
USB string descriptors (one uses "XBOX 360 For Windows" instead). This
fails to match WGI's name and causes Raw Input and WGI to both report the
same gamepad.

Since wireless Xbox 360 controllers seem to have a consistent VID/PID
regardless of the adapter enumerating them, we can also match on that to
catch these.

The duplicate case reported to me was:
Controller (XBOX 360 For Windows) - 030000005e040000a102000000007200
Xbox 360 Wireless Receiver for Windows - 030000005e0400000000000000007701
2022-03-09 21:19:53 -08:00
Sam Lantinga
9299a3e796 Workaround for crash in CoUninitialize() 2022-02-21 16:24:45 -08:00
Sam Lantinga
f97a29f6e1 Use the real device VID/PID when seeing the Steam virtual controller 2022-02-11 22:10:33 -08:00
Ryan C. Gordon
43f0271b4e 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.
2022-01-28 20:40:19 -05:00
pionere
d7110b4490 fix compiler warnings in SDL_windows_gaming_input.c 2022-01-28 20:40:19 -05:00
Sam Lantinga
67cb548bef Fixed build error with C90 compilers 2022-01-20 19:31:54 -08:00
Carl Glave
a23b3c767f Add support for correlating trigger input 2022-01-20 17:43:35 -08:00
Cameron Gutman
d73bd0d2f6 dinput: Don't crash in SDL_DINPUT_JoystickPresent if DInput init failed
The WGI driver will call this regardless of whether our init succeeded.
2022-01-04 15:53:39 -08:00