Skip to content

Commit

Permalink
Wayland: Implement native sub-windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Riteo committed Feb 6, 2025
1 parent f60f69a commit 0e1117d
Show file tree
Hide file tree
Showing 11 changed files with 1,237 additions and 465 deletions.
12 changes: 11 additions & 1 deletion doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,9 @@
<constant name="FEATURE_EMOJI_AND_SYMBOL_PICKER" value="31" enum="Feature">
Display server supports system emoji and symbol picker. [b]Windows, macOS[/b]
</constant>
<constant name="FEATURE_SELF_FITTING_WINDOWS" value="32" enum="Feature">
Display server automatically fits popups according to the screen boundaries. Window nodes should not attempt to do that themselves.
</constant>
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
Makes the mouse cursor visible if it is hidden.
</constant>
Expand Down Expand Up @@ -2176,7 +2179,10 @@
[b]Note:[/b] This flag is implemented on macOS and Windows.
[b]Note:[/b] Setting this flag will [b]NOT[/b] prevent other apps from capturing an image, it should not be used as a security measure.
</constant>
<constant name="WINDOW_FLAG_MAX" value="10" enum="WindowFlags">
<constant name="WINDOW_FLAG_POPUP_WM_HINT" value="10" enum="WindowFlags">
Signals the window manager that this window is supposed to be a window-manager-defined "popup" (usually a floating, borderless, immovable child window).
</constant>
<constant name="WINDOW_FLAG_MAX" value="11" enum="WindowFlags">
Max value of the [enum WindowFlags].
</constant>
<constant name="WINDOW_EVENT_MOUSE_ENTER" value="0" enum="WindowEvent">
Expand Down Expand Up @@ -2206,6 +2212,10 @@
Sent when the window title bar decoration is changed (e.g. [constant WINDOW_FLAG_EXTEND_TO_TITLE] is set or window entered/exited full screen mode).
[b]Note:[/b] This flag is implemented only on macOS.
</constant>
<constant name="WINDOW_EVENT_FORCE_CLOSE" value="8" enum="WindowEvent">
Sent when the window has been forcibly closed by the Display Server. The window shall immediately hide and clean any internal rendering references.
[b]Note:[/b] This flag is implemented only on Linux (Wayland).
</constant>
<constant name="WINDOW_EDGE_TOP_LEFT" value="0" enum="WindowResizeEdge">
Top-left edge of a window.
</constant>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@
[b]Note:[/b] This flag is implemented on macOS and Windows.
[b]Note:[/b] Setting this flag will [b]NOT[/b] prevent other apps from capturing an image, it should not be used as a security measure.
</constant>
<constant name="FLAG_MAX" value="10" enum="Flags">
<constant name="FLAG_MAX" value="11" enum="Flags">
Max value of the [enum Flags].
</constant>
<constant name="CONTENT_SCALE_MODE_DISABLED" value="0" enum="ContentScaleMode">
Expand Down
Loading

0 comments on commit 0e1117d

Please sign in to comment.