Commit Graph

3491 Commits

Author SHA1 Message Date
Cameron Gutman
77b0dad271 cocoa: Change Caps Lock behavior to toggle instead of locking
It currently behaves like a locking key which is pressed
when Caps Lock is enabled and released when disabled. This
means that apps that trigger events on Caps Lock key down will
only fire these events every other time Caps Lock is pressed.
2020-05-25 20:55:29 -07:00
Sam Lantinga
bdfd1b68ba Fixed bug 5146 - SDL_RenderFillRect doesn't work in DirectFB
Lacky

It looks like refactoring of SDL2 internal API has broken SDL_RenderFillRect for DirectFB. In new version function SDL_RenderFillRect returns 0, but rectangle is not visible.

Replacing "count" with "len" in the argument list for SDL_memcpy in DirectFB_QueueFillRects fixes problem.
2020-05-29 16:02:49 -07:00
Tudor Brindus
a6ca61d732 wayland: update pointer position on initial enter event 2020-05-21 00:06:09 -04:00
Sam Lantinga
ae9ff11bae The zero happens at a higher level now 2020-05-29 14:54:07 -07:00
Sam Lantinga
39c958bbaa Initialize the raw_map before getting controller mappings from the driver 2020-05-29 14:48:39 -07:00
Sam Lantinga
2db049473b Fixed variable names to be consistent across functions 2020-05-29 14:48:05 -07:00
Sam Lantinga
345b4d7e14 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.
2020-05-29 13:37:21 -07:00
James Legg
e2dbed9cfe SDL_blit: Fix undefined bitshift operations
Arithmatic operations promote Uint8 to signed int. If the top bit of a
Uint8 is set, and it is left shifted 24 places, then the result is not
representable in a signed 32 bit int. This would be undefined behaviour
on systems where int is 32 bits.
2020-05-29 13:05:37 +01:00
Brendan Shanks
032fa681a8 Add Logitech G29 to steering wheel list 2020-04-24 14:03:30 -07:00
Ryan C. Gordon
aa259ed52d wayland: Changed output removal in handle_surface_leave()
No longer needs an extra malloc, handles unexpected cases like the same
output being listed twice.
2020-05-28 15:18:41 -04:00
Ryan C. Gordon
ce7ae4ec8d wayland: Move buffer copy into mime_data_list_add()
It makes it clearer who owns the memory, and more reasonable to free it on
failure in the creating function.

(and, of course, pacifies static analysis.)
2020-05-28 14:57:10 -04:00
Ryan C. Gordon
22da9d4d77 wayland: assert that mmap() didn't return NULL.
In practice, it never _would_, but in theory it _might_, so this assertion
tells the static analyzer not to worry about it.
2020-05-28 14:47:55 -04:00
Sam Lantinga
1a1f1704a2 Don't include the iOS joystick driver if joysticks are disabled 2020-05-27 10:35:43 -07:00
Sam Lantinga
57149c2410 Fixed building with --disable-joystick on iOS 2020-05-27 10:27:20 -07:00
Sam Lantinga
cf01ee1694 Fixed building with --disable-joystick on Linux 2020-05-27 10:27:04 -07:00
Sam Lantinga
e9f567c707 Fixed building on iOS with MFI controllers disabled 2020-05-27 10:14:08 -07:00
Sam Lantinga
97ca96bdee Use nil instead of NULL for Objective-C objects 2020-05-27 10:13:01 -07:00
Sam Lantinga
03a7abf80c Fixed building with --disable-joystick on macOS 2020-05-27 09:57:26 -07:00
Sam Lantinga
af5eb56c76 Fixed uninitialized variable warning 2020-05-27 09:28:03 -07:00
Sam Lantinga
31916f11aa Fixed compiler warning building on FreeBSD 2020-05-27 09:22:12 -07:00
Sam Lantinga
bcbaa4ec1f If there isn't a GetGlobalMouseState() implementation, fall back to the normal one. 2020-05-26 16:34:50 -07:00
Sam Lantinga
437577f91e Fixed bug 5141 - KMSDRM: manage SDL_GetGlobalMouseState()
Manuel Alfayate Corchete

On the KMSDRM backend, there is no such thing as a desktop, yet some programs could (and DO) use SDL_GetGlobalMouseState().
So I think its good idea that, in KMSDRM, it returns the same mouse coordinates anyway as SDL_GetMouseState() would return. There is nothing else it could return, as far as I can understand, since there is no desktop anyway.
This small patch does precisely that.
2020-05-26 16:29:26 -07:00
Sam Lantinga
1df0a1e497 Fixed bug 5140 - KMSDRM: Dynamic vsync toggle does not work
Manuel Alfayate Corchete

The KMSDRM backend was doing things wrong because of some small (but important) misconceptions on how KMS/DRM works: to implement a largely broken non-vsync refresh mechanism, the SwapWindow() function was issuing new pageflips before previous ones had completed, thus causing EBUSY returns, buffer mismanagement, etc... resulting in general breakage on vsync disabling from apps, that would not allow vsync to work again without KMSDRM video re-initialization.
To further clarify, on most DRM drivers async pageflips are NOT working nowadays, so all issued pageflips will complete on next VBLANK, NOT ASAP (calling drmModePageFlip() with the DRM_MODE_PAGE_FLIP_ASYNC flag will return error).

The old code was assuming that can just issue a synchronous (=on VBLANK) pageflip and then pass a 0 timeout to the pull() function so we do not wait for the pageflip event, thinking that this will lead to correct non-vsynced screen updates from the program: That is plain wrong.
Each pageflip has to be waite before issuing a new one, ALWAYS. And if we do not support ASYNC pageflips on the DRM driver level, then we are forced to wait for the next VBLANK. There is no way around it.

I have also added many comments on the KMSDRM code. This is needed for future reference for me or others who may need to look at this code: KMS/DRM terminology regarding what SYNC and ASYNC mean in pageflip terms, and where to do certain things and why, is not trivial. It is not desirable or possible to invest time on researching the same concepts every time there is need to dive into this code. So please leave all these comments in the patch.
2020-05-26 16:27:00 -07:00
Sam Lantinga
15294e2121 Fixed iOS build 2020-05-26 13:54:47 -07:00
Sam Lantinga
cc2fe84d73 Getting closer. 2020-05-26 13:19:48 -07:00
Sam Lantinga
0713c5790d More Linux fixes. 2020-05-26 13:19:44 -07:00
Sam Lantinga
c7d1dab1fe Rename Linux-only variable. 2020-05-26 13:19:41 -07:00
Sam Lantinga
b820a81ffb Include SDL_hints.h. 2020-05-26 13:19:35 -07:00
Sam Lantinga
de866e6606 Include SDL_hint.h. 2020-05-26 13:19:29 -07:00
Sam Lantinga
abd5841850 Make some changes to SDL_SetThreadPriority to try and have SDL transparently handle more of the work.
1. Comment that SDL_SetThreadPriority will make any necessary system changes when applying priority.
2. Add a hint to override SDL's default behavior for scheduler policy.
3. Modify the pthreads SDL_SetThreadPriority so that instead of just using the current thread scheduler policy it will change it to a policy that should work best for the requested priority.
4. Add hint checks in SDL_SetThreadPriority so that #3 can be overridden if desired.
5. Modify the Linux SDL_SetThreadPriority so that in the case that policy, either by SDL defaults or from the hint, is a realtime policy it uses the realtime rtkit API.
6. Prior to calling rtkit on Linux make the necessary thread state changes that rtkit requires.  Currently this is done every time as it isn't expected that SDL_SetThreadPriority will be called repeatedly for a thread.
2020-05-26 13:19:19 -07:00
Sam Lantinga
f16e6bfa8e Fixed creating a metal renderer without specifying a metal window 2020-05-25 14:10:51 -07:00
Sam Lantinga
f176d7fda0 Added a note not to use XinputUap.dll for XInput support 2020-05-22 16:45:02 -07:00
Ryan C. Gordon
600a2fc7c3 locale: Removed unused variable. 2020-05-21 04:01:37 -04:00
Ryan C. Gordon
a299fdd789 sensor: Fixed compiler warnings on mingw64. 2020-05-21 03:52:48 -04:00
Ryan C. Gordon
ba11122ea0 locale: Fixed compiler warning on Visual Studio. 2020-05-21 03:48:56 -04:00
Ryan C. Gordon
b4e76b58e7 sensor: Fix overaggressive search/replace. :) 2020-05-20 17:32:23 -04:00
Ryan C. Gordon
27c38eb22e sensor: Correct fix for redefinition of various symbols. 2020-05-20 17:22:52 -04:00
Ryan C. Gordon
5fe34a4079 hidapi: Fix compiler warning. 2020-05-20 17:01:25 -04:00
Ryan C. Gordon
c9d358bce9 sensor: Fix build on various Windows compilers with various predefinitions. 2020-05-20 16:59:35 -04:00
Ryan C. Gordon
68777406e5 windows: Fix calls to CoCreateInstance() so last parameter is a LPVOID *. 2020-05-20 16:58:33 -04:00
Ryan C. Gordon
539125b895 locale: Fixed compiler warning on WinRT. 2020-05-20 16:43:02 -04:00
Ryan C. Gordon
d66b73666d locale: Patched to compile on Windows Phone. 2020-05-20 16:15:14 -04:00
Ryan C. Gordon
3808b120dc locale: Make sure C++ implementations (Haiku!) use C linkage. 2020-05-19 03:14:46 -04:00
Ryan C. Gordon
863776f8dd haiku: Another attempt at fixing build. 2020-05-19 01:19:52 -04:00
Ryan C. Gordon
e53d39cf35 haiku: Patched to compile. 2020-05-19 00:09:59 -04:00
Sylvain Becker
db4246f695 Only set colorkey, if converted surface has no alpha channel (2979) 2020-05-17 21:23:17 +02:00
Sylvain Becker
f6197aec85 Fix issue with colorkey, palette and format conversion
Set the colorkey information on the converted surface.
Test-case in bug 3826/2979, conflicting with bug 4798
2020-05-17 20:45:55 +02:00
Sylvain Becker
39690a0478 Fix static analysis warning in SDL_render.c 2020-05-15 21:33:47 +02:00
Ryan C. Gordon
daf360e040 emscripten: Fix crash in SDL_SetWindowTitle().
This patch came from emscripten-ports, thanks!

Fixes Bugzilla #5133.
2020-05-13 16:48:42 -04:00
Tudor Brindus
1a291ab118 wayland: add support for SDL_SetWindowGrab 2020-04-17 13:55:44 -04:00
Sam Lantinga
b47f577a9d Fixed bug 5098 - macOS CreateWindowFrom doesn't work with high-dpi displays
michaeljosephmaltese

Display ends up taking only 1/4 of the screen area. It needs to call "setWantsBestResolutionOpenGLSurface:highdpi", like when creating a window the normal way.
2020-05-11 14:36:23 -07:00
Sam Lantinga
eadc8693dd Fixed bug 5103 - Port fcitx support to both fcitx 4 & 5
wengxt

Due to the new major fcitx version is coming close, the existing code need to be ported to use new Fcitx dbus interface.

The new dbus interface is supported by both fcitx 4 and 5, and has a good side effect, which is that it will work with flatpak for free. Also the patch remove the dependency on fcitx header. Instead, it just hardcodes a few enum value in the code so need to handle the different header for fcitx4 or 5.
2020-05-11 14:31:04 -07:00
Sylvain Becker
2491f16f85 Android: send SDL_LOCALECHANGED when locale changes 2020-05-08 21:40:28 +02:00
Sylvain Becker
2a4ddeeea9 Android: fix missing prototype warning 2020-05-08 11:15:38 +02:00
Sylvain Becker
0059ace0b4 Android: factorize asset manager code (bug 2131 and 4297) 2020-05-08 11:00:51 +02:00
Ryan C. Gordon
fa23e3d00b locale: Implemented SDL_GetPreferredLocales().
This was something I proposed a long time ago, Sylvain Becker did
additional work on it, then back to me.

Fixes Bugzilla #2131.
2020-05-04 02:27:29 -04:00
Sam Lantinga
1e5dd06f83 Added support for the HORI Real Arcade Pro on Mac OSX and Linux 2020-05-06 12:19:58 -07:00
Sam Lantinga
cd2bdaef1c ControllerList: add PDP Faceoff Deluxe Audio Switch Controller and HORI Real Arcade Pro V Switch Edition 2020-05-06 11:19:52 -07:00
Sam Lantinga
0e5b48d2d8 ControllerList: add NACON Revolution Unlimited (and it's dongle) and NACON Daija fight stick. 2020-05-06 11:19:47 -07:00
Ryan C. Gordon
b3a34c94e0 hid: Add Microsoft Precision Mouse to the joystick blacklist.
Same deal as the Razer keyboards, it hangs the enumeration.
2020-05-06 03:18:25 -04:00
Ryan C. Gordon
85d97410d4 hid: Cleanup Windows joystick blacklist code, to make additions easier. 2020-05-06 03:13:44 -04:00
Ryan C. Gordon
b0a20a153c stdlib: Fixed compiler warnings about int vs size_t. 2020-05-05 12:48:55 -04:00
Sam Lantinga
0eb6512b53 Fixed bug 5121 - Use SDL_calloc instead of calloc in Wayland_CreateWindow
meyraud705

'SDL_Windows::driverdata' of a Wayland window is allocated by calloc in 'Wayland_CreateWindow' but freed by SDL_free in 'Wayland_DestroyWindow'.
2020-05-04 13:19:26 -07:00
Sam Lantinga
65ad45340d Improvement for bug 3446 - The haptic API does not allow to select the direction axes
meyraud705

I see how the documentation is confusing. I think that the choice of the axis is an implementation detail. The documentation should state the goal of this value, so I propose this wording:

    "Use this value to play an effect on the steering wheel axis. This provides
     better compatibility across platforms and devices as SDL will guess the
     correct axis."

Value could even be renamed 'SDL_HAPTIC_STEERING_AXIS'.

For Linux, sending an effect on the X axis with a Logitech wheel works. Others brands don't have driver for Linux as far as I know.
2020-05-04 13:17:43 -07:00
Sam Lantinga
11723411ab Added support for the Razer Kishi 2020-05-04 10:16:10 -07:00
Ryan C. Gordon
8601996fbc hints: Allow specifying audio device metadata.
This is only supported on PulseAudio. You can set a description when opening
your audio device that will show up in pauvcontrol, which lets you set
per-stream volume levels.

Fixes Bugzilla #4801.
2020-05-03 22:13:48 -04:00
Sam Lantinga
8b60d39cb0 Fixed bug 5112 - CMake won't compile in VS2019
dark_sylinc

Trying to build SDL with VS2019 using CMake will encounter a linking error

More specifically:

    1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL
2020-05-02 14:43:17 -07:00
Sam Lantinga
b0b12e46ba Fixed running on older versions of iOS 2020-04-27 13:31:10 -07:00
Sam Lantinga
01fd8130fd Fixed compiler warning 2020-04-23 11:13:02 -07:00
Sam Lantinga
c6b24b4b7c Added support for the following controllers:
* 8BitDo N30 Pro 2
* 8BitDo SN30 Gamepad
* 8BitDo SN30 Pro+
* 8BitDo Zero 2
* SZMY-POWER PC Gamepad
* ThrustMaster eSwap PRO Controller
* ZEROPLUS P4 Wired Gamepad

In additional, all 8BitDo controllers use SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS to have the correct mapping based on user preferences.
2020-04-23 11:07:07 -07:00
Sam Lantinga
4727f79416 Don't use the WGI driver if another driver is already handling the joystick 2020-04-23 10:13:17 -07:00
Sam Lantinga
6ca7f510ae Fixed crash trying to get battery status on some devices 2020-04-23 09:35:32 -07:00
Sam Lantinga
0f374b069b Fixed build on older Visual Studio, enable new features on newer Visual Studio 2020-04-22 15:42:32 -07:00
Sam Lantinga
589d636bb9 Fixed rare crash when creating an X11 window 2020-04-22 14:57:06 -07:00
Sam Lantinga
d12ea89c1e Added support for the following controllers:
* PDP Afterglow Switch Controller
* Thrustmaster ESwap Pro PS4 controller
* Giotek VX4
* Generic PS4 controller vid/pid that several knock offs use
2020-04-22 10:50:50 -07:00
Ryan C. Gordon
3625b83c63 hid: Add Razer Arctosa keyboard to hid enumeration blacklist.
Hangs SDL, same as the Razer Lycosa.

Fixes Bugzilla #5101.
2020-04-21 01:32:48 -04:00
Ryan C. Gordon
09ca66bf66 SDL_error: simplified error string management.
This patch removes deferred error string formatting: now we do it during
SDL_SetError(), so there's no limit on printf-style arguments used.

Also removes stub for managing error string translations; we don't have the
facilities to maintain that and the way we set arbitrary error strings
doesn't really make this practical anyhow.

Since the final error string is set right away and unique to the thread,
we no longer need a static buffer for legacy SDL_GetError(), and we don't
have to allocate 5x 128-byte argument fields per-thread. Also, since we now
use SDL_vsnprintf instead of parsing the format string ourselves, there's a
lot of code deleted and we have access to more robust formatting powers now.

This does mean the final error strings can't be more than 128 bytes, down
from the theoretical maximum of around 768, but I think this is probably okay.
They might truncate but they will always be null-terminated!

Fixes Bugzilla #5092.
2020-04-21 01:30:36 -04:00
Ryan C. Gordon
67760f0ed7 joystick: Don't report duplicate recentering events for game controllers. 2020-04-20 18:58:18 -04:00
Ryan C. Gordon
c5f2a1ce4e 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.
2020-04-20 16:01:36 -04:00
Sam Lantinga
aba2792896 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
2020-04-18 21:41:37 -07:00
Sam Lantinga
b90b59279e Added support for the Razer Atrox Arcade Stick 2020-04-17 21:30:58 -07:00
Sam Lantinga
dbcda0b212 Added support for the Razer Wolverine Ultimate 2020-04-17 21:30:56 -07:00
Sam Lantinga
2b32385502 Don't send rumble packets too quickly to Nintendo Switch Pro controllers over Bluetooth 2020-04-17 15:08:48 -07:00
Sam Lantinga
c02f54a0ed Fixed the default face button mapping for Nintendo Switch Pro controllers 2020-04-17 15:08:46 -07:00
Ryan C. Gordon
eaaa809e40 hidapi: Blacklist the Razer Lycosa keyboard from enumeration.
It's not a joystick and it hangs device enumeration.
2020-04-15 13:33:09 -04:00
Ryan C. Gordon
a7a4e16b5b haiku: Patched to compile. 2020-04-15 13:31:54 -04:00
Sam Lantinga
a990a34ac4 Cleanly switch between audio recording, playback, and both, on iOS 2020-04-14 22:26:02 -07:00
Sam Lantinga
14661d3f30 Added support for mousewheel on iOS 2020-04-14 17:31:31 -07:00
Sam Lantinga
50b1c19549 Fixed bug 5091 - Suspicious condition in HIDAPI_DriverXbox360_UpdateXInput
meyraud705

On line 220 of SDL_hidapi_xbox360.c https://hg.libsdl.org/SDL/file/4608f0e6e8e3/src/joystick/hidapi/SDL_hidapi_xbox360.c#l220

if (!XINPUTGETSTATE(user_index, &xinput_state[user_index].state) == ERROR_SUCCESS) {

logical not is only applied to the left hand side of this comparison.

I think you mean:
if (XINPUTGETSTATE(user_index, &xinput_state[user_index].state) != ERROR_SUCCESS) {
2020-04-14 09:55:33 -07:00
Sam Lantinga
2ae1c0f5d0 Allow Bluetooth headphones for iOS playandrecord mode 2020-04-14 09:52:27 -07:00
Sam Lantinga
f34d2c60cc Added zlib license for Steam Controller headers 2020-04-14 07:35:35 -07:00
Sam Lantinga
3e4856c97f Fixed mouse button mapping on iOS 2020-04-13 23:07:54 -07:00
Sam Lantinga
e1215e857f Fixed mouse button mapping on iOS 2020-04-13 22:50:46 -07:00
Sam Lantinga
dbf7f84fd9 Implemented left/right mouse click detection on iOS 2020-04-13 22:29:10 -07:00
Sam Lantinga
171ba00a6a Hide the mouse cursor appropriately on iOS 2020-04-13 19:44:26 -07:00
Ryan C. Gordon
132f87c3a1 opengl: Don't try to do Desktop OpenGL stuff if support isn't available. 2020-04-13 22:06:12 -04:00
Ryan C. Gordon
a96d8a4355 render: Fixed compiler warning about implicit cast. 2020-04-13 22:05:36 -04:00
Sam Lantinga
6f3fa02e27 Make sure we're using the bounds of the view for our mouse region 2020-04-13 18:25:38 -07:00
Sam Lantinga
cab1ee9cbc Don't build iOS mouse support on Apple TV 2020-04-13 15:57:04 -07:00
Sam Lantinga
e5d3629931 Added support for new mouse APIs in iOS 13.4 2020-04-13 15:46:12 -07:00
Ryan C. Gordon
e96b05c395 egl: Attempt to make this compile on WinRT, etc. 2020-04-13 18:21:28 -04:00
Sam Lantinga
1d8797876a Fixed implicit linkage to ftol2() on Windows 2020-04-13 13:24:56 -07:00
Sam Lantinga
c302c1abb8 Fixed build 2020-04-13 13:24:19 -07:00
Sam Lantinga
bf87604ef1 Fixed rare crash when unplugging Xbox controller on Windows 2020-04-13 12:33:29 -07:00
Conn O'Griofa
c0a875faff SDL_EGL_ChooseConfig: don't fall through if no matching format exists
On Raspberry Pi 3 via the VC4 driver in firmware KMS mode, none of the
found configs match the desired format, causing the function to fall through
without any config being selected.

Fix by first iterating over the found configs, and if no match exists,
don't exclude the non-matching configs. This should fix RPI3 and possibly other
targets without breaking targets that have a matching native format (such as RPI4).
2020-04-13 14:48:38 -04:00
Ryan C. Gordon
64617d259a opengl: Convert an int to an SDL_bool. 2020-04-13 14:45:40 -04:00
Ryan C. Gordon
389c8995d2 opengl: Allow SDL_GL_MakeCurrent() to accept a NULL window (thanks, Martin!).
This allows you to bind surfaceless contexts on a background thread to, for
example, load assets in a separate context, for platforms that have different
requirements about sharing surfaces, etc.

Martin's notes on the matter:

"Here's a patch that enables passing NULL windows to SDL_GL_MakeCurrent, if
the involved APIs allow it. Currently, this is only the case for EGL, and
even then only if some specific extensions are present (which they usually
are).

If "surfaceless" contexts are not supported, SDL_GL_MakeCurrent continues to
generate an error (albeit with a more specific error message than it used to),
so this should not break anything that wasn't broken before."

(Please see https://bugzilla.libsdl.org/show_bug.cgi?id=3695 for more
discussion.)

Fixes Bugzilla #3695.
2020-04-13 14:44:21 -04:00
Jay Petacat
8a5ee3faf9 video: NULL out pointer to freed window surface
This behavior matches SDL_RecreateWindow and makes it less likely that
another piece of code (e.g. a DestroyWindowFramebuffer implementation)
will attempt to use or free the stale surface pointer.
2020-04-12 00:55:52 -04:00
hmk
0918903f3c render: add a hint for toggling relative scaling
Fixes Bugzilla #4811.
2019-09-30 22:54:16 +03:00
hmk
aa188048f1 render: Scale relative mouse motion better for logical sizing
From hmk:

"When scaling is enabled (e.g. via SDL_RenderSetLogicalSize, size not equal
to window size), mouse motion events are also scaled.  Small motions are
rounded up (SDL_max() when the value after scaling is less than 1), while
larger motions are truncated by the floating point -> integer conversion.

https://hg.libsdl.org/SDL/file/b18197f9bf9d/src/render/SDL_render.c#l658

The end result feels something like mouse reverse mouse acceleration + angle
snapping at low speeds, but less consistent (amount of truncation & rounding
depends on how fast the mouse is moved) and potentially much worse if the
scaling factor is large.  This pretty much makes it useless for anything
where you need precise mouse aiming (think of games).  I suspect this is why
aiming gets so terrible in some games that let you use scaling to reduce the
render resolution (e.g. Ion Fury).

With 4x4 scaling, I can reproduce a situation where it takes three fast flicks
of the mouse across the pad to undo one slow sweep across the pad.  In other
words, extreme reverse acceleration.  This does not happen when scaling is
disabled.

Furthermore, any game that uses relative mouse motion events for 3D camera
rotation probably wants the raw mouse deltas and not a value that depends on
scaling and resolution and rounding and truncation.  Ideal camera rotation
just takes mouse input, multiplies it by sensitivity, and adds it to the
angle-in-radians or whatever measure is used for yaw & pitch.  Pixels and
screen resolution or window dimensions should not be a part of the equation
at all, even if it could be implemented without rounding errors.

[...]

This [patch] completely eliminates angle snapping for me, and makes
sensitivity consistent.  In other words, it's completely usable for, say,
aiming in a first person shooter."

Partially fixes Bugzilla #4811.
2020-04-10 12:23:08 -04:00
Ryan C. Gordon
d292f6bd4f stdlib: Add SDL_trunc and SDL_truncf 2020-04-10 12:17:14 -04:00
Ryan C. Gordon
a791689086 metal: Added some support interfaces to Apple's Metal API (thanks, Caleb!).
Caleb Cornett's comments:

"A few weeks ago, Alex added a partial Metal API to SDL2:

https://hg.libsdl.org/SDL/rev/22c8e7cd8d38

I noticed it was missing a few features that would help Metal become a
first-class citizen in SDL, so I went ahead and wrote them! Here are the new
APIs:

1. SDL_WINDOW_METAL flag for SDL_CreateWindow(). This allows the programmer
to specify that they intend to create a window for use with SDL_MetalView.
The flag is used to ensure correct usage of the API and to prevent
accidentally defaulting to OpenGL on iOS.

2. SDL_Metal_GetLayer(). This function takes a SDL_MetalView and returns a
pointer to the view's backing CAMetalLayer. This simplifies things
considerably, since in the current version of the SDL_Metal API the
programmer is required to bridge-cast a SDL_MetalView handle to an NSView or
UIView (depending on the platform) and then extract the layer from there.
SDL_Metal_GetLayer automatically handles all of that, making the operation
simple and cross-platform.

3. SDL_Metal_GetDrawableSize(). This function already exists in the current
SDL_Metal API (and is used behind-the-scenes for SDL_Vulkan_GetDrawableSize
on Apple platforms) but was not publicly exposed. My patch exposes this
function for public use. It works just like you'd expect.

Tested on macOS 10.14 and iOS 12.4."

Fixes Bugzilla #4796.
2020-04-10 00:37:35 -04:00
Charlie Birks
258d410653 emscripten: Add a few keyCode mappings for German keyboards
From @sy2002 in https://github.com/emscripten-ports/SDL2/issues/108
2020-04-09 15:57:12 +01:00
Charlie Birks
babf010c60 emscripten: Pass canvas id to request_pointer_lock
Fixes pointer lock with DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
2020-04-09 15:01:47 +01:00
Daid
287772f5e9 emscripten: Let SDL_GetDisplayUsableBounds return the size of the window
This does not account for scrollbars nor margins. But is much better then returning the full display size when not running fullscreen, but for example in an iframe.
2020-04-09 15:01:45 +01:00
Daid
fb3df3a18d emscripten: Fix the reported keys for the numpad. See https://github.com/emscripten-ports/SDL2/issues/94 2020-04-09 15:01:41 +01:00
Sylvain Beucler
44716b0236 emscripten: Send SDL_APP_TERMINATING before unload (#88) 2020-04-09 15:01:37 +01:00
Beuc
0380cbd792 emscripten: Typo 2020-04-09 15:01:32 +01:00
Sam Lantinga
d4f1b520c9 Added support for press/release hardware keyboard events in iOS 13.4 2020-04-08 19:16:31 -07:00
Sam Lantinga
e9c94ac0b3 Fixed Windows accelerometer data units 2020-04-08 10:27:30 -07:00
Sam Lantinga
09f552639a Fixed memory leak and removed debug code from Windows sensor implementation 2020-04-08 09:00:10 -07:00
Sam Lantinga
55515a8c25 SDL: ps4 controller trigger bits on other controllers just mean that there's some activity, not saturation - only force it on if the analog value is 0. 2020-04-08 08:42:15 -07:00
Sam Lantinga
ba95fa6152 Revert "Fix incorrectly terminated MakeThreadHighPriority dbus message"
The first terminator is for input parameters. The second terminator was for the
output parameters.

If an error occurs when calling MakeThreadHighPriority(), e.g. a bad thread id,
then the reply from connection_send_with_reply_and_block() will be null.
2020-04-08 08:42:09 -07:00
Sam Lantinga
3180ba81af First pass at Windows sensor implementation 2020-04-08 08:34:27 -07:00
Ryan C. Gordon
6e6b517789 cocoa: Patched to compile. 2020-04-07 23:34:41 -04:00
Ryan C. Gordon
8c165adde7 joystick: Remove force_centering flag; we handle this on disconnect now. 2020-04-07 23:17:27 -04:00
Ryan C. Gordon
fba081e489 wasapi: Patched to compile on C89 systems, and use SDL_ceilf instead of ceilf. 2020-04-07 14:51:08 -04:00
Ryan C. Gordon
4c2be47207 wasapi: Improve WASAPI audio backend latency (thanks, Anthony!).
Anthony Pesch's notes on his patch:

"Currently, the WASAPI backend creates a stream in shared mode and sets the
device's callback size to be half of the shared stream's total buffer size.

This works, but doesn't coordinate will with the actual hardware. The hardware
will raise an interrupt after every period which in turn will signal the
object being waited on inside of WaitDevice. From my empirical testing, the
callback size was often larger than the period size and not a multiple of it,
which resulted in poor latency when trying to time an application based on the
audio callback. The reason for this looked something like:

* The device's callback would be called and and the audio buffer was filled.
* WaitDevice would be called.
* The hardware would raise an interrupt after one period.
* WaitDevice would resume, see that a a full callback had not been played and
  then wait again.
* The hardware would raise an interrupt after another period.
* WaitDevice would resume, see that a full callback + some extra amount had
  been played and then it would again call our callback and this process would
  repeat.

The effect of this is that the pacing between subsequent callbacks is poor -
sometimes it's called very quickly, sometimes it's called very late.

By matching the callback's size to the stream's period size, the pacing of
calls to the user callback is improved substantially. I didn't write an actual
test for this, but my use case for this was my Dreamcast emulator
(https://redream.io) which uses the audio callback to help drive the emulation
speed. Without this change and with the default shared stream buffer (which
has a period of ~10ms) I would get frame times that were between ~3-30
milliseconds; after this change I get frame times of ~11-22 milliseconds.

Note, this patch also has a change that removes passing a duration to the
Initialize call. It seems that the default duration used (when 0 is passed)
does typically match up with the duration returned by GetDevicePeriod, however
the Initialize docs say:

> To set the buffer to the minimum size required by the engine thread, the
> client should call Initialize with the hnsBufferDuration parameter set to 0.
> Following the Initialize call, the client can get the size of the resulting
> buffer by calling IAudioClient::GetBufferSize.

This change isn't strictly required, but I made it to hopefully rule out
another source of unexpected latency."

Fixes Bugzilla #4592.
2020-04-07 14:37:24 -04:00
Michael Maltese
361417c0a4 cocoa: allow calling CreateWindowFrom on an NSView
This lets applications embed SDL with other widgets surrounding it.
Already possible on Windows and X11.

Fixes Bugzilla #5060.
2020-03-25 16:40:43 -07:00
Ryan C. Gordon
8641f6e99d emscripten: support KaiOS's Left Soft Key and Right Soft Key (thanks, pelya!).
Fixes Bugzilla #5027.
2020-04-07 14:03:13 -04:00
Ryan C. Gordon
309d6137ae cocoa: OpenGL setView and update must be used on main thread (thanks, Tim!).
If called from background threads, use Grand Central Dispatch to use the
main thread instead. On the main thread, just call them directly.

Fixes Bugzilla #4932.
2020-04-07 14:01:25 -04:00
Ryan C. Gordon
024698779b wayland: Support wayland compositors with wl_seat version < 5 (thanks, Nia!).
Fixes Bugzilla #5074.
2020-04-07 13:30:46 -04:00
Sam Lantinga
3cb62d5265 Fixed setting the controller name for the RAWINPUT driver 2020-04-07 11:17:52 -07:00
Sam Lantinga
e62c25b693 The 0x02ff product ID shows up for new firmware Xbox One controllers using the RAWINPUT driver 2020-04-07 11:17:22 -07:00
Sam Lantinga
88cecee495 Fixed build warning 2020-04-07 10:14:12 -07:00
Sam Lantinga
50cb8e0f04 Fixed deadlock in new raw input joystick code
The appropriate locking is done elsewhere, this prevents inverted lock acquisition
2020-04-07 10:13:08 -07:00
Sam Lantinga
b6afbe6317 Added SDL_log.h to SDL_internal.h so logging is available everywhere 2020-04-07 09:38:57 -07:00
Sam Lantinga
488b94cb40 Don't interpret raw input messages with no mouse position
This happens occasionally on touch devices when raw input is enabled
2020-04-07 09:18:19 -07:00
Sam Lantinga
0721931f5b Avoid sending regular mouse messages for touch input 2020-04-06 19:21:56 -07:00
Jay Petacat
c760c02c6c Fix some format specifier warnings
The warnings were produced by GCC 9.2.x for x86_64-linux-gnu or
i386-pc-msdosdjgpp targets.

Most of the fixes involve changing the type of a variable rather than
the format specifier. For many of the affected test conuter variables,
a basic int seems sufficient.

Some format specifier warnings still remain for cases where changing
type or casting seemed inappropriate. Those warnings will probably
require some new format specifier macros (e.g. SDL_PRIu32).
2020-03-25 01:34:15 -04:00
Sam Lantinga
dad73b1f0c Fixed bug 5073 - SDL does not handle URL Schemes in MacOS
Jason

In iOS, URL Events trigger the DropFile event. I would also expect the same event to be fired on the macOS platform but this is not implemented at all in the AppDelegate.
2020-04-05 10:47:58 -07:00
Sam Lantinga
9525f9729a Fixed bug 5076 - SDL_netbsdaudio: Add support for 32-bit LPCM
Nia Alarie

The kernel supports this, make SDL expose it so it can be used.
2020-04-05 10:44:51 -07:00
Sam Lantinga
e05d92a17d Fixed bug 5075 - Don't assume a GL library version number on NetBSD.
Nia Alarie

If you install X as part of NetBSD, the GL library is libGL.so.3, but if you install the GL library later as a package, it's libGL.so.1.
2020-04-05 09:01:33 -07:00
Sam Lantinga
d4b561f472 Fixed bug 5015 - SDL_RenderReadPixels on DirectX 11.1 backend seems to be broken
Konrad

It appears that I cannot use SDL_RenderReadPixels on a bound framebuffer (SDL_Texture set as render target) as it simply results in gibberish data. However, drawing that framebuffer into the default target (window surface) does render it correctly. Other backends (OpenGL, software, Direct3D) do work fine.

It looks to me like D3D11_RenderReadPixels just gets the general backbuffer and not the current render target and its backbuffer.

Here is the patch which actually fetches the current render target and its underlying ID3D11Resource which is ID3D11Texture2D.
2020-04-05 08:58:47 -07:00
Sam Lantinga
f3e609679d Fixed setting the "playandrecord" audio hint on Apple TV
The Apple TV doesn't have record capability by default, so activating the audio session with AVAudioSessionCategoryPlayAndRecord fails.
2020-04-02 12:27:29 -07:00
Sam Lantinga
378a5cfb61 Updated thread priorities for Apple operating systems 2020-04-01 16:39:05 -07:00
Sam Lantinga
3154d92473 SDL: plumb previously unused digital trigger bits for PS4 controllers. Victrix fight stick only sets these bits and doesn't send the analog values
CR: SamL
2020-03-30 14:26:21 -07:00
Sam Lantinga
f4a56d7e61 Enable thread-safety features in libdbus
There are multiple SDL APIs that internally sink into dbus calls, e.g. battery
status, thread priority. If those calls happen in different threads simultaneously
it can result in dbus crashes.

To abide by dbus's multithreading guidelines we must call dbus_threads_init_default()
to enable dbus's internal locking mechanisms:
https://dbus.freedesktop.org/doc/api/html/group__DBusThreads.html#gac7b8a7001befc3eaa8c6b043151008dc

Additionally, access to a DBusMessage must be synchronized between threads.
SDL was already abiding that guideline as the DBusMessage structs aren't shared.

The following email from the dbus mailing list hints that arbitrating access to
the DBusConnection on the SDL may also be required:
https://lists.freedesktop.org/archives/dbus/2017-September/017306.html
2020-03-30 14:26:15 -07:00
Sam Lantinga
2e667a8be9 Fix incorrectly terminated MakeThreadHighPriority dbus message
Currently the message is double terminated, which results in SDL_DBus_CallMethodInternal()
incorrectly assuming that the other party is always returning true.

I'm not super familiar with dbus, so I'm not sure if this could also be the cause of this bug:
https://github.com/ValveSoftware/steam-for-linux/issues/6901
2020-03-30 14:26:10 -07:00
David Ludwig
6e7465bd60 Fixed Bug 4883, redux - connect SDL_GetDisplayDPI to UIKit_GetDisplayDPI
SDL_GetDisplayDPI was failing on iOS, as UIKit_GetDisplayDPI was
not getting assigned to SDL's internal field in SDL_VideoDevice:
GetDisplayDPI.
2020-03-28 15:43:55 -04:00
Ryan C. Gordon
55b4f18e1a coreaudio: The default SDL audio device now tracks the system output default.
So if you go into System Preferences on a MacBook and toggle between a pair of
connected bluetooth headphones and built-in internal speakers, SDL will
switch the device it is playing sound through, to match this setting, on the
fly.

Likewise if the default output device is a USB thing and is unplugged; as the
default device changes at the system level, SDL will pick this up and carry
on with the new default. This is different from our unplug detection for
specific devices, as in those cases we want to send the app a disconnect
notification, instead of migrating transparently as we now do for default
devices.

Note that this should also work for capture devices; if the device changes,
SDL will start recording from the new default.

Fixes Bugzilla #4851.
2020-03-29 01:54:00 -04:00
Ryan C. Gordon
46bb47cf04 thread: Put all important SDL_CreateThread internal data into SDL_Thread.
This avoids the need to malloc something extra, use a semaphore, etc, and
fixes Emscripten with pthreads support, which might not spin up a web worker
until after SDL_CreateThread returns and thus can't wait on a semaphore at
this point in any case.

Fixes Bugzilla #5064.
2020-03-26 22:14:59 -04:00
Sam Lantinga
abdc5cbf24 Allow background music to play in the "play and record" case on iOS 2020-03-26 19:30:17 -07:00
Ryan C. Gordon
369e5f33fb dbus: System bus is optional, we only need a session bus (thanks, tamo!).
Fixes Bugzilla #4795.
2020-03-26 20:28:04 -04:00
Ryan C. Gordon
07f231eeae joystick: Make sure recentering events happen before disconnect events.
Fixes Bugzilla #5063.
2020-03-26 18:47:04 -04:00
Ryan C. Gordon
f2ff953ef7 cocoa: Just update the OpenGL context directly if on the main thread. 2020-03-26 13:42:56 -04:00
Fabrice Fontaine
9354aea198 src/video/kmsdrm/SDL_kmsdrmvideo.c: fix build
Build is broken without EGL since version 2.0.12 and
https://hg.libsdl.org/SDL/rev/72cc4740dec2:

/home/giuliobenetti/autobuild/run/instance-1/output-1/build/sdl2-2.0.12/src/video/kmsdrm/SDL_kmsdrmvideo.c: In function 'KMSDRM_CreateSurfaces':
/home/giuliobenetti/autobuild/run/instance-1/output-1/build/sdl2-2.0.12/src/video/kmsdrm/SDL_kmsdrmvideo.c:394:5: error: unknown type name 'EGLContext'
     EGLContext egl_context;
     ^

Fixes:
 - http://autobuild.buildroot.org/results/fafd20a01591032662f9ca025fcea3478239cf3c

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-03-25 09:38:45 -07:00
Fabrice Fontaine
a4b0204b1a src/video/directfb/SDL_DirectFB_render.c: fix build
Build with directfb is broken due to a spurious '}' and a missing 'E'
since version 2.0.12 and https://hg.libsdl.org/SDL/rev/4c2dcf490cba:

/home/buildroot/autobuild/run/instance-2/output-1/build/sdl2-2.0.12/src/video/directfb/SDL_DirectFB_render.c: In function 'SetBlendMode':
/home/buildroot/autobuild/run/instance-2/output-1/build/sdl2-2.0.12/src/video/directfb/SDL_DirectFB_render.c:202:9: error: case label not within a switch statement
  202 |         case SDL_BLENDMODE_MUL:
      |         ^~~~

/home/buildroot/autobuild/run/instance-2/output-1/build/sdl2-2.0.12/src/video/directfb/SDL_DirectFB_render.c:205:67: error: 'DSBF_DSTCOLOR' undeclared (first use in this function); did you mean 'DSBF_DESTCOLOR'?
  205 |             SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DSTCOLOR));
      |                                                                   ^~~~~~~~~~~~~

Fixes:
 - http://autobuild.buildroot.org/results/83ccefee68c2800c0544e6f40fa8bc8ee6b67b77

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-03-24 10:05:51 -07:00
Sam Lantinga
885b3f6948 Don't check the HIDAPI driver for the virtual device created by xow 2020-03-23 14:10:25 -07:00
Sam Lantinga
2c02b7410c Fixed bug 5052 - Interval between SDL_SENSORUPDATE events for gyroscopes is too high
Andrei Kortunov

Hello. I try to implement an application for Android, which uses a new sensors API from 2.0.9 to control a camera rotation via built-in gyroscope, using the code from the test/testsensor.c as an example.

Gyroscope input itself works well, but an interval between SDL_SENSORUPDATE events is about 200ms (the SENSOR_DELAY_NORMAL, I believe), when I need the interval about 20-40ms (the SENSOR_DELAY_GAME or SENSOR_DELAY_FASTEST).
2020-03-23 12:10:05 -07:00
Jay Petacat
e0a270561f Do not overwrite window surface created by driver
If a driver's implementation of CreateWindowFramebuffer sets the window
surface, use that rather than overwriting it. A driver may set the window
surface if data cannot be passed via the CreateWindowFramebuffer output
parameters (e.g. surface palette colors).
2020-03-22 20:09:14 -04:00
Sam Lantinga
1fd548b67a Fixed building back to Mac OSX using the 10.7 SDK 2020-03-23 11:42:44 -07:00
Ryan C. Gordon
19a5f4ab5d opengl: Don't enable/disable texturing except when actually rendering.
Otherwise our cached state goes out of sync when updating a texture. Since
these state changes aren't necessary, they were removed instead of updating
the cached state.

Fixes Bugzilla #4998.
2020-03-22 14:32:47 -04:00
Sam Lantinga
cb8c91d956 Fixed bug 5051 - Switch Pro Controller hidapi driver does not report battery levels when connected via Bluetooth
bluenaxela+sdl

I've noticed that the Switch Pro Controller hidapi driver does not report battery levels when connected via Bluetooth, despite having code for setting joystick->epowerlevel.

This is caused by the driver always using k_eSwitchInputReportIDs_SimpleControllerState via Bluetooth. Using that mode means that the state reports you get back from the controller do not include battery state. Not using the full controller state over Bluetooth effectively makes this driver's support for setting joystick->epowerlevel entirely pointless, only ever reporting SDL_JOYSTICK_POWER_WIRED.

Is there a reason this was set to only use SimpleControllerState via Bluetooth?

I've attached a patch I'm using to allow getting battery level for the Switch Pro Controller.

A couple notes about this patch:
1) It changes LoadStickCalibration to accept the input_mode that is selected, because that's really what should determine what is used for stick extents, since stick extents differ between the modes.
2) In my patch I only use FullControllerState when the vid/pid matches the official Switch Pro Controller, as a cautionary measure in case some third-party controllers have problems with FullControllerState mode via Bluetooth (I noticed a HORI Wireless Switch Pad I had seemed to not read controller calibration correctly for stick extents. Maybe it's calibration data was uninitialized on account of having never been used with a Switch? I'm unsure, though if that guess is right maybe SDL2 should be detecting an uninitiated calibration state and using some sensible defaults)
2020-03-22 11:01:14 -07:00
Sam Lantinga
f55cbdfd96 Allow Valve devices in driver check, we know they're well behaved controllers 2020-03-20 21:05:07 -07:00
Sam Lantinga
6e646b6156 Removed blacklist entries for devices that aren't game controllers, allow Steam Controllers 2020-03-20 20:53:26 -07:00
Cameron Gutman
5ed71f3bc0 Only enumerate HID devices on Windows that have gamepad HID usages
There are a number of poorly behaved HID devices that time out on attempts to
read various strings. Rather than end up on an endless treadmill of blacklisting
broken devices, reduce our risk by only querying devices that are gamepads.
SDL_hidapijoystick.c already checks these same usages, so we shouldn't
exclude any working HID devices (caveat below).

This also makes HidP_GetPreparsedData() and HidP_GetCaps() failure skip
the device entirely, but that seems desired. If a device can't even return basic
top-level collection data properly, we want nothing to do with that broken device.
If we do find devices that work with HIDAPI joystick and fail these calls, we can
add an exception via VID+PID matching.
2020-03-20 13:44:50 -07:00
Sam Lantinga
106ffd57d8 Fixed bug 5049 - HORI Wireless Switch Pad does not connect properly via Bluetooth
bluenaxela+sdl

The HORI Wireless Switch Pad does not properly connect via bluetooth. I did some debugging and found that the code that tries to control the Home LED causes this controller to disconnect.
2020-03-20 20:45:30 -07:00
Jimb Esser
417713a75c Probable fix for compile errors on Mac OS and (non-VS) Win32 2020-03-20 19:49:19 -07:00
Sam Lantinga
dc36f133b4 Backed out changeset c29d04c3fa49 2020-03-20 19:49:15 -07:00
Sam Lantinga
2db65a7fe7 Fixed compile warnings 2020-03-20 19:47:46 -07:00
Ryan C. Gordon
90f9e8f8b6 egl: Don't use SDL_LoadFunction to get GL entry points on Emscripten.
This results in a dlsym() call, which causes Emscripten to panic if the game
wasn't explicitly built dlopen support. eglGetProcAddress works just fine on
this platform, so just let that codepath handle it.
2020-03-20 15:13:09 -04:00
Emir Marincic
5b3b55a181 [NSOpenGLContext update[ is prohibited outside the main thread 2020-03-20 11:52:18 +03:00
David Ludwig
7e5340c5ac Fix for Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.0.12
This is a multi-part fix, and is the 2nd attempt at a fix for Bug 5034.  Here
are the problems being addressed:

1. On macOS 10.14.x and earlier, trying to call IOHIDDeviceUnscheduleFromRunLoop
   without a prior, paired call to IOHIDDeviceScheduleWithRunLoop, appears to
   lead to a crash.  A per-device flag has been added to make sure that these
   calls are paired.
2. DARWIN_JoystickDetect was free'ing its SDL_joystick's hwdata field
   (via FreeDevice) without setting it to NULL, and DARWIN_JoystickRumble wasn't
   checking for a NULL hwdata.  FreeDevice will now set hwdata to NULL and
   DARWIN_JoystickRumble will check for a NULL hwdata.
2020-03-17 17:34:24 -04:00
Sam Lantinga
4c22a21e06 Fixed bug 3446 - The haptic API does not allow to select the direction axes
meyraud705

Added Linux implementation, otherwise you get "Unsupported direction type" error.
Added documentation to explain why one would use SDL_HAPTIC_FIRST_AXIS.
2020-03-17 14:18:05 -07:00
Sylvain Becker
e6189f4046 Fix warnining implicit declaration of SDL_DetectPalette (Thanks meyraud705) 2020-03-17 15:47:30 +01:00
Sylvain Becker
838bbf1f7a Fixed bug 5037 - Regression 2.0.12 Alpha value of 0 on palette may become opaque
(see also bug 3827)
2020-03-17 09:35:42 +01:00
David Ludwig
36d5845152 Backout prior fix for Bug 5034, which needs more research
This backs-out the change, https://hg.libsdl.org/SDL/rev/14c961903135
2020-03-17 02:31:47 -04:00
Sam Lantinga
55a2a12ddf Fixed compile warning 2020-03-16 22:34:33 -07:00
Sam Lantinga
9b879a08aa Fixed compiler warning 2020-03-16 19:15:28 -07:00
Jimb Esser
c2c5d0b392 Fix compile error 2020-03-16 16:52:49 -07:00
David Ludwig
197b14de4a Fixed Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.0.12
The Darwin/macOS joystick driver was freeing its joystick's hwdata field
without zeroing it out in any live instance of SDL_Joystick.
2020-03-16 19:24:25 -04:00
Jimb Esser
47da53b91d Fix compiler warnings 2020-03-16 14:49:20 -07:00
David Ludwig
8cd08646bb virtual joysticks: move variable decls to top of function (for C90 compat; Bug 5038) 2020-03-16 17:19:18 -04:00
Sam Lantinga
7379991778 Fixed bug 3446 - The haptic API does not allow to select the direction axes
Mathieu Laurendeau

Consider a device supporting effects on multiple axes.
There's currently no way to play effects against a single-axis direction.


A device supporting effects against X and Y may not allow to play effects with a two-axis direction coordinate, even if one of the coordinates is null.

My current (ugly) work around for this is to add a direction type SDL_HAPTIC_X_FORCE to play effects against a X-axis only direction (patch attached).

This issue impacted two GIMX users using the following wheels:
- Leo Bodnar SimSteering force feedback wheel
- Accuforce direct drive wheel

Playing constant/spring/damper effects against a X-axis direction worked well for the first wheel, but not for the second one.

A better strategy seems to play the effects against the first axis reported by the DirectInput enumeration.

This strategy also works with Logitech wheels (at least the DFGT).

It's been more than a year that I have the latest patch (playing effects against the first axis only) in the GIMX software. It's being used by thousands of people, mostly for adapting their FFB wheel to the PS4. I had no report that proves this strategy to be wrong.
2020-03-16 13:28:38 -07:00
Sam Lantinga
543994b193 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.
2020-03-16 12:25:02 -07:00
Sam Lantinga
4dea340ca7 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.
2020-03-16 12:23:38 -07:00
David Ludwig
b2296506bc virtual joysticks: MSVC support part 1/2, make driver's .c file be uniquely named 2020-03-15 15:05:36 -04:00
David Ludwig
cc90875647 virtual joysticks: removed ball support (Bug 5028) 2020-03-15 13:25:49 -04:00
Sam Lantinga
151c8fbf19 Fixed build error
Malte Kie?ling

I get a build error in SDL_sysjoystick.c:74 for the merged patch, but its nothing to sweat about, just -Werror=declaration-after-statement doing its usual stuff.
2020-03-14 17:45:00 -07:00
Sam Lantinga
1ff483d1f3 Added SDL_GetErrorMsg() to get the error message in a thread-safe way 2020-03-13 21:28:09 -07:00
Sam Lantinga
19c3484469 Fixed slow enumeration when Apple Cinema HD display 30" is plugged in 2020-03-13 19:19:29 -07:00
Ethan Lee
133b475586 Use LIBUSB_CALL for hidapi's read_callback function 2020-03-11 14:17:19 -04:00
Sam Lantinga
2be75c6a61 Fixed bug 5028 - Virtual Joysticks (new joystick backend)
David Ludwig

I have created a new driver for SDL's Joystick and Game-Controller subsystem: a Virtual driver.  This driver allows one to create a software-based joystick, which to SDL applications will look and react like a real joystick, but whose state can be set programmatically.  A primary use case for this is to help enable developers to add touch-screen joysticks to their apps.

The driver comes with a set of new, public APIs, with functions to attach and detach joysticks, set virtual-joystick state, and to determine if a joystick is a virtual-one.

Use of virtual joysticks goes as such:

1. Attach one or more virtual joysticks by calling SDL_JoystickAttachVirtual.  If successful, this returns the virtual-device's joystick-index.
2. Open the virtual joysticks (using indicies returned by SDL_JoystickAttachVirtual).
3. Call any of the SDL_JoystickSetVirtual* functions when joystick-state changes.  Please note that virtual-joystick state will only get applied on the next call to SDL_JoystickUpdate, or when pumping or polling for SDL events (via SDL_PumpEvents or SDL_PollEvent).


Here is a listing of the new, public APIs, at present and subject to change:

------------------------------------------------------------

/**
 * Attaches a new virtual joystick.
 * Returns the joystick's device index, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nballs, int nbuttons, int nhats);

/**
 * Detaches a virtual joystick
 * Returns 0 on success, or -1 if an error occurred.
 */
extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);

/**
 * Indicates whether or not a virtual-joystick is at a given device index.
 */
extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);

/**
 * Set values on an opened, virtual-joystick's controls.
 * Returns 0 on success, -1 on error.
 */
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick * joystick, int axis, Sint16 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualBall(SDL_Joystick * joystick, int ball, Sint16 xrel, Sint16 yrel);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick * joystick, int button, Uint8 value);
extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick * joystick, int hat, Uint8 value);

------------------------------------------------------------

Miscellaneous notes on the initial patch, which are also subject to change:

1. no test code is present in SDL, yet.  This should, perhaps, change.  Initial development was done with an ImGui-based app, which potentially is too thick for use in SDL-official.  If tests are to be added, what kind of tests?  Automated?  Graphical?

2. virtual game controllers can be created by calling SDL_JoystickAttachVirtual with a joystick-type of SDL_JOYSTICK_TYPE_GAME_CONTROLLER, with naxes (num axes) set to SDL_CONTROLLER_AXIS_MAX, and with nbuttons (num buttons) set to SDL_CONTROLLER_BUTTON_MAX.  When updating their state, values of type SDL_GameControllerAxis or SDL_GameControllerButton can be casted to an int and used for the control-index (in calls to SDL_JoystickSetVirtual* functions).

3. virtual joysticks' guids are mostly all-zeros with the exception of the last two bytes, the first of which is a 'v', to indicate that the guid is a virtual one, and the second of which is a SDL_JoystickType that has been converted into a Uint8.

4. virtual joysticks are ONLY turned into virtual game-controllers if and when their joystick-type is set to SDL_JOYSTICK_TYPE_GAMECONTROLLER.  This is controlled by having SDL's default list of game-controllers have a single entry for a virtual game controller (of guid, "00000000000000000000000000007601", which is subject to the guid-encoding described above).

5. regarding having to call SDL_JoystickUpdate, either directly or indirectly via SDL_PumpEvents or SDL_PollEvents, before new virtual-joystick state becomes active (as specified via SDL_JoystickSetVirtual* function-calls), this was done to match behavior found in SDL's other joystick drivers, almost all of which will only update SDL-state during SDL_JoystickUpdate.

6. the initial patch is based off of SDL 2.0.12

7. the virtual joystick subsystem is disabled by default.  It should be possible to enable it by building with SDL_JOYSTICK_VIRTUAL=1



Questions, comments, suggestions, or bug reports very welcome!
2020-03-13 19:08:45 -07:00
Sam Lantinga
879f137aec Added support for the older Xbox One S Bluetooth controller report format 2020-03-13 19:00:24 -07:00
Sam Lantinga
d662a65964 Fixed crash if manufacturer or product string is NULL 2020-03-13 19:00:22 -07:00
Sam Lantinga
255c9c23d4 Fixed bug 4921 - Do not swap B/X buttons on GameCube controller unless it's requested
The binding for the Mayflash GameCube controller adapter now respects the SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS hint
2020-03-13 13:28:33 -07:00
Sam Lantinga
6318765d54 Handle entirely duplicated joystick product names, as well as vendor and product names that start with the name of the vendor, but with different case (e.g. 8bitdo 8BitDo) 2020-03-13 13:05:43 -07:00
Sam Lantinga
de2001eeee Fixed binding the D-PAD on the 8BitDo M30 controller 2020-03-13 13:05:40 -07:00
Sam Lantinga
cb2f78b12d Updated 8BitDo SF30 Pro mapping with hint support, added Android binding for the 8BitDo M30 Gamepad 2020-03-13 13:05:38 -07:00
Sam Lantinga
cb986aff9f Fixed exception at shutdown if the controllers are closed after the HIDDeviceManager is shutdown 2020-03-13 13:05:32 -07:00
Sam Lantinga
80d075a01a Fixed compiler warnings 2020-03-13 09:43:48 -07:00
Sam Lantinga
5722e88481 Fixed build warnings 2020-03-12 19:49:33 -07:00
Sam Lantinga
c44473ba73 Unified code to standardize joystick names 2020-03-12 19:47:30 -07:00
Sam Lantinga
db3b3a1d84 Added support for SDL hints in the game controller mapping database 2020-03-12 19:47:28 -07:00
Sam Lantinga
93ed3c8baf Updated SDL to version 2.0.13 for development builds 2020-03-10 18:25:47 -07:00
Sam Lantinga
983bbf9ef3 Backed out changeset 51622f74dc85 2020-03-10 18:35:31 -07:00
Sam Lantinga
9fdc6cf307 Removed Xbox HIDAPI debug code 2020-03-10 18:34:33 -07:00
Sam Lantinga
4fb06a2a38 Updated SDL to version 2.0.13 for development builds 2020-03-10 18:25:47 -07:00
Sam Lantinga
fe97992185 Read the buttons on Nintendo Switch and GameCube controllers as they are labeled, and swap them if the applications wants positional button data instead. 2020-03-10 17:35:14 -07:00
Sam Lantinga
4caa6a0688 Fixed bug 4921 - Do not swap B/X buttons on GameCube controller unless it's requested
Ethan Lee

Basically replicating the solution of the Switch Controller's button label issue. Physical layout should take priority unless it's explicitly requested by the user or application!
2020-03-10 16:41:42 -07:00
Sam Lantinga
342f62ca69 Fixed bug 5022 - SDL_iconv_string can get stuck in an infinite loop when encountering invalid characters
ciremo6483

In `SDL_iconv_string` the `while (inbytesleft > 0)` loop can end up in a state where it never terminates because the library `iconv` function called from `SDL_iconv` doesn't consume any bytes.

This happened when a `WCHAR_T` input string was being converted to `UTF-8` but contained invalid characters. It would first It would first skip a few bytes due to `case SDL_ICONV_EILSEQ` but when there were 3 bytes remaining of `inbytesleft` `iconv` just didn't consume anything more (but didn't throw an error either).

It just so happens that the Microsoft Classic IntelliMouse `product_string` contains such invalid characters (`"Microsoft? Classic IntelliMouse?"`), meaning the function would get stuck with said mouse plugged in.

A fix for this would be to check if `inbytesleft` was unchanged after an iteration and in that case either decrement the counter like when `SDL_ICONV_EILSEQ` is returned or simply break the loop.
2020-03-10 16:29:28 -07:00
Sam Lantinga
1f4965c8c4 Fixed warnings building with mingw64 2020-03-08 21:24:06 -07:00
Sam Lantinga
c8c05a9fc3 Fixed bug 4991 - Pixel shader problem when recreating a texture for direct3d renderer
cmediaplayer

Hi, i already mentioned in the SDL discourse a bug that recreating of a texture occours pixel shader problem on direct3d renderer. There is no problem for direct3d11. You can see the issue by using my app named C Media Player which is available for Windows for free using my web site www.cmediaplayer.com. Just follow the steps:

*Open a media file
*When playing the file change the scale quality under the video menu.
*You will see the problem.
2020-03-08 19:23:21 -07:00
Sam Lantinga
367a356132 Don't release the backbuffer on error, we didn't acquire it. 2020-03-08 18:56:07 -07:00
Cameron Gutman
4e0fb110c8 Clear the old player index slot when moving to a new one 2020-03-07 19:21:21 -08:00
Cameron Gutman
165ccaa85b Fix incorrect player index when assigning a joystick the same index twice
Prior to this fix, we would hit the existing_instance >= 0 case and move the joystick
again to a different index than the one requested by the caller. It also breaks the assumption
that a SDL_JoystickID is only present in SDL_joystick_players at one location.
2020-03-07 17:20:04 -08:00
Cameron Gutman
e152a3cedb direct3d: Don't attempt to create zero sized vertex buffer 2020-03-07 13:59:42 -08:00
Cameron Gutman
467434b92d Added support for indicating player index on DS4 controllers 2020-03-07 13:17:28 -08:00
Sam Lantinga
82be6dd7c9 Fixed regression in bug 4966 - KMSDRM: Add dynamic modeset support
Anthony Pesch

I was just communicating with one of the Retropie developers regarding this.

This change removed the forced window focus change on creation (3534cb3793) as part of the change no longer assumes there's only a single window being created. This was perhaps an over-aggressive removal.

Due to that change, joystick events are only received if SDL_SetKeyboardFocus is called explicitly, or if the app has specified SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS.

I think that part of my change should be reverted to continue setting mouse / keyboard focus to the window being created. If SDL_WINDOW_INPUT_FOCUS is to be used as an input flag the code could be conditional, but that would still leave existing software broken.
2020-03-07 08:48:04 -08:00
Ethan Lee
27889d0261 winrt: Wait for EnumerationCompleted before leaving WASAPI_EnumerateEndpoints 2020-03-03 12:31:41 -05:00
Sam Lantinga
e9bc21fba5 Fixed rumble for third-party Nintento Switch Pro controllers
The 8BitDo SF30 Pro Gamepad will generate a single motor pulse for each rumble message, so we need to do this frequently to have continous rumble on this device.
2020-03-04 17:10:37 -08:00
Sam Lantinga
428cfddb4c Fixed crash when a controller is disconnected while rumble is pending 2020-03-04 14:59:44 -08:00
Sam Lantinga
281d05a6d1 Fixed handling the guide button with both V1 and V2 of the Xbox One Bluetooth wireless protocols 2020-03-04 09:42:10 -08:00
Sam Lantinga
69a8c8468c Fixed using more than one Xbox Bluetooth controller
Don't prevent duplicate devices using hidraw, instead libusb takes precedence and all hidraw devices that aren't handled by libusb are available
2020-03-04 09:42:08 -08:00
Sam Lantinga
2a91f682b5 Fixed bug 5012 - KaiOS keycodes support
pelya

KaiOS is an OS for feature phones, with numeric keypad and non-touch screen, and typically 512 Mb RAM and 4 Gb flash.
It is based on Firefox OS, all apps are made with HTML5 and Javascript. SDL can be cross-compiled using emscripten and packaged as native app.
This patch adds support for star '*' and pound '#' keys on such phones to generate SDL events.
2020-03-03 17:56:33 -08:00
Sam Lantinga
96836ec643 Add 500ms max wait time for hid_write to complete on Windows
It appears that with some (presumably) flaky drivers or hardware that the WriteFile in hid_write never completes leading to GetOverlappedResult to block forever waiting for it.
2020-03-03 09:22:43 -08:00
Sam Lantinga
07000bfc33 Fixed bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application
Jake Breen

I have tracked it down to a call on
hid_device_info() -> HidD_GetManufacturerString (Line 499 in src\hidapi\windows\hid.c)
2020-03-02 17:31:58 -08:00
Sam Lantinga
aa384ad02b Fixed bug 5001 - Feature request: SDL_isupper & SDL_islower 2020-03-02 15:21:07 -08:00
Sam Lantinga
3b3ae4d14d Possible fix for bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application
Jake Breen

When I run SDL_INIT with SDL_INIT_JOYSTICK it stalls for about 10 seconds (last report was 10,615ms), but only if I'm currently playing audio. (Like in Spotify for example.)

querying something related to device access (last dll loaded)
'BabbysFirst64.exe' (Win32): Loaded 'C:\Windows\SysWOW64\deviceaccess.dll'.

I use a USB DAC because my mobo's audio out is pretty not great. And I've noticed unplugging it seems to solve the issue. I haven't noticed any other issues that are caused by my DAC.

My DAC is the Sound BlasterX G1 https://us.creative.com/p/gaming-headsets/sound-blasterx-g1
Vid = 041E
PID = 3249

My system specs:
- Windows 10 Pro
- Ryzen 2700x
- 16GB Ram
- Nvidia 2070 RTX

Additional USB devices plugged in:
- Valve Index
- Xbox One Elite Controller
2020-03-02 15:06:47 -08:00
Sam Lantinga
a19757ac8d Fixed bug 5007 - Segfault in KMSDRM_VideoQuit() on Raspberry Pi Zero with no display attached
Charles Huber

This patch fixes the segfault on my Pi, though the valid display index range reported by the CHECK_DISPLAY_INDEX() macro in src/video/SDL_video.c is a little weird:

$ SDL_VIDEO_EGL_DRIVER=libEGL.so SDL_VIDEO_GL_DRIVER=libGLESv2.so ./a.out
SDL_Init(): displayIndex must be in the range 0 - -1
2020-03-02 14:55:40 -08:00
Sam Lantinga
eb19631a1e This controller firmware is supported on Windows, and is covered by the Bluetooth check on Mac OSX 2020-03-02 10:57:57 -08:00
Sam Lantinga
49564c8b8d Added support for the PDP Victrix Pro FS with Touch Pad for PS4 2020-03-02 10:47:48 -08:00
Sam Lantinga
4572dd2ae6 Fixed bug 4854 - Add a way to extend the values in controller_type.h
Added a hint SDL_HINT_GAMECONTROLLERTYPE to allow overriding the built-in controller type database
2020-03-02 10:37:28 -08:00
Sam Lantinga
27f346a058 Fixed compile warning 2020-03-02 09:46:37 -08:00
Sam Lantinga
339612d5af ControllerList: add support for Victrix Pro FS w/ Touchpad for PS4 2020-03-02 09:35:12 -08:00
Sam Lantinga
52be663380 Use SDL math functions in Steam Controller support 2020-03-02 09:35:09 -08:00
Sam Lantinga
756d2073fe Updated the HIDAPI Xbox One driver with support for Bluetooth Xbox One controllers 2020-03-02 09:26:12 -08:00
Sam Lantinga
997f3e9e82 Fixed build warnings 2020-03-02 09:03:55 -08:00
Sam Lantinga
bebc486774 We already have a hidapi implementation for Windows, we don't need libusb 2020-03-01 17:53:30 -08:00
Sam Lantinga
74ed215618 Updated version to 2.0.12 for release candidate build 2020-03-01 14:58:16 -08:00
Sam Lantinga
6590d078d7 Fixed bug 4996 - Mac: XBoxOne Bluetooth rumble isn't working
rofferom

I have an annoying issue on MacOS about XBoxOne Bluetooth rumble (Vendor: 0x045e, Product: 0x02fd).

When 360controller is installed, rumble is working correctly. However, Bluetooth rumble isn't working at all, with or without 360controller installed (although it is working with Chrome + https://html5gamepad.com).

I looked at the code, and it seems that XBox controllers are managed in MacOS in this file: SDL_hidapi_xbox360.c. The XBoxOne file is disabled for MacOS in SDL_hidjoystick_c.h.

The function HIDAPI_DriverXbox360_Rumble() is called correctly, and hid_write() returns no error.

I have tried a stupid test. I took the rumble packet from 360controller: ec4e88eb2d/XBOBTFF/FFDriver.cpp (L620). With the patch I have attached, I manage to have rumble working on Bluetooth (with some stupid vibration level, but it proves it can if the packet is changed).

But it breaks the USB rumble with 360controller. A comment in the function makes an explicit reference to 360controller, I think that's why I have broken this specific usecase.

I don't know what is the correct way to fix this, but it seems that the current implementation has a missing case for Bluetooth support.


Note that I also tested master this morning, and I have another issue:
    if (!device->ffservice) {
        return SDL_Unsupported();
    }

test fails in DARWIN_JoystickRumble(). This test has been done quickly, I'm not totaly confident about its accuracy.
2020-03-01 14:52:49 -08:00
Romain Roff?
5346216368 mac: Fix gamepad detection 2020-03-01 13:01:53 -08:00
Sam Lantinga
51e9e98451 Fixed whitespace 2020-03-01 13:00:50 -08:00
Sam Lantinga
8a6f1aa5f5 Fixed bug 4369 - Going fullscreen with green knob in MacOS freezes app for 15 seconds.
Elmar

creating a fullscreen window with SDL_CreateWindow(..SDL_WINDOW_FULLSCREEN_DESKTOP..) in MacOS works fine, except if it was triggered by the user with the green knob in the top left window title bar.

Then "something" is different, and SDL_CreateWindow hangs for 15-20 seconds (tested in MacOS 10.13 and 10.14).

Responsible for the hang is this code in SDL_cocoawindow.m - Cocoa_SetWindowFullscreenSpace:

        const int maxattempts = 3;
        int attempt = 0;
        while (++attempt <= maxattempts) {
            /* Wait for the transition to complete, so application changes
             take effect properly (e.g. setting the window size, etc.)
             */
            const int limit = 10000;
            int count = 0;
            while ([data->listener isInFullscreenSpaceTransition]) {
                if ( ++count == limit ) {
                    /* Uh oh, transition isn't completing. Should we assert? */
                    break;
                }
                SDL_Delay(1);
                SDL_PumpEvents();
            }
            if ([data->listener isInFullscreenSpace] == (state ? YES : NO))
                break;
            /* Try again, the last attempt was interrupted by user gestures */
            if (![data->listener setFullscreenSpace:(state ? YES : NO)])
                break; /* ??? */
        }

One trivial workaround is to change 'const int limit = 10000' to 500. Then the freeze is so short that it doesn't look like a freeze to the user.

Looking further into the problem, I observed that the function Cocoa_SetWindowFullscreenSpace recursively calls itself via some ObjectiveC messages. I managed to extract a callstack for this (copied below): Note how Cocoa_SetWindowFullscreenSpace in stack line 22 calls SDL_PumpEvents, which eventually arrives at  SDL_SendWindowEvent, which calls SDL_UpdateFullscreenMode (stack line 0), which then calls Cocoa_SetWindowFullscreenSpace again (not shown). This recursive second call is the one that hangs.

Another "solution" that worked for me was to add a flag to SDL_Window that is set in Cocoa_SetWindowFullscreenSpace and causes this function to return immediately if called from itself.

Obviously, this is also an ugly hack, but I don't have enough time to dive into this crazy Cocoa/ObjectiveC business deep enough to find a proper solution. But hopefully it's easy for one of the experts around.

Note that there is a "failure to go fullscreen"-message involved, maybe using the green knob causes this failure at first.

I can unfortunately not provide a minimum example.

Best regards,
Elmar

0   com.yasara.View               	0x00000001007495af SDL_UpdateFullscreenMode + 207
1   com.yasara.View               	0x00000001006e2591 SDL_SendWindowEvent + 401
2   com.yasara.View               	0x0000000100775a72 -[Cocoa_WindowListener windowDidResize:] + 370
3   com.yasara.View               	0x0000000100776550 -[Cocoa_WindowListener windowDidExitFullScreen:] + 512
4   com.apple.AppKit              	0x00007fff3180a2a4 -[_NSWindowEnterFullScreenTransitionController failedToEnterFullScreen] + 692
5   com.apple.AppKit              	0x00007fff31c59737 -[_NSEnterFullScreenTransitionController _doFailedToEnterFullScreen] + 349
6   com.apple.AppKit              	0x00007fff3172aa53 __NSFullScreenDockConnectionSendEnterForSpace_block_invoke + 135
7   libxpc.dylib                  	0x00007fff6114b9b1 _xpc_connection_reply_callout + 36
8   libxpc.dylib                  	0x00007fff6114b938 _xpc_connection_call_reply_async + 82
9   libdispatch.dylib             	0x00007fff60ec7e39 _dispatch_client_callout3 + 8
10  libdispatch.dylib             	0x00007fff60ede3b0 _dispatch_mach_msg_async_reply_invoke + 322
11  libdispatch.dylib             	0x00007fff60ed2e25 _dispatch_main_queue_callback_4CF + 807
12  com.apple.CoreFoundation      	0x00007fff33d39e8b __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13  com.apple.CoreFoundation      	0x00007fff33d3959a __CFRunLoopRun + 2335
14  com.apple.CoreFoundation      	0x00007fff33d38a28 CFRunLoopRunSpecific + 463
15  com.apple.HIToolbox           	0x00007fff32fd1b35 RunCurrentEventLoopInMode + 293
16  com.apple.HIToolbox           	0x00007fff32fd1774 ReceiveNextEventCommon + 371
17  com.apple.HIToolbox           	0x00007fff32fd15e8 _BlockUntilNextEventMatchingListInModeWithFilter + 64
18  com.apple.AppKit              	0x00007fff3128deb7 _DPSNextEvent + 997
19  com.apple.AppKit              	0x00007fff3128cc56 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
20  com.yasara.View               	0x000000010076fab2 Cocoa_PumpEvents + 290
21  com.yasara.View               	0x00000001006dd1c7 SDL_PumpEvents_REAL + 23
22  com.yasara.View               	0x00000001007795cf Cocoa_SetWindowFullscreenSpace + 223
23  com.yasara.View               	0x000000010074970b SDL_UpdateFullscreenMode + 555
24  com.yasara.View               	0x00000001006e2476 SDL_SendWindowEvent + 118
25  com.yasara.View               	0x0000000100774ff7 -[Cocoa_WindowListener resumeVisibleObservation] + 135
26  com.yasara.View               	0x000000010077664c Cocoa_ShowWindow + 188
27  com.yasara.View               	0x0000000100749492 SDL_FinishWindowCreation + 546
28  com.yasara.View               	0x0000000100748da5 SDL_CreateWindow_REAL + 1573
29  com.yasara.View               	0x000000010010d9b1 vga_setvideomode + 1347
30  com.yasara.View               	0x00000001003f0d46 mod_initscreen + 2614
31  com.yasara.View               	0x00000001003f344b mod_reinitscreen + 460
32  com.yasara.View               	0x00000001003f370d mod_resizescreen + 383
33  com.yasara.View               	0x0000000100418e39 mod_main + 815
34  com.yasara.View               	0x000000010029ca5d main2 + 5766
35  com.yasara.View               	0x000000010011d1b7 main.main_cpuok + 19
2020-03-01 12:58:50 -08:00
Sam Lantinga
bd5da73afd Fixed bug 4992 - UWP/WinRT does not set thread priority when using SDL_SetThreadPriority
Ethan Lee

Attached is a diff that I used to get SetThreadPriority working locally. I still have no idea what the minimum SDK version is since Microsoft never documented it, but it's worth pointing out that they're much more aggressive about using the latest VS and UWP SDK anyway (for example, an updated Xbox is no longer compatible with VS2017, and updates are required to have a network connection of any kind).
2020-03-01 12:50:42 -08:00
Sam Lantinga
1af31a26d1 Fixed trying to handle the HORI Wireless Switch Pad when connected via USB 2020-02-27 13:53:32 -08:00
Sam Lantinga
20d67446e0 Xbox One controller rumble doesn't need synchronization if you use a packet counter of 0 2020-02-27 09:33:32 -08:00
Sam Lantinga
9013c9169c Fixed bug 5005 - warnings in kmsdrm
Malte Kie?ling

At the moment i get following warnings from kmsdrm:

 * in SDL_kmsdrmvideo.c KMSDRM_DestroySurfaces is return type int, but thats never returned or checked against
 * in SDL_kmsdrmvideo.c KMSDRM_DestroySurfaces the variable viddata is not used
 * in SDL_kmsdrmopengles.c KMSDRM_GLES_LoadLibrary a cast to NativeDisplayType is missing

I attached a patch for them :)
2020-02-27 08:20:34 -08:00
Sam Lantinga
7f26ff237d Fixed bug 4987 - Can't build on MinGW a recent state (15'th February, 2020): conflicting types 2020-02-27 08:18:20 -08:00
Sylvain Becker
21a2e0c787 Fix compilation C90 mixed declarations and code (Thanks Cameron Gutman !) 2020-02-25 06:53:51 +01:00
Sylvain Becker
e2b132ca74 Better fix to set the palette opaque, when there is also a colorkey
(see bug 3827)
2020-02-24 21:57:03 +01:00
Sam Lantinga
e3b0713e40 Don't call setPreferredOutputNumberOfChannels on iOS, it breaks audio output 2020-02-24 12:07:18 -08:00
Sam Lantinga
2c9871a4a8 Fixed surround sound support on Apple TV 2020-02-24 10:25:57 -08:00
Sylvain Becker
f485766005 Fix: set to opaque when a palette surface is converted to an alpha format. 2020-02-23 23:07:15 +01:00
Sylvain Becker
bf8aa1edae Fix regression: when a palette + colorkey is converted, it needs a blend mode.
- Regression of test_1.c of bug 3827, after fix from bug 4798.
- Blending is also needed when the palette contains alpha value, but not necessarily colorkey.
- Clean up SDL_ConvertColorkeyToAlpha which doesn't seem to need 'ignore_alpha' parameter any-more.

(see bug 3827)
2020-02-23 22:38:08 +01:00
Ryan C. Gordon
094655cff9 cocoa: Make sure wait for button enable can't be infinite. 2020-02-23 14:49:03 -05:00
Ryan C. Gordon
723165187f cocoa: Removed a debug printf that was accidentally committed. 2020-02-23 14:48:48 -05:00
Sylvain Becker
9a7c2b2246 Fixed bug 4999 - Palette surface always promoted to alpha (Thanks Cameron Gutman!)
MSVC Static analysis: Incorrect alpha_value check in SDL_render.c
(see also bug 4425)
2020-02-23 09:59:52 +01:00
Ryan C. Gordon
4d9e6e5f70 cocoa: When exiting a fullscreen space, wait for window state to normalize.
A good metric of this is when the titlebar's "minimize" button is reenabled,
which doesn't happen by the time windowDidExitFullscreen triggers.

This fixes minimizing a fullscreen window on macOS.

Fixes Bugzilla #4177.
2020-02-21 14:50:09 -05:00
Sam Lantinga
8d14636326 Fixed support for third party Xbox 360 wireless controller dongle 2020-02-19 08:26:00 -08:00
Ryan C. Gordon
44698c4970 dynapi: Fixed build on non-Android platforms. 2020-02-18 01:44:07 -05:00
Sam Lantinga
ad225047b6 Added Android SDK conditionals to game controller mappings
The Nintendo Switch Pro controller has a different mapping on Android 10 and newer
2020-02-17 14:15:47 -08:00
Sam Lantinga
d7ece7ee6f Made SDL_GetAndroidSDKVersion() available for applications 2020-02-17 13:54:45 -08:00
Ryan C. Gordon
93b26f172c opengl: Backed out hg changeset 94f9f40a957f
This is the OpenGL line drawing fix for Bugzilla #3182, but there's some
disagreement about what the renderers should do here, so I'm backing this out
until after 2.0.12 ships, and then we'll reevaluate all the renderer backends
to decide what's correct, and make them all work the same.
2020-02-17 16:15:04 -05:00
Ryan C. Gordon
1b82606e1d x11: Wait a bit in SDL_SetWindowSize() to see if window manager vetoed change.
Same idea as the fix for Bugzilla #4646.

Fixes Bugzilla #4727.
2020-02-17 16:11:18 -05:00
Ryan C. Gordon
e731522578 x11: Don't delay an extra 10ms if we were just going to break out of the loop. 2020-02-17 15:02:37 -05:00
Ryan C. Gordon
367a8b9701 x11: Don't wait for the window to move if it's already in the place we want it. 2020-02-17 15:00:02 -05:00
Sam Lantinga
4a9dbfef6b Fixed bug 4987 - Can't build on MinGW a recent state: conflicting types
Vitaly Novichkov

Recent attempt to build a recent HG state of SDL2 via AppVeyor gives the failure:

https://ci.appveyor.com/project/Wohlstand/sdl-mixer-x/builds/30821858/job/359gqvypi2f18nok

```
C:\projects\sdl-mixer-x\build-MinGW-w32-MinSizeRel-Win32-VB6-Binding\external\AudioCodecs\src\AudioCodecs-build\external\SDL2\src\SDL2HG\src\dynapi\SDL_dynapi_procs.h:56:29: error: conflicting types for 'SDL_CreateThread'
 SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c),(a,b,c),return)
2020-02-15 16:39:38 -08:00
Cameron Cawley
582f570600 Improved CPU detection on ARM platforms 2020-02-04 16:46:22 +00:00
Cameron Cawley
8f1a916ac5 Add basic support for compiling on RISC OS 2020-02-13 20:50:47 +00:00
Sam Lantinga
35704c983e Fixed bug 4980 - Build fails for SDL_kmsdrm*.c
Malte Kie?ling

Since https://hg.libsdl.org/SDL/rev/f908bd722523 / bug 4966 i cannot build SDL anymore. The error i get is, essentially, caused by -Werror=declaration-after-statement in SDL_kmsdrmvideo.c and SDL_kmsdrmopengles.c
2020-02-14 16:17:17 -08:00
Sam Lantinga
715f8d42a2 Fixed bug 4986 - Memory leak in HIDAPI_JoystickConnected
meyraud705

Memory allocated for device->joysticks on line 589 of SDL_hidapijoystick.c is never freed.

Also, use memmove because memory is overlapping.
2020-02-14 16:15:46 -08:00
Sam Lantinga
f4e23553d7 Fixed audio not coming out of the phone speakers while recording on iOS 2020-02-14 15:19:34 -08:00
Sam Lantinga
922b3dc3e7 Fixed re-setting the audio session category when closing an audio device 2020-02-14 14:18:12 -08:00
Ryan C. Gordon
d1df34370e x11: SDL_SetWindowPosition should try to wait for the window manager.
Wait up to 100 milliseconds, since the window manager might alter or
outright veto the window change...or not respond at all.

In a well-functioning system, though, this should help make sure
that SDL_SetWindowPosition's results match reality.

Fixes Bugzilla #4646.
2020-02-14 13:17:18 -05:00
Ryan C. Gordon
a77a890d4a wayland: Don't delay pending surface resize handling on Vulkan.
OpenGL apparently needs to not do any drawing between wl_egl_window_resize
and eglSwapBuffers, but Vulkan apps don't use SDL to present, so they
never call into an equivalent of SDL_GL_SwapWindow where our Wayland code
was handling pending resize work.

Fixes Bugzilla #4722.
2020-02-14 00:58:36 -05:00
Ryan C. Gordon
7ad77bccb2 wayland: Don't force the window into OpenGL mode if we want Vulkan. 2020-02-14 01:08:21 -05:00
Sam Lantinga
14bf532df3 Fixed opening audio on Android from the Steam Link shell activity 2020-02-13 16:10:52 -08:00
Sam Lantinga
b431286471 Resolved conflict and added Android_JNI_RequestPermission() 2020-02-13 10:19:05 -08:00
Sam Lantinga
e261bd4205 Improved fix for bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work 2020-02-12 12:26:27 -08:00
Ryan C. Gordon
afb70f2681 test: Reimplemented SDLTest_CommonUsage() to restore binary compatibility.
Fixes Bugzilla #4975.
2020-02-12 13:09:38 -05:00
Ryan C. Gordon
0a6d80abf7 mac: Wait a bit before activating app at startup.
This is obnoxious and wrong, but the patch that activates the Dock before
activating the app fixes the _menu_ not responding on Catalina, but the
first window created by the app won't have keyboard focus without a small
delay inserted.

This obviously needs a better solution, but it gets it limping along correctly
for now.
2020-02-12 13:08:29 -05:00
Sam Lantinga
6fe6946a2f Fixed relative mode mouse events stopping if you click on the title bar 2020-02-11 21:19:05 -08:00
Sam Lantinga
6ec14b7fda Fixed iOS and Android build 2020-02-11 16:23:43 -08:00
Sam Lantinga
4bb95e8403 Implemented OpenSL-ES audio recording on Android 2020-02-11 16:14:02 -08:00
Sam Lantinga
fe8ce66b53 Attempt to make version detection safe for Mac OS X < 10.10 2020-02-11 10:35:14 -08:00
Sam Lantinga
52b410ab8e Workaround for bug 4822 - Broken visual output in full screen mode with OS X 10.15
sjordan

We did some investigations into a different direction which I would like to share. As mentioned previously the scaling setting in the preferences play an important role for our problem and they also hint towards an issue with point/pixel scaling factors.

We found an interesting correlation between our fail case and the behavior of [nsWindow.screen backingScaleFactor]. It turns out that whenever we encounter the fail case the scale factor is zero when we print it quickly after calling SDL_CreateWindow. After some time the value changes to a non-zero value. In the success case the scaling factor is nonzero 'immediately'. Note that we don't use that factor. We also find that the window backingScaleFactor does not show the strange behavior even in the fail case.

We have also attempted to find out whether any event triggers the transition from zero to non-zero. We found the transition happening when we call SDL_PollEvent. We can even force this to happen by explicitly adding a SDL_PollEvent at an early stage, but it will only happen if a certain amount of time elapsed, so we need to add some sleep before the call to trigger the transition at an earlier stage. All that seems to imply that the transition happens async and that SDL_PollEvent merely causes the system to update its internal state at that time.

We have also verified that the scaling setting in the preferences does NOT directly correlate to the scaling factor behavior. We find that a particular scaling setting can lead to a fail case for one resolution and a success case for another resolution. This shows that the scaling setting alone does not determine whether the problem will appear or not.

We have also verified on another Mac with 10.14 that the scaling factor is always non-zero and we always have the success case.

I have no idea how to interpret this initial-zero behavior and haven't found any usable information on the screen backing scale factor. It seems as 10.15 does some stuff more async than before and maybe the problem could be caused by unfortunate timings. I would be very interested to hear your opinion about that.

...

Finally we found the cause of all our problems: it's the origin hack in Cocoa_SetWindowFullscreen:

        /* Hack to fix origin on Mac OS X 10.4 */
        NSRect screenRect = [[nswindow screen] frame];
        if (screenRect.size.height >= 1.0f) {
            rect.origin.y += (screenRect.size.height - rect.size.height);
        }

If we comment this one out our game and testdraw2 do behave correctly.

It turns out that if a window is not fully contained in the screen, it's screen property becomes zero and therefore we saw a zero when printing the backing scale factor (although it's not clear why it became nonzero later).

We suggest to add a runtime check which skips this code for 10.15 (or possibly earlier if you happen to know that the hack is not needed for certain older versions).

More info: consider the line

NSRect screenRect = [[nswindow screen] frame];

in Cocoa_SetWindowFullscreen. We found that this rect has the dimensions of the desktop
on our OS X 10.15 setup. This is true both for the success case and the fail case. It seems as the success case is actually a fail case in disguise.

On the other Mac with OS X 10.14 the same rect has the dimension of the newly created screen. This is what I would expect, because at that time the window has already been created successfully and there should be a newly created screen associated to the window.

What are the cases in which the whole origin conversion code for the fullscreen case is supposed to have a non-trivial result?

Today we found that if we print the dimensions of [nswindow screen] later, then we find them to be correct. So the conclusion seems to be that OS X 10.15 does indeed do the window/screen setup more async than before and that the origin correction code uses the [nswindow screen] at a time where the window/screen setup isn't finalized yet.
2020-02-11 10:21:31 -08:00
Sam Lantinga
c31727c7e7 Fixed bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work
The problem here was calling ClipCursor() continuously in a tight loop. Fixed by only calling ClipCursor() if the clip area needs to be updated.
2020-02-11 10:08:22 -08:00
Sam Lantinga
668276fe81 Don't add a frame to borderless windows.
It was done to allow hotkey resizing of borderless windows, but Windows will sometimes draw it, regardless of our WM_* message handling. See bug 4466 for more details.
2020-02-11 09:41:55 -08:00
Sam Lantinga
f867cebbd4 Fixed bug 4709 - incorrect (not) handling of windows on-screen cursor keys
Alex Denisov

When using Win10 on-screen keyboard (tooltip.exe), the left and right cursor keys in it do not produce SDLK_LEFT and SDLK_RIGHT events.

Windows messages generated by the on-screen keyboard, for some reason, have their scancodes set to zeroes. Here is the log from Spy++:

WM_KEYDOWN nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
WM_KEYUP nVirtKey:VK_LEFT cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Regular physical keyboard produces VK_LEFT (ScanCode:4B) and VK_RIGHT (ScanCode:4D) which are interpreted correctly.

With on-screen keyboard, the switch statement in VKeytoScancode() does not check for VK_LEFT and VK_RIGHT, returning SDL_SCANCODE_UNKNOWN, which in turn does not get mapped to anything (because the scan codes are zeroes).
2020-02-11 08:36:13 -08:00
Ryan C. Gordon
4378fcd9a7 wayland: Fix building with -fno-common (which is now the default in GCC 10).
Fixes Bugzilla #4957.
2020-02-10 23:48:06 -05:00
Sam Lantinga
d55f47d564 Fixed compile warning 2020-02-10 13:59:05 -08:00
Fabrice Fontaine
cbc65ce80d src/core/linux/SDL_threadprio.c: fix build without threads
Add an include on SDL_error.h to avoid the following build failure
without threads:

/home/buildroot/autobuild/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/arm-buildroot-linux-uclibcgnueabihf/8.3.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/ld: build/.libs/SDL_threadprio.o: in function `SDL_LinuxSetThreadPriority_REAL':
SDL_threadprio.c:(.text+0x0): undefined reference to `SDL_Unsupported'

Fixes:
 - http://autobuild.buildroot.org/results/7f7712c5bd47de4a3fcec1e0d0526fd5a3ecd532

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-02-10 13:56:53 -08:00
Ryan C. Gordon
ed10d9473f opengl: Build out full GL_LINES and respect the diamond-exit rule.
Likewise for the GLES1 and GLES2 renderers.

This solves the missing pixel at the end of a line and removes all the
heuristics for various platforms/drivers. It's possible we could still use
GL_LINE_STRIP with this and save some vertex buffer space, assuming this
doesn't upset some driver somewhere, but this seems to be a clean fix that
makes the GL renderers match the software renderer output.

Diamond-exit rule explanation:
http://graphics-software-engineer.blogspot.com/2012/04/rasterization-rules.html

Fixes Bugzilla #3182.
2020-02-10 12:53:54 -05:00
Sam Lantinga
13155b35b4 The scissor rect needs to be updated when the viewport changes in the Metal renderer 2020-02-10 09:42:53 -08:00
Sam Lantinga
3e935aecb9 Fixed bug 4966 - KMSDRM: Add dynamic modeset support
Anthony Pesch

* Remove triple buffering support. As far as I can tell, this goes against the libdrm API; the EGL implementations themselves control the buffering. Removing it isn't absolutely necessary as it seemingly works on the Pi at least, but I noticed this while doing my work and explained my reasoning in the commit.

* Replace the crtc_ready logic which allocates an extra bo to perform the initial CRTC configuration (which is required before calling drmModePageFlip) with a call to drmModeSetCrtc after the front and back buffers are allocated, avoiding this allocation.

* Standardized the SDL_*Data variable names and null checks to improve readability. Given that there were duplicate fields in each SDL_*Data structure, having generic names such as "data" at times was very confusing.

* Removed unused fields from the SDL_*Data structures and moves all display related fields out of SDL_VideoData and into SDL_DisplayData. Not required since the code only supports a single display right now, but this was helpful in reading and understanding the code initially.

* Implement KMSDRM_GetDisplayModes / KMSDRM_SetDisplayMode to provide dynamic modeset support.

These changes have been tested on a Raspberry Pi 4 and a Dell XPS laptop with an HD 520.

As an update, I went back over the triple buffer changes and left them in. I didn't entirely get the code originally, I had just seen it calling KMSDRM_gbm_surface_lock_front_buffer twice for a single swap and had removed it because I was paranoid of bugs stemming from it while working on the modeset changes.

I've made a few small changes to the logic that had thrown me off originally and rebased the changes:
* The condition wrapping the call to release buffer was incorrect.
* The first call to KMSDRM_gbm_surface_lock_front_buffer has been removed. I don't understand why it existed.
* Added additional comments describing what was going on in the code (as it does fix the buffer release pattern of the original code before it).
2020-02-09 11:44:22 -08:00
Sam Lantinga
e5e5416975 Removed VID/PID 0x1532/0x0037, which was listed in the Linux kernel as a Razer Sabertooth, because at least one variant of the Razer DeathAdder mouse shows up with this VID/PID.
Specifically the Razer DeathAdder 2013 has this VID/PID
2020-02-07 20:19:32 -08:00
Sam Lantinga
833f76ab7b Fixed bug 4968 - NULL passed to memcpy in WriteProprietary in SDL_hidapi_switch.c
meyraud705

In SDL_hidapi_switch.c

line 443: Function BTrySetupUSB call WriteProprietary with pBuf=NULL and ucLen=0
line 376: WriteProprietary check its input (!pBuf && ucLen > 0) || ucLen > sizeof(packet.rgucProprietaryData): ucLen is 0 so it passes
line 382: WriteProprietary call memcpy with pBuf=NULL
2020-02-07 11:49:56 -08:00
Sam Lantinga
8ba77b35a5 Use the asynchronous HIDAPI rumble code for Nintendo Switch Pro controllers 2020-02-07 11:44:57 -08:00
Sam Lantinga
81256207bd Update for bug 4923 - Calling SDL_GameControllerRumble() often takes 8 ms
meyraud705

Dualshock4 on bluetooth need 78 bytes for the rumble data while SDL_HIDAPI_RumbleRequest can only hold 64 bytes.

'volatile' is not meant for thread synchronization.

The list of rumble request could grow infinitely if user call SDL_JoystickRumble too much. The documentation says "Each call to this function cancels any previous rumble effect", so overwriting pending request seem like a good idea.
2020-02-07 11:02:34 -08:00
David Ludwig
d88f3f5226 macOS: fix crash if and when joystick-init-on-add fails 2020-02-05 13:16:17 -05:00
Sam Lantinga
a199cb89ad Updated the Android Xbox One Wireless Controller mapping for the latest Xbox controller firmware update 2020-02-05 09:29:46 -08:00
Sam Lantinga
dc1d3c2974 Catch both PS3 and PS4 motion controls and don't treat them as a game controller 2020-02-04 18:36:23 -08:00
Sam Lantinga
1d1a35ef64 Fixed Visual Studio build 2020-02-04 16:05:39 -08:00
Sam Lantinga
1bd120266f Added SDL_hidapi_rumble.c to the macOS, iOS and tvOS builds 2020-02-04 15:42:49 -08:00
David Ludwig
65fd633694 FIX for SDL-4927: CFRetain+CFRelease a game controller's IOKit object
This fixes a crash whereby SDL could crash on macOS/Darwin, if and when a
USB game controller gets unplugged.  SDL was not retaining a reference
to the controller's OS/IOKit-provided 'device object', and was capable
of trying to use it, after a device was hot-unplugged.
2020-01-30 18:03:34 -05:00
Sam Lantinga
02108cf7e5 Added missing files from previous commit 2020-02-04 15:27:25 -08:00
Sam Lantinga
1684606fdf Fixed long delay on main thread caused by blocking rumble writes in HIDAPI drivers
There is now a thread that handles all HIDAPI rumble requests and a lock that guarantees that we're not reading and writing the device at the same time.
2020-02-04 15:26:56 -08:00
Sam Lantinga
6efebf1768 Moved rumble expiration to the main joystick handling level, and prevent sending the driver layer duplicate rumble requests. 2020-02-04 12:48:53 -08:00
Sjoerd Simons
976eee77cc Correct joystick hat indexes on linux
The index and indices were swapped; Which is fine as long as there are
no gaps in the ABS_HAT* event availability but otherwise things do get confused.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
2020-02-04 07:23:44 -08:00
Sam Lantinga
4b585e75d9 Fixed bug 4833 - Use EGL for X11?
Martin Fiedler

To be precise, this is about *desktop OpenGL* on X11. For OpenGL ES, EGL is already used (as it's the only way to get an OpenGL ES context), as Sylvain noted above.

To shine some light on why this is needed:
In 99% of all cases, using GLX on X11 is fine, even though it's effectively deprecated in favor of EGL [1]. However, there's at least one use case that *requires* the OpenGL context being created with EGL instead of GLX, and that's DRM_PRIME interoperability: The function glEGLImageTargetTexture2DOES simply doesn't work with GLX. (Currently, Mesa actually crashes when trying that.)
Some example code:
https://gist.github.com/kajott/d1b29c613be30893c855621edd1f212e
Runs on Intel and open-source AMD drivers just fine (others unconfirmed), but with #define USE_EGL 0 (i.e. forcing it to GLX), it crashes. The same happens when using SDL for window and context creation.

The good news is that most of the pieces for EGL support on X11 are already in place: SDL_egl.c is pretty complete (and used for desktop OpenGL on Wayland, for example), and SDL_x11opengl.c has the aforementioned OpenGL-ES-on-EGL support. However, when it comes to desktop OpenGL, it's hardcoded to fall back to GLX.

I'm not advocating to make EGL the default for desktop OpenGL on X11; don't fix what ain't broken. But something like an SDL_HINT_VIDEO_X11_FORCE_EGL would be very appreciated to make use cases like the above work with SDL.


[1] source: Eric Anholt, major Linux graphics stack developer, 7 years ago already - see last paragraph of https://www.phoronix.com/scan.php?page=news_item&px=MTE3MTI
2020-02-03 08:06:52 -08:00
Sam Lantinga
67f4478867 Fixed bug 4917 - Wayland: handle discrete pointer axis events
Luis Caceres

The current handling of Wayland mouse pointer events only handles wl_pointer.axis events, which, according to the Wayland documentation, deal with mouse wheel scroll events on a continuous scale. While this is reasonable for some input sources (e.g. touchpad two-finger scrolling), it is not for mouse wheel clicks which generate wl_pointer.axis events with large deltas.

This patch adds handling for wl_pointer.axis_discrete and wl_pointer.frame events and prefers to report SDL_MouseWheelEvent in discrete units if they are available. This means that for mouse wheel scrolling we count in clicks, but for touchpad two-finger scrolling we still use whatever units Wayland uses. This behaviour is closer to that of the X11 backend.

Since these events are only available since version 5 of the wl_seat interface, this patch also checks for this and falls back to the previous behaviour if its not available. I also had to add definitions for some of the pointer and keyboard events specified in versions 2-5 but these are just stubs and do nothing.
2020-02-03 00:57:12 -08:00
Sam Lantinga
b5849daf3e Fixed build warnings on Android 2020-02-01 09:23:04 -08:00
Sam Lantinga
212609b3f2 Map the right pad on the Steam Controller to the right stick in the game controller API 2020-01-31 14:09:23 -08:00
Sam Lantinga
39a498c940 Build the hidapi framework and weak link it on Mac OS X 2020-01-31 13:09:20 -08:00
Sam Lantinga
91121ee4bb Weak link the hidapi framework on iOS and tvOS 2020-01-31 10:45:04 -08:00
Sam Lantinga
1190343f36 Build hidapi as a framework on iOS, so it can be linked by the application as well. 2020-01-30 16:02:56 -08:00
Sam Lantinga
62a3d6c004 Fixed build 2020-01-30 14:58:41 -08:00
Sam Lantinga
37278066f2 Export SDL functions for iOS application delegates 2020-01-30 14:51:33 -08:00
Ryan C. Gordon
66579dbd1a test: Common framework now accepts --usable-bounds command line argument. 2020-01-30 13:47:48 -05:00
Ryan C. Gordon
80e7e2eb9d test: change path in a comment from '\\' to '/' char. Nothing serious here. 2020-01-30 13:47:19 -05:00
Sam Lantinga
0641711e9f Added missing file from previous commit 2020-01-29 20:09:59 -08:00
Sam Lantinga
0897f2359c Fixed compiler warning 2020-01-29 20:09:16 -08:00
Sam Lantinga
355f0b54ec Added support for the Steam Controller on mobile devices 2020-01-29 20:09:11 -08:00
Sam Lantinga
c9c89783cb Miscellaneous pending fixes 2020-01-29 20:09:08 -08:00
Sam Lantinga
43b377b077 Fixed wired PS4 controller support on Android 2020-01-28 17:11:17 -08:00
Ryan C. Gordon
39563b7bfa x11: Use XSync when changing window position instead of XFlush.
Attempt to fix regression in Bugzilla #4646.
2020-01-28 13:51:24 -05:00
Ryan C. Gordon
c7e1b289ee cocoa: Fix command line apps' menu bar not working on macOS Catalina.
Fixes Bugzilla #4937.
2020-01-27 17:15:12 -05:00
Ryan C. Gordon
059de38c2c darwin: Don't pass NULL device refs to IOHIDDeviceGetValue().
Possibly fixes Bugzilla #4961.
2020-01-27 15:44:48 -05:00
Ryan C. Gordon
b4c2e29eed video: Added a hint to override the display's usable bounds. 2020-01-27 10:58:30 -05:00
Sam Lantinga
7ea3f5b464 Fixed bug 4898 - No rumble because of integer overflow in SDL_JoystickRumble
meyraud705

Switch hidapi and xinput also need to check for overflow, attached a patch for them.
2020-01-26 12:48:35 -08:00
Sam Lantinga
5e649983e7 Don't enumerate devices we can't open 2020-01-26 12:40:32 -08:00
Sam Lantinga
adb53d0b1f Fixed disabling the Xbox 360 wireless HIDAPI driver 2020-01-26 10:32:39 -08:00
Sam Lantinga
c9f672fde4 Fixed compiler warnings 2020-01-23 22:24:24 -08:00
Sam Lantinga
2ae41b9c61 Fixed mapping for both versions of the Xbox One Elite Series 2 controller firmware connecting over Bluetooth 2020-01-23 12:53:43 -08:00
Sam Lantinga
48240ac88e Added mapping for the Xbox One controller connected via the wireless dongle using xow 2020-01-23 12:53:41 -08:00
Sam Lantinga
6dc172d093 Turn off rumble on drivers which don't respect the replay.length value 2020-01-23 12:53:39 -08:00
Sam Lantinga
30ff5fcfc0 SDL_LEAN_AND_MEAN defaults off 2020-01-23 01:03:23 -08:00
Sam Lantinga
b5e3d264f2 Added a single SDL_LEAN_AND_MEAN define to turn on minimal SDL builds
Protected more code with #ifdefs to reduce the size of minimal shared library builds
2020-01-23 01:00:52 -08:00
Sam Lantinga
b1c6e7c244 Fixed compile warning 2020-01-23 00:32:34 -08:00
Sam Lantinga
443bce741b Added support for the paddles on the Xbox One Elite Series 1 controller 2020-01-22 11:28:35 -08:00
Sylvain Becker
6f89b059f7 Documentation of the footprint #defines 2020-01-22 15:23:44 +01:00
Ryan C. Gordon
f30ef6ed3d audio: Fixed a '//' style comment. 2020-01-21 17:40:16 -05:00
Ryan C. Gordon
dbe5c14b33 audio: Calculate a legitimate SDL_AudioSpec::silence in SDL_LoadWAV_RW(). 2020-01-21 15:49:37 -05:00
Sylvain Becker
55afc281fa Add #define SDL_HAVE_BLIT_N_RGB565 to compile out RGB565 LUT 2020-01-21 22:06:09 +01:00
Sylvain Becker
7df22cf2c2 A few #defines to reduce SDL2 footprint.
Only applied when library is statically linked
2020-01-21 21:33:40 +01:00
Sam Lantinga
25c88ea903 The Xbox One 0x01 initialization packet is an ack packet 2020-01-20 13:53:40 -08:00
Sam Lantinga
9c3d1602ab Refactored code so SDL_GetJoystickGameControllerType() is called less during controller detection 2020-01-19 11:43:36 -08:00
Sam Lantinga
ff06801106 Added missing file from previous commit 2020-01-18 11:21:42 -08:00