Commit Graph

4846 Commits (b15e880e73cc6a8e3f7c73ea8e61346d39096ccf)

Author SHA1 Message Date
Sam Lantinga b15e880e73 Fixed open functions in the SDL_hidapi.h header 2021-11-11 13:50:16 -08:00
Sam Lantinga b9b0df40bf Fixed Linux build 2021-11-11 12:52:40 -08:00
Sam Lantinga c9ada1c142 Made HIDAPI device change notifications available via SDL_hid_device_change_count() 2021-11-11 12:46:10 -08:00
Ethan Lee 63ae103cd1 wayland: QTWAYLAND_CONTENT_ORIENTATION can support multiple values as bitmasks 2021-11-11 13:16:34 -05:00
Sam Lantinga ebed961cb2 Fixed build with older Linux kernel headers 2021-11-11 09:51:39 -08:00
Sam Lantinga 11ae43ca16 Only lock the pointer for mouse relative mode, there isn't really a concept of grab and confinement on iOS
Locking the pointer prevents the on-screen cursor from moving, which isn't what we want with a grab behavior.

Fixes https://github.com/libsdl-org/SDL/issues/4941
2021-11-11 07:51:34 -08:00
Misa 66a08aa391 Add and use `SDL_FALLTHROUGH` for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__
compiler attribute. Unfortunately, not all compilers have this
attribute, or even have __has_attribute to check if they have the
__fallthrough__ attribute. [[fallthrough]] is also available in C++17
and the next C2x, but not everyone uses C++17 or C2x.

So define the SDL_FALLTHROUGH macro to deal with those problems - if we
are using C++17 or C2x, it expands to [[fallthrough]]; else if the
compiler has __has_attribute and has the __fallthrough__ attribute, then
it expands to __attribute__((__fallthrough__)); else it expands to an
empty statement, with a /* fallthrough */ comment (it's a do {} while
(0) statement, because users of this macro need to use a semicolon,
because [[fallthrough]] and __attribute__((__fallthrough__)) require a
semicolon).

Applications using SDL are also free to use this macro (because it is
defined in begin_code.h).

All existing /* fallthrough */ comments have been replaced with this
macro. Some of them were unnecessary because they were the last case in
a switch; using SDL_FALLTHROUGH in those cases would result in a compile
error on compilers that support __fallthrough__, for having a
__attribute__((__fallthrough__)) statement that didn't immediately
precede a case label.
2021-11-11 07:23:25 -08:00
Sam Lantinga 828a0a4a10 Fixed mapping for PS4 controller when using the classic Joystick
interface on Linux
2021-11-11 07:13:29 -08:00
Sam Lantinga dc9de1e2bd Get the correct USB VID/PID information for /dev/input/js* devices 2021-11-11 07:03:30 -08:00
Sam Lantinga bd92a95f22 Cleanup for the /dev/js* support (thanks @meyraud705) 2021-11-11 06:30:36 -08:00
Mathieu Eyraud 3090812e1e Convert last SDL_IOReady()'s 2nd parameter to flags
Conversion missed in https://github.com/libsdl-org/SDL/pull/4897
2021-11-11 06:17:26 -08:00
Sam Lantinga 1c78b08007 Added support for /dev/input/js* on Linux
Added the hint SDL_HINT_LINUX_JOYSTICK_CLASSIC to control whether /dev/input/js* or /dev/input/event* are used as joystick devices

Added the hint SDL_HINT_JOYSTICK_DEVICE to allow the user to specify devices t
hat will be opened in addition to the normal joystick detection

Fixes https://github.com/libsdl-org/SDL/issues/1314
Fixes https://github.com/libsdl-org/SDL/issues/1727
Fixes https://github.com/libsdl-org/SDL/issues/1981
Closes https://github.com/libsdl-org/SDL/pull/4727
2021-11-10 20:02:25 -08:00
Sam Lantinga 65a50b2430 Re-enable udev joystick enumeration by default 2021-11-10 16:15:22 -08:00
Sam Lantinga dfb834d3d4 Track button state for each mouse input source separately
This way we'll get button down and up events for each mouseID
individually.

Fixes https://github.com/libsdl-org/SDL/issues/4518
2021-11-10 13:44:29 -08:00
Sam Lantinga eda4c40732 Make sure the X event is an Xkb event before checking the Xkb event type 2021-11-10 12:48:09 -08:00
Sam Lantinga 98c9836287 Don't clobber the error in SDL_ShowMessageBox() if one has been set at
the platform level

Fixes https://github.com/libsdl-org/SDL/issues/4760
2021-11-10 11:04:51 -08:00
Sam Lantinga dc4c7d9539 Fixed infinite loop in SDL_vsnprintf() if the format string is too large for the output buffer
Fixes https://github.com/libsdl-org/SDL/issues/4940
2021-11-10 09:48:49 -08:00
Sam Lantinga d5032582e0 Use consistent language between SDLTest_AssertPass() and SDLTest_AssertCheck() 2021-11-10 09:45:56 -08:00
Sam Lantinga 6c4b4ee7a6 Don't assert on API parameters
This causes lots of spam in test automation and it's not clear it's useful to developers. If we need this level of validation, we should add a log category for it.
2021-11-10 09:41:43 -08:00
Sam Lantinga fed857787a Update the orientation and display modes when the display settings change on Windows
Fixes https://github.com/libsdl-org/SDL/issues/1061
2021-11-10 08:47:39 -08:00
Sam Lantinga c0f1109bd0 Implemented querying the orientation of displays on Windows 2021-11-10 06:03:01 -08:00
Sam Lantinga 3a31a45028 End the scene before resetting the D3D device, since we'll start with BeginScene after that.
If we don't do this, we'll end up with unbalanced Begin/End scene pairs which causes D3DERR_INVALIDCALL in the present.

Fixes https://github.com/libsdl-org/SDL/issues/4933
2021-11-10 05:24:31 -08:00
Cameron Gutman 6b64c47b69 haptics: Enumerate XInput/DInput joysticks after haptic init
Since the haptic subsystem is usually initialized after the joystick subsystem,
the initial calls to HapticMaybeAddDevice() from inside SDL_JoystickInit() will
arrive too early to be handled by the haptic subsystem. We need to add those
haptic devices for those already present joysticks ourselves.
2021-11-09 23:46:34 -06:00
Eric Wasylishen 0d98793693
testwm2: Fix video modes menu hit detection when highdpi or logical size used (#4936)
* SDLTest_CommonDrawWindowInfo: log SDL_RenderGetScale, SDL_RenderGetLogicalSize

* testwm2: fix video modes menu hit detection in High DPI cases

- also when logical size is specified, e.g.
  `--logical 640x480 --resizable --allow-highdpi`

* add function to determine logical coordinates of renderer point when given window point

* change since to the targeted milestone

* fix typo

* rename for consistency

* Change logical coordinate type to float, since we can render with floating point precision.

* add function to convert logical to window coordinates

* testwm2: use new SDL_RenderWindowToLogical

* SDL_render.c: alternate SDL_RenderWindowToLogical/SDL_RenderLogicalToWindow

Co-authored-by: John Blat <johnblat64@protonmail.com>
Co-authored-by: John Blat <47202511+johnblat64@users.noreply.github.com>
2021-11-09 21:03:42 -08:00
Sam Lantinga 27ce914463 Send absolute mouse motion when in normal mouse mode and relative mouse motion when in relative mode on iOS
This keeps the SDL cursor in sync with the visible cursor when in normal mouse mode.
2021-11-09 20:51:42 -08:00
Sam Lantinga 19c129faba Added documentation that the UIApplicationSupportsIndirectInputEvents key must be set to true
in your application's Info.plist in order to get real Bluetooth mouse events.
2021-11-09 20:32:16 -08:00
Sam Lantinga 7681929cb4 Don't send the initial joystick axis event if the application is in the background 2021-11-09 12:30:37 -08:00
Sam Lantinga d31f90d9e1 Don't send game controller touchpad or sensor events unless the application has focus
Fixes https://github.com/libsdl-org/SDL/issues/4891
2021-11-09 12:09:01 -08:00
Sam Lantinga d2f756360e When making the window centered it should use windowed mode size since it doesn't affect fullscreen windows
Fixes bug https://github.com/libsdl-org/SDL/issues/4750
2021-11-09 11:55:02 -08:00
Susko3 1fc25bd839 Properly position the IME window(s) on windows 2021-11-09 11:00:46 -08:00
Ryan C. Gordon 04f42e0468 metal: Deal better with -[CAMetalLayer nextDrawable] returning nil.
Fixes #4863.
2021-11-09 12:03:12 -05:00
Sam Lantinga 0f2bf62935 Fixed building hidapi when libusb is available 2021-11-09 06:20:46 -08:00
Sylvain e8731933cc
Fixed warning: macro is not used 2021-11-09 13:33:25 +01:00
Sylvain c7065bf42f
Fix warning: declaration shadows a local variable 2021-11-09 13:33:24 +01:00
Cameron Gutman 715e7bda22 haptic: Don't enumerate joysticks if the joystick subsystem is active
The joystick subsystem has complex precedence logic to deal multiple competing
backends like XInput, RawInput, and WGI. Let it fire the MaybeAdd callbacks
for joystick devices, since it knows which backend will end up managing them.

This resolves a situation where the RawInput joystick backend would take
control of an XInput device but the XInput haptic backend would still create
a haptic device. Since the XInput joystick backend didn't own the underlying
joystick device, we'd end up with an orphaned haptic device that didn't work
with SDL_HapticOpenFromJoystick() on the associated joystick device.
2021-11-09 01:43:44 -06:00
Ethan Lee ae67c7d2da Implemented SDL_SetWindowMouseRect() on Wayland 2021-11-09 01:34:02 -05:00
Sam Lantinga 18e69827aa Fixed Linux build 2021-11-08 22:29:02 -08:00
Yufei Huang 881f747d5c Always destroy icon 2021-11-08 22:20:50 -08:00
Yufei Huang 7fea557b99 SDL_windowsmouse.c: Remove LR_COPYDELETEORG flag 2021-11-08 22:20:50 -08:00
Sam Lantinga 67c42cb44c Fixed Windows build 2021-11-08 22:16:01 -08:00
Sam Lantinga fd79607eb0 Added SDL_GetWindowMouseRect()
Also guarantee that we won't get mouse movement outside the confining area, even if the OS implementation allows it (e.g. macOS)
2021-11-08 21:34:48 -08:00
Sam Lantinga 4db546b092 Implemented SDL_SetWindowMouseRect() on macOS 2021-11-08 20:35:56 -08:00
Cameron Gutman 9c95c2491c x11: Use XCheckIfEvent() instead of XNextEvent() for thread-safety
A racing reader could read from our fd between SDL_IOReady()/X11_Pending()
and our call to XNextEvent() which will cause XNextEvent() to block for
more data. Avoid this by using XCheckIfEvent() which will never block.

This also fixes a bug where we could poll() for data, even when events were
already read and pending in the queue. Unlike the Wayland implementation,
this isn't totally thread-safe because nothing prevents a racing reader
from reading events into the queue between our XCheckIfEvent() and
SDL_IOReady() calls, but I think this is the best we can do with Xlib.
2021-11-08 19:17:18 -08:00
Sam Lantinga 2d23d66a61 Fixed SetWindowMouseRect return value on Windows 2021-11-08 16:33:50 -08:00
Sam Lantinga 7d21322df1 Implemented SDL_SetWindowMouseRect() on Windows 2021-11-08 16:29:19 -08:00
Ethan Lee 4b42c05ba1 video: Add SDL_SetWindowMouseRect.
This API and implementation comes from the Unreal Engine branch of SDL, which
originally called this "SDL_ConfineCursor".

Some minor cleanup and changes for consistency with the rest of SDL_video, but
there are two major changes:

1. The coordinate system has been changed so that `rect` is _window_ relative
   and not _screen_ relative, making it easier to implement without having
   global access to the display.
2. The UE version unset all rects when passing `NULL` as a parameter for
   `window`, this has been removed as it was an unused feature anyhow.

Currently this is only implemented for X, but can be supported on Wayland and
Windows at minimum too.
2021-11-08 14:16:54 -08:00
Sam Lantinga a3e8fd49e6 Cancel any accumulated mouse wheel motion in the opposite direction when the wheel direction changes
Fixes https://github.com/libsdl-org/SDL/issues/2912
2021-11-08 09:58:11 -08:00
Sam Lantinga 5dbbc8e61f Added mouse wheel deltas with floating point precision
Fixes https://github.com/libsdl-org/SDL/issues/4888
2021-11-08 09:44:31 -08:00
Sam Lantinga d95a52c9a5 Fixed comment typo 2021-11-08 09:39:21 -08:00
Ethan Lee fc998b8ec9
wayland: Return true for HasScreenKeyboardSupport only if no physical keyboard exists 2021-11-08 12:37:10 -05:00