67 Commits

Author SHA1 Message Date
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 +02: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 -05: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 +01: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 +00: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 -05: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 +02: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 -05:00
Thaddeus Crews
0d267e7b1e
Core: Add dedicated BitField template 2025-04-11 11:53:26 -05:00
Pāvels Nadtočajevs
9abe2e5294
Add uri_file_decode to handle + in file names. 2025-04-07 23:49:17 +03: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 +02:00
Kiro
23129a66ed Replace append_utfx with direct String::utfx 2025-03-30 19:56:38 +02:00
Lukas Tenbrink
ffa6ef220b Use append_ instead of parse_ for String methods. 2025-03-27 17:51:02 +01: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 -06: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 +01: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 +01: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 +01: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 -05: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 +01:00
Thaddeus Crews
f1c0b5b854
Merge pull request #101779 from Riteo/primary-mess
Wayland: Check selection devices before using them
2025-01-22 09:19:30 -06:00
Riteo
d12137bdda Wayland: Pass unmodified symbols to key events
Before this change we would internationalize the keycode itself in all
`InputEventKey`s, confusing the whole input subsystem.
2025-01-20 18:27:04 +01:00
Riteo Siuga
bed2a1927f Wayland: Check selection devices before using them
Looks like we never actually stopped the code from using bad pointers.
I even forgot the check in the primary selection code 🤦
2025-01-20 02:13:45 +01:00
Lukas Tenbrink
512abc38b2 Remove implicit conversions from String, Char16String and CharString to data pointers. Make conversions to StrRange implicit to aid transition. 2025-01-17 17:31:58 +01:00
Travis Lange
d713a22f2e fix wayland can set mode exclusive full screen 2025-01-14 20:21:52 -05:00
Pāvels Nadtočajevs
7f0b4e58b0 Implement DisplayServer.window_start_resize. 2025-01-07 07:58:02 +02:00
Rémi Verschelde
44f871ff72
Merge pull request #100898 from Summersay415/wayland-issue
Fix exclusive fullscreen on Wayland
2025-01-06 22:47:53 +01:00
Rémi Verschelde
35cf29bb21
Merge pull request #100715 from buresu/fix-wayland-ime-input
Fix last character deletion in Wayland IME input
2025-01-03 00:48:55 +01:00
Summersay415
8c1742c957 Fix exclusive fullscreen on Wayland 2025-01-02 21:49:49 +07:00
A Thousand Ships
a1846b27ea
Improve use of Ref.is_null/valid
Use `is_null` over `!is_valid` and vice versa.
2024-12-23 16:35:02 -05:00
Naoto Kondo
b719eed725 Fix last character deletion in Wayland IME input 2024-12-22 05:52:03 +09:00
Tiktalik
fb741715c1
Fixed incorrect use of vertical scroll where it should have been horizontal. 2024-12-20 00:53:10 -07:00
Pāvels Nadtočajevs
293be04ec8 Implement window_start_drag on Windows and Linux. 2024-12-17 16:49:27 +02:00
Thaddeus Crews
38775731e8
Merge pull request #99965 from Riteo/unstable-galore
Wayland: Add support for xdg-foreign-unstable-v2
2024-12-11 17:36:07 -06:00
Thaddeus Crews
f222cc43f3
Merge pull request #99633 from buresu/fix-wayland-keymapping
Fix underscore input not working with jp106 keyboard on wayland platform
2024-12-10 14:15:51 -06:00
Riteo
65c28ed31d Wayland: Add support for xdg-foreign-unstable-v2
The v1 version is deprecated and bound to be removed in the future from
all compositors. This patch adds a v1/v2 designator to everything
related to the protocol and prefers the v2 protocol if both are
available.

Additionally, renames the event handler to follow the Wayland interface
name, for consistency with the rest of the codebase.
2024-12-10 01:29:46 +01:00
MBCX
6bc80effbb Make Godot compile on FreeBSD 2024-12-05 12:33:55 -04:00
Pāvels Nadtočajevs
84650f2018 Implement DisplayServer.beep. 2024-12-03 12:43:26 +02:00
Naoto Kondo
f367a6c231 Fix underscore input not working with jp106 keyboard on wayland platform 2024-11-30 23:40:42 +09:00
Trevor Davenport
0d9a705e25 Wayland: Only set selection when there is not already a source.
Co-authored-by: Riteo Siuga <riteo@posteo.net>
2024-11-17 16:00:24 -07:00
Riteo
c15cd3acc4 Wayland: Simplify cursor code and fix custom cursors
Initially the WaylandThread cursor code was supposed to be as stateless
as possible but, as time went on, this wasn't possible.

This expectation made the resulting API quite convoluted, so this patch
aims to simplify it substantially bot in terms of API surface and, most
importantly, in terms of actual implementation complexity.

This patch also fixes custom cursors since I accidentally changed the
mmap flags to MAP_PRIVATE some time ago. This took me hours to notice.
2024-09-13 19:08:53 +02:00
Riteo
343ea9c6f7 Wayland: clear button mask on pointer leave
While experimenting with the recent "extent to title" PR, I noticed that
it's not guaranteed for a "button released" event to be emitted when
the pointer leaves the main surface, leaving some buttons stuck.

Not doing this for tablets since the spec makes this behavior clear and
explicit, so we (hopefully) shouldn't have this issue there.
2024-09-10 20:53:53 +02:00
Riteo
26d89bc8e9 Wayland: make primary selection logic consistent with main clipboard 2024-09-08 16:48:41 +02:00
Rémi Verschelde
78f47abe2b
Merge pull request #94022 from Riteo/a-fraction-of-the-work
Wayland: Switch pointer position handling to doubles
2024-08-22 00:10:31 +02:00
Riteo
0d1826e084 Wayland: Avoid recreating input objects on capability change
Before, multiple capability events would instantiate the same object
over and over as long as its bit was set. This caused issues with
hotplug and device suspension.
2024-08-09 15:42:23 +02:00
Riteo
e307fd60d8 Wayland: Fix error spam when interacting with decorations
Also tried to make tablet handling a bit tidier (less whitespace).

That said I'll uniform tablet handling better once we're back in the dev
cycle.
2024-07-20 03:46:35 +02:00
Riteo
a852e76196 Wayland: commit surface on window creation
This is needed for initializing xdg_surfaces when not using libdecor.
Now the pure xdg_shell code path should work again.
2024-07-15 22:11:24 +02:00
Riteo
2ff50119dc Wayland: switch pointer position handling to doubles
This reduces even further the amount of work we have to do when scaling
and potentially improves input accuracy as now the input code is free
from any form of rounding.
2024-07-07 09:07:29 +02:00
Riteo
3e0632cbd2 Wayland: scale relative pointer motion
Oops, forgot to do that. Motion-dependent stuff should now work properly
when using scaled displays.
2024-07-07 08:39:53 +02:00
Riteo
f27471fbd8 Wayland: minimize surface commits and limit them to the main thread
Before of this patch, as explained in the usual
commented-wall-of-text-longer-than-the-actual-patch-itself™, due to the
multithreaded nature of the Wayland thread, it was possible to commit a
surface while the renderer was doing stuff, which was _very_ wrong.

Initially the consequences of such a sin weren't obvious but, now that
explicit synchronization is becoming more and more common, we can't
commit a buffer randomly without basically guaranteeing a nasty, nasty
crash (and we should have avoided commits altogether in the first place
to ensure atomic surface updates).

We now only trigger a commit _in the main thread_ when low processor usage
mode is on _and_ if we know that we won't be rendering anything as, due to
its intermittent nature, it makes "legacy" (pre xdg_wm_base v6) frame
callback based suspension quite annoying.
2024-06-28 01:47:25 +02:00
bruvzg
be25e60f61
[Wayland] Implement IME support. 2024-06-11 12:24:54 +03:00
A Thousand Ships
955d5affa8
Reduce and prevent unnecessary random-access to List
Random-access access to `List` when iterating is `O(n^2)` (`O(n)` when
accessing a single element)

* Removed subscript operator, in favor of a more explicit `get`
* Added conversion from `Iterator` to `ConstIterator`
* Remade existing operations into other solutions when applicable
2024-05-04 16:08:55 +02:00