Commit Graph

7690 Commits (68103993520166dc2d573bdb5dfe0ed7a2f641ea)

Author SHA1 Message Date
Sam Lantinga b33f470901 Fixed detection of the PDP Afterglow Wireless Switch Controller over Bluetooth 2021-07-30 18:23:42 -07:00
Sam Lantinga 6af6950dbc Added support for the Victrix Gambit Tournament Controller 2021-07-30 18:23:42 -07:00
Sam Lantinga 243a8836af The PowerA Nintendo Switch Fusion Pro Controller has a working USB mode, enabled via the switch on the underside of the controller. 2021-07-30 18:23:41 -07:00
Ethan Lee 71897cc1c9 wayland: Always trigger a resize when handling a configure event.
When we removed the OpenGL resize workaround it introduced a problem for
fullscreen windows in particular: When leaving fullscreen we tried to send a
resize event, but UpdateFullscreenMode would send a SIZE_CHANGED immediately
after, deleting our resize event and causing the following configure event's
resize to be ignored. This timing issue resulted in fullscreen windows not
being resized at all when becoming a floating window.

By always forcing resize events from configure events, we ensure that RESIZED
always makes it through. SetWindowSize-type changes should be unaffected as
they do not fire configure events.
2021-07-30 16:05:06 -04:00
David Gow 8f06a629aa render: Fix -Wmaybe-uninitialized warning in RenderDrawLinesWithRects{,F}
The RenderDrawLinesWithRects and RenderDrawLinesWithRectsF functions can
sometimes call QueueCmdFillRects() with the data pointed to by frects
uninitialised. This can occur if none of the lines can be replaced with
rects, in which case the frects array is empty, and nrects is 0.

gcc 10.3.0 will detect this possibility, and print a warning like:
/home/david/Development/SDL/src/render/SDL_render.c: In function 'RenderDrawLinesWithRectsF':
/home/david/Development/SDL/src/render/SDL_render.c:2725:15: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]
 2725 |     retval += QueueCmdFillRects(renderer, frects, nrects);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/david/Development/SDL/src/render/SDL_render.c:499:1: note: by argument 2 of type 'const SDL_FRect *' to 'QueueCmdFillRects' declared here
  499 | QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect * rects, const int count)
      | ^~~~~~~~~~~~~~~~~

This is harmless, because when this is uninitialised, nrects is always
0, so QueueCmdFillRects() does nothing anyway. We therefore can work
around this by only calling QueueCmdFillRects() when nrects is nonzero.
Somewhat impressively, gcc recognises that this is now safe.
2021-07-30 10:53:49 -04:00
Ethan Lee c20ab7dae9 wayland: Fix GetWindowWMInfo for <2.0.15 2021-07-30 00:16:52 -07:00
Ryan C. Gordon 585c11c5ae
direct3d: Fix possibly-incorrect scissor test when clearing.
Thanks to @JayFoxRox who did the detective work on this!

Fixes #3357.
2021-07-30 00:33:15 -04:00
Cameron Gutman 6f684f674e cocoa: Add keyboard grab support
CGSSetGlobalHotKeyOperatingMode() is not a public API, so we will only
compile this in if SDL_MAC_NO_SANDBOX=1 is defined during compilation.
2021-07-29 19:06:43 -07:00
Sam Lantinga 69518b9ecc Make sure we don't send a resize event while a window is being destroyed
This fixes https://github.com/libsdl-org/SDL/issues/3669
2021-07-29 17:09:24 -07:00
Sam Lantinga 3ababa09c5 Don't explicitly use any C runtime library with Visual Studio
Visual Studio will still use Multi-threaded DLL by default, but since we don't link with a C runtime we won't end up with any Visual Studio runtime dependency.

This fixes https://github.com/libsdl-org/SDL/issues/4328
2021-07-29 15:17:42 -07:00
Ryan C. Gordon 659e1f0a3f
audiocvt: The to-5.1 converters now soften FL and FR channels more.
This is experimental and might be tweaked further.

Reference #4104.

Also reference:

https://github.com/Keriew/augustus/issues/194#issuecomment-847655049
2021-07-29 17:55:59 -04:00
Christian Rauch f20a85818c commit after setting/unsetting limits 2021-07-29 14:55:03 -07:00
Sam Lantinga 9984891ba8 Use the wl_touch object as a touch ID on Wayland (thanks @russelltg!)
This fixes https://github.com/libsdl-org/SDL/issues/4517
2021-07-29 14:46:24 -07:00
Ethan Lee 74162b7401 wayland: Add support for text-input-unstable-v3 2021-07-29 14:43:46 -07:00
Jessica Clarke e4411505ab Don't pack SDL_AudioCVT on CHERI architectures
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.

The referential safety is enforced through the use of tagged memory, and
there is only a single tag bit per capability-sized word, meaning it is
impossible to store capabilities at unaligned locations, either getting
a trap on load/store or the validity tag being stripped when
round-tripepd through memory.

Since this is a new ABI for which SDL has never been compiled before, we
do not need to be concerned with this compatibility measure, so just
don't pack the struct for CHERI architectures.

This code is inherently rather dubious anyway; if MSVC and GCC disagree
on struct layout when targeting Windows then that is a bug in GCC, but
likely extends from the bogus #pragma pack directives for MSVC in
begin_code.h, which will force types to be *underaligned* (and is
attempting to work around something that is fundamentally a broken idea
to be doing). In particular 8-byte-aligned types will be underaligned to
4 bytes, but only on MSVC.  Since that code is not used for GCC that is
probably the cause of the struct layout discrepancy, and there are
likely other instances of that throughout SDL. Moreover, the supposed
fix here is not in fact a fix, as now GCC will think SDL_AudioCVT is
only 1-byte-aligned but MSVC will think it's 4-byte or 8-byte-aligned,
meaning ABI incomatibility is introduced by this change. However,
removing it would break ABI compatibility for purely-GCC-compiled code
(as old binaries would see the struct as 1-byte-aligned and new binaries
would see the struct as 8-byte-aligned) so SDL is stuck with this until
it bumps its ABI.
2021-07-29 14:42:15 -07:00
Jessica Clarke 02daab8736 Fix pointer provenance in SDL_SIMDRealloc
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.

The C standard does not guarantee that if two pointers compare equal
they are the same pointer, as C pointers have a notion of provenance,
and compilers have been known to exploit this during optimisation. For
CHERI, this becomes even more important, as in-place expansion can
result in realloc returning a capability to the same address but with
increased capability bounds, and so reusing the old capability will trap
trying to access outside the bounds of the original allocation.

In the case that ptr == mem, memdiff and ptrdiff should still be equal,
so the only overhead is a small amount of pointer arithmetic and a store
of the new pointer (which is required per the C standard in order to not
be undefined behaviour when next loaded).

This also fixes the calculation of oldmem to use uintptr_t rather than
size_t as casting the pointer to size_t on CHERI will strip the
capability metadata, including the validity tag, with the subsequent
cast back to void * resulting in a null-derived capability whose
validity tag is clear and thus cannot be dereferenced without trapping.
2021-07-29 14:42:15 -07:00
Jessica Clarke 8f38ba4d68 Fix casts that should be using uintptr_t
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.

On most systems (anything with a flat memory hierarchy rather than using
segment-based addressing), size_t and uintptr_t are the same type.
However, on CHERI, size_t is just an integer offset, whereas uintptr_t
is still a capability as described above. Casting a pointer to size_t
will strip the metadata and validity tag, and casting from size_t to a
pointer will result in a null-derived capability whose validity tag is
not set, and thus cannot be dereferenced without faulting.

The audio and cursor casts were harmless as they intend to stuff an
integer into a pointer, but using uintptr_t is the idiomatic way to do
that and silences our compiler warnings (which our build tool makes
fatal by default as they often indicate real problems). The iconv and
egl casts were true positives as SDL_iconv_t and iconv_t are pointer
types, as is NativeDisplayType on most OSes, so this would have trapped
at run time when using the round-tripped pointers. The gles2 casts were
also harmless; the OpenGL API defines this argument to be a pointer type
(and uses the argument name "pointer"), but it in fact represents an
integer offset, so like audio and cursor the additional idiomatic cast
is needed to silence the warning.
2021-07-29 14:42:15 -07:00
Jessica Clarke c8b4edf3d0 Fix SDL_Event definition to support systems with pointers larger than 8 bytes
This is needed to support CHERI, and thus Arm's experimental Morello
prototype, where pointers are implemented using unforgeable capabilities
that include bounds and permissions metadata to provide fine-grained
spatial and referential memory safety, as well as revocation by sweeping
memory to provide heap temporal memory safety.
2021-07-29 14:42:15 -07:00
Sam Lantinga 9d457aa446 Don't uninitialize COM because of what appears to be a bug in Microsoft WGI reference counting.
This fixes https://github.com/libsdl-org/SDL/issues/4488
2021-07-29 14:25:13 -07:00
Sam Lantinga b3a0174b26 Scale the values correctly based on the sensor type (thanks @meyraud705) 2021-07-29 14:25:13 -07:00
Sam Lantinga 65ff00ec1b Query the rate for the correct sensor (thanks @meyraud705) 2021-07-29 14:25:13 -07:00
SDL Wiki Bot 72ee0ccdd5 Sync wiki -> header 2021-07-29 13:46:05 +00:00
Sam Lantinga a186a503e7 Added SDL_GameControllerGetSensorDataRate() to get the sensor update rate for a controller. 2021-07-29 06:43:39 -07:00
Sam Lantinga ce8261dd6d Only pump events once per frame and process all currently pending events
If you continually poll for events it's possible that new events can come in while you're still processing the last one, delaying rendering. This is more likely with high update rate sensors.
2021-07-29 06:36:20 -07:00
Brick 53987e9b4f Optimized SDL_Convert51ToStereo_AVX 2021-07-28 16:11:04 -07:00
Sam Lantinga 8e35ff5cb3 By default minimize real fullscreen windows when they lose focus so the desktop video mode is restored.
This fixes https://github.com/libsdl-org/SDL/issues/4039
2021-07-28 14:20:29 -07:00
Aaron Plattner 1e07dba09b x11: Use glXChooseFBConfig when available in X11_GL_GetVisual
When choosing an X11 Visual for a window based on its GLX capabilities, first
try glXChooseFBConfig (if available) before falling back to glXChooseVisual.
This normally does not make a difference because most GLX drivers create a
Visual for every GLXFBConfig, exposing all of the same capabilities.

For GLX render offload configurations (also know as "PRIME") where one GPU is
providing GLX rendering support for windows on an X screen running on a
different GPU, the GPU doing the offloading needs to use the Visuals that were
created by the host GPU's driver rather than being able to add its own. This
means that there may be fewer Visuals available for all of the GLXFBConfigs the
guest driver wants to expose. In order to handle that situation, the NVIDIA GLX
driver creates many GLXFBConfigs that map to the same Visual when running in a
render offload configuration.

This can result in a glXChooseVisual request failing to find a supported Visual
when there is a GLXFBConfig for that configuration that would have worked. For
example, when the game "Unnamed SDVX Clone" [1] tries to create a configuration
with multisample, glXChooseVisual fails because the Visual assigned to the
multisample GLXFBConfigs is shared with the GLXFBConfigs without multisample.

Avoid this problem by using glXChooseFBConfig, when available, to find a
GLXFBConfig with the requested capabilities and then using
glXGetVisualFromFBConfig to find the corresponding X11 Visual. This allows the
game to run, although it doesn't make me any better at actually playing it...

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Fixes: https://forums.developer.nvidia.com/t/prime-run-cannot-create-window-x-glxcreatecontext/180214

[1] https://github.com/Drewol/unnamed-sdvx-clone
2021-07-28 13:48:16 -07:00
Ozkan Sezer cf85710cf8 SDL_audiocvt.c: disable AVX for clang < 5 and gcc < 4.9
See: https://github.com/libsdl-org/SDL/issues/4533
2021-07-28 22:55:10 +03:00
Ryan C. Gordon cc4ab10195
windows: convert "//" comment to "/**/", add a FIXME.
Reference #4129
Reference #4177
2021-07-28 14:37:33 -04:00
Adam a203194893
Added in a MIME-type to the X11 clipboard. (#4385) 2021-07-28 14:06:51 -04:00
SDL Wiki Bot 5346cf842c Sync wiki -> header 2021-07-28 17:13:05 +00:00
Ethan Lee ad310d3900 wayland: libdecor support for SetWindowModalFor 2021-07-28 09:45:10 -07:00
Ethan Lee 93976ade3b wayland: libdecor support for GetWindowWMInfo 2021-07-28 09:45:10 -07:00
SDL Wiki Bot 46919b1e8e Sync wiki -> header 2021-07-28 16:11:06 +00:00
David Gow 1fb4429bc0 wayland: Avoid a pointer→TouchID cast warning
As of [1], SDL now compiles with a warning in SDL_waylandevents.c on
32-bit systems under gcc 10.3.0:

/tmp/SDL/src/video/wayland/SDL_waylandevents.c: In function 'seat_handle_capabilities':
/tmp/SDL/src/video/wayland/SDL_waylandevents.c:958:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  958 |         SDL_AddTouch((SDL_TouchID)seat, SDL_TOUCH_DEVICE_DIRECT, "wayland_touch");
      |                      ^
/tmp/SDL/src/video/wayland/SDL_waylandevents.c:964:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  964 |         SDL_DelTouch((SDL_TouchID)seat);
      |                      ^

This is due to SDL_TouchID always being 32-bit, but seat being a pointer
which is (obviously) only 32-bit on 32-bit systems. The conversion is
therefore harmless, so silence it with an extra cast via intptr_t.

This is what the cocoa backend does (and is similar to what the Win32
backend does, except with size_t).

Fixes: 03c19efbd1 ("Added support for multiple seats with touch input on Wayland")

[1]: 03c19efbd1
2021-07-28 09:05:23 -07:00
Ozkan Sezer 4a7799be18 --disable-wayland-shared implies --disable-libdecor-shared for now.
C.f.: https://github.com/libsdl-org/SDL/issues/4543
2021-07-28 17:01:02 +03:00
David Gow 18303c92bc Wayland: Fix building with --disable-wayland-shared with libdecor.
When wayland is not dynamically loaded (--enable-wayland-shared=no)
libdecor.h is not included unless SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
is set, so it fails to build.  We can't simply move the libdecor.h
include above the #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC block, as
libdecor.h itself #includes wayland headers we need to replace with
#defines. Instead, duplicate the #include.

Fixes https://github.com/libsdl-org/SDL/issues/4543

Note that this doesn't fix any of the underlying issues of libdecor
being treated as part of wayland, it just fixes the build. A better
solution would probably be to decouple the wayland dynamic loading
from the libdecor dynamic loading completely, though that is a lot
more work...
2021-07-28 17:01:02 +03:00
David Gow 21cba92423 wayland: Don't create zxdg toplevel decoration twice
Each window can have at most one zxdg toplevel decoration, but as of
[1], we accidentally create two. (If libdecor is not in use). This
causes wayland windows with server-side decorations (e.g. on KDE/KWin)
to crash with the message:

zxdg_decoration_manager_v1@7: error 1: decoration has been already constructed

This extra zxdg_decoration_manager_v1.get_toplevel_decoration() call was
introduced while deprecating wl-shell and xdg-shell-stable[1] support,
and possibly was a bad interaction with [2], which moved the decoration
creation around.

Fixes: 6aae5b44f8 ("Remove wl-shell and xdg-shell-unstable-v6 support (#4323)")

[1]: https://github.com/libsdl-org/SDL/pull/4323
[2]: https://github.com/libsdl-org/SDL/pull/4374
2021-07-28 04:12:39 -07:00
Ethan Lee 7b239edb83 wayland: Assign frame_callback on window creation.
Fixes a crash when creating and destroying a window without calling SwapWindow.
2021-07-28 00:48:05 -07:00
Sam Lantinga 41e1a2360f Correct the maximized size and position for borderless resizable windows
This fixes bug https://github.com/libsdl-org/SDL/issues/4043
2021-07-27 16:51:08 -07:00
Ethan Lee 03185e748b wayland: Tag/Check wl_output objects as well, fixes crashes when libdecor is in use 2021-07-27 16:05:53 -07:00
Ryan C. Gordon 871c11191b wayland: handle pending resizes immediately, not on SwapWindow.
This was originally a workaround for an old Mesa bug, since fixed, apparently,
and causes other problems.

Fixes #4326.
2021-07-27 18:24:09 -04:00
Sam Lantinga 51c61d7cdf Run the entire Cocoa messagebox function on the main thread.
This fixes bug https://github.com/libsdl-org/SDL/issues/4420
2021-07-27 14:57:18 -07:00
Sam Lantinga dfd3f30e88 Make Cocoa_HandleTitleButtonEvent() static since it's not used anywhere else 2021-07-27 14:27:37 -07:00
Sam Lantinga 14d58dc890 Fixed the parameter documentation 2021-07-27 14:23:40 -07:00
Ethan Lee a3eb297ec2 wayland: Rework enter/leave and update_scale_factor to avoid bogus wl_output data.
Also remove get_window_scale_factor() which was just pointless indirection.
2021-07-27 14:21:32 -07:00
Simon Zeni 6aae5b44f8
Remove wl-shell and xdg-shell-unstable-v6 support (#4323)
* wayland-protocol: update wayland.xml to 1.19.0

* wayland: remove shell_surface field from SDL_SysWMinfo

* wayland: remove wl_shell support

* waypand-protocols: update xdg-shell.xml to 1.20

* wayland: remove xdg-shell-unstable-v6 support

* wayland: deprecate wl shell surface syswm info, add xdg surface
2021-07-27 14:12:26 -07:00
Sam Lantinga 65dc4edb52 Reverted accidental Visual Studio version bump in SDL.sln 2021-07-27 12:51:44 -07:00
Sam Lantinga 88e4755c26 Make sure we don't try to turn on relative mouse mode while clicking on the window title bar.
This fixes bug https://github.com/libsdl-org/SDL/issues/4469
2021-07-27 12:43:45 -07:00
Sam Lantinga 7df6a9ea59 Add a test case for bug https://github.com/libsdl-org/SDL/issues/4469 2021-07-27 12:43:45 -07:00