Commit Graph

99 Commits (master)

Author SHA1 Message Date
Riteo 0e21840973 Wayland: Add environment variable to disable libdecor loading
Libdecor has some quirks and depending on the setup it might be useful
to switch to the xdg-shell branch. Recompiling the whole engine without
libdecor is not an acceptable way to do that.
2025-12-16 19:12:49 +07:00
Rémi Verschelde 3e2f769ddf
Merge pull request #113947 from deralmas/wl-misc-fixes/cleanup-forgor
Wayland: Add missing destroy calls for text input and tablet
2025-12-16 11:26:53 +07:00
Rémi Verschelde d84a8a63fa
Merge pull request #113946 from deralmas/wl-misc-fixes/mfw-mutating-a-copy
Wayland: Fix accidental copy during global remove
2025-12-16 11:26:47 +07:00
Rémi Verschelde 5d5db072f3
Merge pull request #113656 from deralmas/gray-goo-scenario
Wayland: Work around window scale ambiguity
2025-12-16 11:26:42 +07:00
Rémi Verschelde 61b5f80a50
Merge pull request #113256 from deralmas/wl-keyboard-stuff
Wayland: Misc keyboard touchups
2025-12-16 11:26:31 +07:00
Thaddeus Crews 206f1b5a7c
Merge pull request #113977 from deralmas/wl-misc-fixes/shhhhh
Wayland: Silence `window_get_wl_surface` on invalid window
2025-12-15 08:01:05 +07:00
Dery Almas 874dd28d66 Wayland: Silence window_get_wl_surface on invalid window
Makes it more consistent with the rest of the `WaylandThread` methods
(so that we can silently check for the window's existence).

Fixes errors when trying to capture the pointer when no surface has been
pointed yet (its logic assumed that this method was silent).

We double-check everywhere anyway but I added it in some places where we
can't either guarantee that it'll check (to avoid segfaults) or that
would be useful to report directly.
2025-12-13 10:10:29 +07:00
Dery Almas 1d1cd7cc1a Wayland: Add missing destroy calls for text input and tablet
Thank you Kiisu_Master for finding this!
2025-12-12 19:22:19 +07:00
Dery Almas b439a71db3 Wayland: Fix accidental copy during global remove
We were accidentally mutating a copy during cleanup of the viewporter
and fractional scale manager.

Thank you Aaron Franke for finding this out :D
2025-12-12 19:06:29 +07:00
Pāvels Nadtočajevs 1251348c96
[Wayland] Implement `keyboard_get_label_from_physical` 2025-12-10 13:19:35 +07:00
Berke Güzel 48c50bacba Wayland: Fix laggy window resize
scale_changed and size_changed were incorrectly initialized to true,
causing redundant WindowRectMessage and DPI change events to be pushed
on every configure event regardless of actual changes.
2025-12-07 13:29:19 +07:00
Dery Almas 99b109e981 Wayland: Work around window scale ambiguity 2025-12-06 00:54:50 +07:00
Rémi Verschelde 1c7ef74f4f
Merge pull request #113346 from deralmas/wl-keyboard-saga/unify-keys
Wayland: Unify key handling logic
2025-12-01 11:50:11 +07:00
Dery Almas 9a814b4444 Wayland: Unify key handling logic
Previously we had different logic for direct key presses and client-side
key repetition, as one queued up input events and the other dispatched
them directly (client-side key repetition is run from the main thread).

I kinda figured out that this difference doesn't really matter, as we
can queue them up before the thread message dispatching logic. That's
exactly what we do now, which allows us to make a single method for both
of them, making the code much clearer and simplifying future maintenance.

This patch also includes a tiny fixup in the compose logic, which checks
for the validity of the generated key event before actually working with
it. The cases in which we can end up with an invalid reference are very
few, so it's not the end of the world, but it's still absolutely a good
idea to check, to avoid nasty surprises down the line.
2025-11-30 05:11:40 +07:00
LanzaSchneider 3a965d50fe Fix incorrect format specifier for bool in Wayland libdecor 2025-11-29 10:20:27 +07:00
Riteo Siuga f90a9ad659 Destroy XKB keymap and state on seat capability change
Wasn't that much of a concern as it would have been disposed of next
time a keyboard got added, but it's still a good thing to do.
2025-11-27 23:02:08 +07:00
Dery Almas b0a42784f1 Wayland: Fix SIGFPE with repeat rate of 0
We always divided by the rate, which could be zero, which is a valid
value (it means "disable key repeating").
2025-11-27 22:37:28 +07:00
Dery Almas 8fb195e20d Wayland: Fix Wayland driver in export templates
I might have accidentally put the socket connection logic inside a
`TOOLS_ENABLED` `#ifdef` xD
2025-11-25 03:36:16 +07:00
Dery Almas 8ced63315a Wayland: Implement compose and dead key support 2025-11-22 23:30:23 +07:00
Dery Almas bbf65ae72f Wayland: Implement game embedding
This patch introduces a new protocol proxy, which multiplxes Wayland
clients into a single connection, allowing us to redirect calls (e.g.
create toplevel -> create subsurface). Mixed with some state tracking
and emulation, we can embed a full-featured client into the editor.
2025-11-19 21:24:18 +07:00
Thaddeus Crews 2d7380c3ff
Merge pull request #111493 from deralmas/racing-the-thread
Wayland: Defer event thread initialization to late initialization
2025-11-06 08:13:13 +07:00
Riteo Siuga 4df96fc7ab Wayland: Set window parent before commit
Fixes a timing issue where dialogs got configured right before having
their parent set. This gave compositors the time to resize/rearrange the
dialog as if it were a normal window, only to be marked as "floating"
right away. On niri, this manifested as huge dialog windows.

This is achieved with the addition of a `p_parent_id` parameter to
`window_create`, akin to its popup counterpart.

`window_create` now also accepts a single `Size2i` parameter instead of
two integers, in line with the rest of the `WaylandThread` API. The
original idea was to have a very "barebones" API, akin to the `drivers/`
directory, but that didn't pan out.
2025-10-28 04:10:28 +07:00
Dery Almas ab205a78ce Wayland: defer event thread initialization to late initialization
This race condition made me pull my hair. `wl_display_roundtrip` has its
own little event loop, which apparently conflicts hard with the
always-running event loop thread.

I kinda assumed that it would be thread-safe thanks to its internal
`wl_display_prepare_read` call that the docs talk about but that's
clearly not enough.

Luckily this method is called very few times and the only dangerous
instances are in the initialization routine, which first starts the
thread and then does various roundtrips. Libdecor has also some internal
roundtrips of its own which would often fail. Starting the thread after
all initialization fixes the issue.

Tested this by spamming *lots* of `wl_display_roundtrip` in
`WaylandThread::init()` with and without this fix.
2025-10-10 23:25:00 +07:00
Rémi Verschelde a6e44be2dc
Merge pull request #105587 from deralmas/framing-this-moment
Wayland: Emulate frame event for old `wl_seat` versions
2025-10-07 13:06:47 +07:00
Thaddeus Crews 21fd4faf1b
Merge pull request #107469 from Ivorforce/vector-localvector-explicit-span-conversions
Remove implicit conversions between `LocalVector` and `Vector`
2025-09-30 11:19:17 +07:00
Thaddeus Crews ce157a446f
Merge pull request #107096 from ArchercatNEO/xdg-toplevel-icon
Wayland: Implement the xdg-toplevel-icon-v1 protocol
2025-09-22 08:50:10 +07:00
Lukas Tenbrink abe3b481ae Make conversions from `LocalVector` to `Vector` explicit. 2025-09-16 21:41:28 +07:00
ArchercatNEO 188b47a29b Wayland: Implement the xdg-toplevel-icon-v1 protocol
Closes #87747
Requires a compositor which supports xdg-toplevel-icon-v1.
As of this commit only KWin supports this protocol.
2025-08-22 09:45:28 +07:00
Riteo Siuga b60b68055f Wayland: Fix division by zero when scale is less than 1
The `Vector2i` division operator casts doubles down to `int32_t`. It
would thus truncate the fractional scale factor to 0 if less than 1,
resulting in a FPE on x86_64.
2025-06-21 03:09:51 +07:00
Thaddeus Crews 856d7108e0
Merge pull request #106414 from Riteo/unexpected-frame
Wayland: Fix stuck pointer buttons on window leave
2025-06-18 18:13:45 +07:00
Riteo 67c317c58d Wayland: Add missing return in selection logic
Fixup to "Wayland: Check selection devices before using them"

This slipped under the radar... until for some reason optimized builds
started crashing, perhaps due to timing-related shenanigans, no idea.
2025-05-26 20:36:15 +07:00
Thaddeus Crews 202b1176a4
Merge pull request #106251 from ArchercatNEO/wayland-cursor-shape
[Wayland] Implement the cursor-shape-v1 protocol
2025-05-16 10:29:02 +07:00
ArchercatNEO 3cd7b5b9a8 [Wayland] Implement the cursor-shape-v1 protocol
Related #106229. The cursor-shape protocol allows us to not have to deal with cursor theming and instead depend on the
compositor for it.
This still does not quite solve the issue when the compositor doesn't implement the protocol
(or running under the x11 backend) but for gnome/kde and a few more this should resolve things.
2025-05-15 15:42:48 +07:00
Riteo a3913b045d Wayland: Fix stuck pointer buttons on window leave
This issue came from the frame-based refactoring done in the multiwin
PR.

It looks like some (all?) compositors group certain events alongside
`wl_pointer::leave`, which I absolutely did not expect. The docs don't
seem to mention it either from what I can tell.

We now fall-back on the old pointed window if and only if the current
window is invalid and the old one isn't. Each state fetch is guarded
with an `ERR_FAIL_NULL` so this should still catch any potentially
corrupted window with missing data but a valid ID.

I also added the usual big comment so that this "quirk" does not get
lost to time.
2025-05-14 23:30:16 +07:00
mara d213e72866 wayland: Unbreak build with libdecor=no
In #101774, some libdecor-specific code was added, but without adding the guards. This broke the build with
`libdecor=no`.

Add `#ifdef` guard as necessary.
2025-05-14 13:36:45 +07:00
Thaddeus Crews 3947cbe3b2
Merge pull request #104386 from Repiteo/core/cpp-math
Core: Replace C math headers with C++ equivalents
2025-04-27 19:21:22 +07:00
Riteo Siuga 48882f3ca4 Wayland: Handle fifo_v1 and clean up suspension logic
Before, the WSI was unfortunately quite broken and we had work around it
by manually pacing frames. Needless to say it was not an ideal solution.

Now, the WSI can make use of the new fifo_v1 protocol to work properly.
If it's available, we'll trust the WSI by disabling manual frame pacing.

While we're at it, let's clean up the suspension code a bit by removing
some duplicated stuff and handling the suspension state through a switch
case.
2025-04-20 18:05:35 +07:00
Riteo 2e41412ee4 Wayland: Emulate frame event for old wl_seat versions
Multiwindow support simplified input handling by processing all data
only during a `wl_seat::frame` event, which got introduced in wl_seat
version 5. If the compositor reports an older version, we manually call
the frame event handler.
2025-04-20 17:11:08 +07:00
Thaddeus Crews ad40939b6f
Core: Replace C math headers with C++ equivalents
- Minor restructuring to ensure `math_funcs.h` is the central point for math functions
2025-04-16 15:49:02 +07:00
Thaddeus Crews 0d267e7b1e
Core: Add dedicated `BitField` template 2025-04-11 11:53:26 +07:00
Pāvels Nadtočajevs 9abe2e5294
Add `uri_file_decode` to handle `+` in file names. 2025-04-07 23:49:17 +07:00
Riteo 84d3adcf2f Wayland: Implement native sub-windows
The backend is now mature enough to not explode with multiple windows
but the `DisplayServer` API still cannot meet some guarantees required
by the various Wayland protocols we use. To meet those guarantees this
patch adds three new elements to the DisplayServer API, with relative
handling logic for `Window` and `Popup` nodes:

 - `WINDOW_EVENT_FORCE_CLOSE`, which tells a window to *forcefully*
close itself and ensure a proper cleanup of its references, as Wayland
enforces this behavior;

 - `WINDOW_FLAG_POPUP_WM_HINT`, which explicitly declares a window as a
"popup", as Wayland enforces this distinction and heuristics are not
reliable enough;

 - `FEATURE_SELF_FITTING_WINDOWS`, which signals that the compositor can
fit windows to the screen automatically and that nodes should not do
that themselves.

Given the size of this feature, this patch also includes various
`WaylandThread` reworks and fixes including:

 - Improvements to frame wait logic, with fixes to various stalls and a
configurable (through a `#define`) timeout amount;

 - A proper implementation of `window_can_draw`;

 - Complete overhaul of pointer and tablet handling. Now everything is
always accumulated and handled only on each respective `frame` event.
This makes their logic simpler and more robust.

 - Better handling of pointer leaving and pointer enter/exit event
sending;

 - Keyboard focus tracking;

 - More solid window references using IDs instead of raw pointers as
windows can be deleted at any time;

 - More aggressive messaging to window nodes to enforce rects imposed by
the compositor.
2025-04-04 20:23:25 +07:00
Kiro 23129a66ed Replace append_utfx with direct String::utfx 2025-03-30 19:56:38 +07:00
Lukas Tenbrink ffa6ef220b Use `append_` instead of `parse_` for `String` methods. 2025-03-27 17:51:02 +07:00
Thaddeus Crews d9125ebebe
Merge pull request #101293 from Ivorforce/string-to-pointer-conversion
Remove implicit conversions from `String`, `Char16String` and `CharString` to data pointers.
2025-03-07 15:12:12 +07:00
Rémi Verschelde a8a1009468 Merge pull request #102641 from Riteo/modifying-spacetime-itself
Wayland: Unstuck keys with same keycode
2025-02-11 23:59:12 +07:00
Riteo 54755a27e9 Wayland: Unstuck keys with same keycode
This fixes once and for all the core issue of different Godot `keycode`s
released from the same raw XKB keycode.

The `InputEventKey` `keycode` value _should_ map to the "unmodified"
key, but unfortunately there's an ambiguity with their encoding for
"special" keys ("delete", "insert", etc.), in witch they ignore their
unicode representation. This means that a key that is special when plain
but a character when modified would never be properly picked up, so we
do indeed change its keycode. As a consequence of this exception, some
Godot keys never receive release events and get "stuck".

This patch adds an extra check through an `HashMap` to "unstuck" keys
that changed while having the same keycode.

I also could not resist simplifying a bit the regular key event
generation method but this makes things more consistent and predictable
IMO.
2025-02-11 13:16:16 +07:00
Riteo cbd68eb403 Wayland: Fix engine stalls wihle waiting frames
There were two edge cases in the frame waiting logic (aka manual frame
throttling or emulated vsync) which would cause the editor to stall in
one way or another:

 1. Waiting right after starting the editor would cause a deadlock
between both threads until something happened in the Wayland event
queue, in turn unblocking the Wayland thread and kickstartin the whole
thing;

 2. Starting the editor (and probably other long-loading stuff) without
low consumption mode would suspend the window and never commit its
surfaces, thus never signaling the compositor that we want frame events.
2025-02-11 01:33:36 +07:00
Adam Scott 1376828ef6
Fix `fr+oss` layout issues with KP period
Co-authored-by: Riteo Siuga <riteo@posteo.net>
2025-02-08 17:17:11 +07:00
Riteo 140a63be25 Linux/BSD: Modify only keypad keys
The `keycode` field of `InputEventKey` is supposed to be "unshifted";
That is, what the key would output if no modifier keys were pressed.
This should match what's written on the key label, but `Key` enumerates
also all keypad keys, which require a modifier. We thus require some
extra checks for them.

Note that this can still allow "stuck keys", but that's an even deeper
problem.
2025-02-02 19:19:15 +07:00