Commit Graph

88 Commits

Author SHA1 Message Date
Frank Praznik 4d76c9cb46 video: wayland: Use wp-viewporter for fullscreen with non-native resolutions
Wayland doesn't support mode switching, however Wayland compositors can support the wp_viewporter protocol, which allows for the mapping of arbitrarily sized buffer regions to output surfaces.  Use this functionality, when available, for fullscreen output when using non-native display modes and/or when dealing with scaled desktops, which can incur significant overdraw without this extension.

This also allows for the exposure of arbitrarily sized, emulated display modes, which can be useful for legacy compatability.
2022-03-28 13:18:26 -04:00
Ethan Lee 7a1c45bd1c wayland: Optimize keyboard_handle_modifiers.
1. Mod index values are (mostly) constant, so can be done with xkb_state_new
2. Mods can change without the group changing, avoid remap events if possible

Lastly, as a bonus, I added braces to the locale check, because I was nearby.
2022-03-25 12:54:05 -04:00
Ethan Lee 2891f0821b wayland: Use xkb_keymap_mod to set mod state 2022-03-25 02:49:49 -04:00
Ethan Lee 6d9ca92626 wayland: Enforce text capitalization manually, for remapped keymods 2022-03-25 01:36:39 -04:00
Ethan Lee a75c6150e0 wayland: Add an xkb_keysym_t->SDL_Keycode mapping for backspace 2022-03-25 01:33:40 -04:00
Florian "sp1rit"​ 9125b244e7 wayland: Basic support for zwp_tablet_*v2 protocol 2022-03-23 13:47:46 -04:00
Weng Xuetian b11dfd7611 Only generate key repetition for keys that should repeat on wayland.
This fix repetition on modifier keys, e.g. Control.
2022-02-01 17:56:04 -05:00
Weng Xuetian a90a2e7582 Fix text_input_v3 preedit string
For every batch of text_input_v3 updates, if there is no preedit in this
batch, preedit should be cleared.
2022-02-01 15:51:26 -05:00
Ethan Lee 9a2bbd8acb wayland: Convert URI to local path for DropFile 2022-01-12 13:01:05 -05:00
Ethan Lee 3e1b3bc344
wayland: Horizontal wheel values do not need to be inverted 2022-01-10 10:07:44 -05:00
Joan Bruguera 9e6249fa54 wayland: Avoid spurious key repeats when not pumping events
Previous to this commit, key repeats events were typically generated when
pumping events, based on the time of when the events are pumped. However,
if an application doesn't call `SDL_PumpEvents` for some seconds, this time
can be multiple seconds in the future compared to the actual key up event time,
and generates key repeats even if a key was pressed only for an instant.

In practice, this can happen when the user presses a key which causes the
application to do something without pumping events (e.g. load a level).
In Crispy Doom & PrBoom+, when the user presses the key bound to "Restart
level/demo", the game doesn't pump events during the "screen melt" effect,
and the level is restarted multiple times due to spurious repeats.

To fix this, if the key up event is among the events to be pumped, we generate
the key repeats there, since in the Wayland callback we receive the time when
the key up event happened. Otherwise, we know no key up event happened and we
can generate as many repeats as necessary after pumping.

Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
2022-01-08 14:10:22 -08:00
Joan Bruguera 461724d287 wayland: Refactor time fields in SDL_WaylandKeyboardRepeat
Refactorization with no functional changes.

Instead of `next_repeat_ms` containing a timestamp based on SDL ticks, we make
it zero-based relative to the key press time, and we store the key press time in
SDL ticks in a new field.

This refactorization is groundwork for future commits which need to use the
key press and release timestamps provided by the Wayland API, which are also
expressed in milliseconds, but whose base does not match the one for SDL ticks.

Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
2022-01-08 14:10:22 -08:00
Joan Bruguera fb0c3040c0 wayland: Avoid infinite loop in keyboard_repeat_handle
If `repeat_info->next_repeat_ms` overflows, many key presses will be generated.
In the worst case, `now = 0xFFFFFFFFU` and the loop will never terminate.

Rearrange the comparison in order to gracefully handle the overflow case.

Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
2022-01-08 14:10:22 -08:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Valentin Hăloiu cb8fa5f9c3 wayland: fix keycodes of swapped xkb modifier keys 2021-12-09 09:30:58 -08:00
Sylvain cb9f85e8d0 Don't use "round", so that it's doesn't show up while searching for the function 2021-11-22 08:38:46 -08:00
Ozkan Sezer 781caec2b2 SDL_waylandevents.c (keyboard_handle_keymap): silenced -Wwrite-strings . 2021-11-15 00:55:24 +03:00
Ethan Lee ae67c7d2da Implemented SDL_SetWindowMouseRect() on Wayland 2021-11-09 01:34:02 -05:00
Cameron Gutman a559864968 x11/wayland: Fix signal handling while blocking in WaitEventTimeout()
Add a new flag to avoid suppressing EINTR in SDL_IOReady(). Pass the
flag in WaitEventTimeout() to ensure that a SIGINT will wake up
SDL_WaitEvent() without another event coming in.
2021-10-30 21:23:45 -07:00
Cameron Gutman c97c46877f core: Convert SDL_IOReady()'s 2nd parameter to flags 2021-10-30 21:23:45 -07:00
Cameron Gutman 2bf36bfac4 wayland: Implement WaitEventTimeout() and SendWakeupEvent()
We can have spurious wakeups in WaitEventTimeout() due to Wayland events
that don't end up causing us to generate an SDL event. Fortunately for us,
SDL_WaitEventTimeout_Device() handles this situation properly by calling
WaitEventTimeout() again with an adjusted timeout.
2021-10-27 19:16:53 -05:00
Cameron Gutman 408a93a1ec wayland: Use multi-thread event reading APIs
Wayland provides the prepare_read()/read_events() family of APIs for
reading from the display fd in a deadlock-free manner across multiple
threads in a multi-threaded application. Let's use those instead of
trying to roll our own solution using a mutex.

This fixes an issue where a call to SDL_GL_SwapWindow() doesn't swap
buffers if it happens to collide with SDL_PumpEvents() in the main
thread. It also allows coexistence with other code or toolkits in
our process that may want read and dispatch events themselves.
2021-10-25 12:00:35 -04:00
David Gow eadc8f9355 wayland: Cleanup some SDL_TryLockMutex() calls.
Check the result of these against 0 explicitly, so that it's obvious
we're bailing out on failure, not success.
2021-10-02 11:14:52 -04:00
David Gow 25f9e32b0e wayland: Don't let multiple threads dispatch wayland events at once
wl_display_dispatch() will block if there are no events available, and
while we try to avoid this by using SDL_IOReady() to verify there are
events before calling it, there is a race condition between
SDL_IOReady() and wl_display_dispatch() if multiple threads are
involved.

This is made more likely by the fact that SDL_GL_SwapWindow() calls
wl_display_dispatch() if vsync is enabled, in order to wait for frame
events. Therefore any program which pumps events on a different thread
from SDL_GL_SwapWindow() could end up blocking in one or other of them
until another event arrives.

This change fixes this by wrapping wl_display_dispatch() in a new mutex,
which ensures only one thread can compete for wayland events at a time,
and hence the SDL_IOReady() check should successfully prevent either
from blocking.
2021-10-02 11:03:20 -04:00
Ethan Lee 7ed415d2ed wayland: Reuse KeySymToUcs4 to replicate X11 keymap behavior 2021-09-23 11:50:47 -07:00
Ethan Lee 1a4e2e5ef7 wayland: For text, ignore key events when Ctrl is held
Fixes #4695
2021-09-23 14:34:39 -04:00
Aleksey Rybalkin 402b86f2a8 waylandevents: prevent segfault if xkb compose table is not found
this can happen e.g. on pure wayland system where there is no X11
locales for xkbcommon to find.
2021-08-15 10:11:19 -04:00
David Gow fbc364908a Use the new SDL_clamp() macro where sensible
There were a few places throughout the SDL code where values were
clamped using SDL_min() and SDL_max(). Now that we have an SDL_clamp()
macro, use this instead.
2021-08-14 09:01:14 -07:00
Ethan Lee 32f909f7e3 wayland: Remove redundant waylanddyn.h includes.
All files including waylanddyn.h already include waylandvideo.h first.
2021-08-03 14:57:22 -04:00
Sebastian Krzyszkowiak 54aea2446e wayland: Disable key repeat when repeat rate equals 0
This fixes a crash on pressing keyboard button when compositor sends
zero as repeat rate, indicating that key repeat should be disabled.

From Wayland protocol spec:

> Negative values for either rate or delay are illegal. A rate of zero
> will disable any repeating (regardless of the value of delay).
2021-07-31 21:40:27 -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
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
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
Christian Rauch 9e6fcbe72c wayland: client-side decoration 2021-07-25 14:54:12 -07:00
Sam Lantinga 03c19efbd1 Added support for multiple seats with touch input on Wayland
This fixes bug https://github.com/libsdl-org/SDL/issues/4517
2021-07-24 15:25:50 -07:00
meyraud705 4ada14a267 Replace libc functions to SDL equivalent in wayland video subsystem
Wayland video subsystem uses a mix of libc and SDL function.
This patch switches libc functions to SDL ones and fixes a mismatch in memory
allocation/dealoccation of SDL_Cursor in SDL_waylandmouse.c (calloc on line 201
and SDL_free on line 313) which caused memory corruption if custom memory
allocator where provided to SDL.
2021-07-21 09:28:38 -07:00
Ethan Lee 8e3ec34d34 wayland: Refactor toplevel mapping, implement HideWindow 2021-04-21 13:11:47 -04:00
Luis Cáceres 5c78df9c23
Support key composing (i.e. dead keys) in Wayland driver (#4296)
Based on an old patch by chw from the old Bugzilla issue tracker.

Authored-by: chw

Co-authored-by: Sam Lantinga <slouken@libsdl.org>
2021-04-13 16:56:50 -07:00
Ethan Lee dfcd5fbcad wayland: Set the keymap in keyboard_handle_modifiers 2021-04-13 13:30:50 -07:00
Ethan Lee 875f839df4 wayland: A bunch of clipboard safety fixes.
Also removed Wayland_get_data_device because it was a pointless getter function.
2021-04-09 22:30:08 -07:00
Ethan Lee 7510245af9 wayland: Create the data_device only after both device_manager and input exist.
There is no guarantee on what order the Wayland interfaces will come in, but the
callbacks were assuming that wl_data_device_manager would could before wl_seat.
This would cause certain desktops to not have any data_device to work with,
meaning certain features like the clipboard would silently no-op.
2021-04-09 22:30:08 -07:00
Ethan Lee eeee730833 wayland: Implement IME support.
Note that this is purely to make it possible to enter text that requires
composition - for example, before this commit Kanji input didn't work at all.

The big problem this still has is that we need the window position, and this is
still not implemented. Once we have this information we can do the equivalent
of XTranslateCoordinates to put the rectangle where we want it.
2021-03-29 15:54:36 -07:00
Cameron Gutman 8c5b7af2d2 Wayland: Fix mouse pointer hiding on Plasma Wayland
Unlike Mutter and Sway, KWin actually checks the serial passed in
wl_pointer_set_cursor(). The serial provided is supposed to be the
serial of the pointer enter event, but We were always passing 0.
This caused KWin to drop our requests to hide the cursor.

Thanks to the KDE folks for spotting this in my debug logs.

Fixes #3576
2021-02-25 18:47:12 -08:00
Cameron Gutman d133a5f6f7 wayland: cancel key repeat when keyboard focus is lost
SDL_SetKeyboardFocus(NULL) will lift any keys still pressed when keyboard focus
leaves the window, but then key repeat comes behind our backs and presses the
key down again. This results in an infinite stream of SDL_KEYDOWN events when
focus leaves the window with a key down (particularly noticeable with Alt+Tab).
2021-02-10 10:22:16 -05:00
Cameron Gutman 7ff3832e4d Fix continuous scrolling speed on Wayland
Wayland compositors seem to have standardized on 10 units per "wheel tick" for
continuous scroll events, so we need to convert these axis values to ticks by
dividing by 10 before reporting them in SDL_MOUSEWHEEL events.
2021-01-24 00:51:25 -05:00
Cameron Gutman cf84ec441f Improve reliability of cursor hiding on GNOME Wayland
Hiding the cursor doesn't appear to work reliably on GNOME when another window
steals mouse focus right as we call SDL_ShowCursor(SDL_DISABLE). This can happen
when the keyboard shortcut inhibition permission prompt appears in response to a
call to SDL_SetRelativeMouseMode() with SDL_HINT_GRAB_KEYBOARD=1. The result is
that the default cursor is stuck locked in position and visible on screen
indefinitely.

By redrawing the cursor on pointer focus enter, the cursor now disappears upon
the first mouse motion event. It's not perfect but it's way better than the
current behavior.
2021-01-24 00:51:25 -05:00
Cameron Gutman d789ba8332 Implement keyboard grab support for Wayland
Use zwp_keyboard_shortcuts_inhibit_manager_v1 to allow SDL applications
to capture system keyboard shortcuts like Alt+Tab when keyboard grab is
enabled via SDL_HINT_GRAB_KEYBOARD.
2021-01-24 00:51:24 -05:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga cb36189692 Fixed bug 5235 - All internal sources should include SDL_assert.h
Ryan C. Gordon

We should really stick this in SDL_internal.h or something so it's always available.
2020-12-09 07:16:22 -08:00