Commit graph

106 commits

Author SHA1 Message Date
Sylvain c5c94a6be6 Change return type from void to int, for functions that set an error
(SDL_SetError(), SDL_OutOfMemory(), SDL_Unsupported(), SDL_InvalidParam())

Update prototype to forward errors to generic layer, for the functions:
MoveCursor, WarpMouse, GL_DeleteContext, GetDisplayModes.

Check invalid parameter in SDL_SetTextInputRect() generic layer.
2023-02-07 13:51:45 -08:00
happyharryh 57e78f4cf5 Fixed the hat_map to avoid segmentation fault 2023-01-12 06:55:35 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Sylvain Becker d7d3c22dbf
Remove more reserved identifiers (#6925) 2022-12-29 13:58:16 -08:00
Sam Lantinga 36d4395c97 SDL API renaming: internal functions 2022-12-27 15:05:51 -08:00
Sam Lantinga 659abc721a SDL API renaming: SDL_gamecontroller.h
SDL_gamecontroller.h has been renamed SDL_gamepad.h, and all APIs have been renamed to match.

Fixes https://github.com/libsdl-org/SDL/issues/6885
2022-12-27 09:47:24 -08:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Sam Lantinga e8b1dfef9b Fixed centering the D-pad on some joysticks
Fixes https://github.com/libsdl-org/SDL/issues/6767
2022-12-05 13:33:04 -08:00
Sam Lantinga d3ba6529e6 Fixed windows build 2022-12-04 09:39:55 -08:00
Sam Lantinga b8760a3ffe The timestamp_us member of the sensor events has been renamed sensor_timestamp and now represents nanoseconds. 2022-12-04 09:29:28 -08:00
Sam Lantinga 73f4aeee6a Pass the event timestamp for joystick events
This allows the application to get more fine grained information about controller event timing, and group events that happened together.
2022-12-04 09:29:28 -08:00
Sam Lantinga 8121bbd083 Convert ticks to 64-bit, added nanosecond precision to the API
Fixes https://github.com/libsdl-org/SDL/issues/5512
Fixes https://github.com/libsdl-org/SDL/issues/6731
2022-12-02 12:37:41 -08:00
Pierre Wendling 3c501b963d
Clang-Tidy fixes (#6725) 2022-12-01 13:07:03 -08:00
Sam Lantinga 5750bcb174
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
2022-11-30 12:51:59 -08:00
Sam Lantinga c5790359fd
Added precompiled header support for Visual Studio and Xcode (#6710)
Fixes https://github.com/libsdl-org/SDL/issues/6704
2022-11-29 18:34:15 -08:00
Sylvain Becker 6a2200823c
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
2022-11-27 08:38:43 -08:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -08:00
Sam Lantinga a635a485bc Re-added WinRT support until we're sure that it's no longer being used 2022-11-23 10:41:43 -08:00
Ozkan Sezer dc2a3e06e9 removed WinRT support. 2022-11-22 23:36:24 +03:00
Sam Lantinga 8b20b568b0 Don't report battery level for disconnected batteries
Fixes https://github.com/libsdl-org/SDL/issues/6536
2022-11-21 07:42:14 -08:00
Sam Lantinga 0bc852ce53 Revert "Disable the RAWINPUT joystick driver by default"
Disabling RAWINPUT on Windows 10 causes these issues:
* All Xbox controllers are named "XInput Controller".
* Trigger rumble no longer works.
* "XInput Controllers" are now also listed as separate haptic devices
2022-10-17 17:43:06 -07:00
Sam Lantinga 47ba997f06 Disable the RAWINPUT joystick driver by default
It's only needed to support more than 4 Xbox controllers, and adds significant complexity to the joystick processing, and we regularly get bugs from people who aren't using an SDL window who need to turn on SDL_HINT_JOYSTICK_THREAD.
2022-10-17 07:39:52 -07:00
Sam Lantinga 5025f24033 Don't use RAWINPUT joystick driver on Windows XP
Fixes https://github.com/libsdl-org/SDL/issues/6400
2022-10-17 07:35:00 -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
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
Ozkan Sezer 714502d373 minor windows warning fixes. 2022-06-13 22:15:56 +03: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
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 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 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
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Mathieu Eyraud 02021ae753 Return capabitlities from RawInput joystick 2021-11-27 07:26:10 -05:00
Sam Lantinga 67b5de5b41 Fixed build warnings 2021-11-26 10:18:08 -08:00
Sylvain 6fb50bd0a6 Don't use "exp" as a name so that it's doesn´t show up with searching for the function 2021-11-22 08:38:46 -08:00