Skip to content

Commit 84d3adc

Browse files
committed
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.
1 parent 27b2ba6 commit 84d3adc

File tree

12 files changed

+1261
-473
lines changed

12 files changed

+1261
-473
lines changed

doc/classes/DisplayServer.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,9 @@
19581958
<constant name="FEATURE_NATIVE_COLOR_PICKER" value="32" enum="Feature">
19591959
Display server supports native color picker. [b]Linux (X11/Wayland)[/b]
19601960
</constant>
1961+
<constant name="FEATURE_SELF_FITTING_WINDOWS" value="33" enum="Feature">
1962+
Display server automatically fits popups according to the screen boundaries. Window nodes should not attempt to do that themselves.
1963+
</constant>
19611964
<constant name="MOUSE_MODE_VISIBLE" value="0" enum="MouseMode">
19621965
Makes the mouse cursor visible if it is hidden.
19631966
</constant>
@@ -2181,7 +2184,10 @@
21812184
[b]Note:[/b] This flag is implemented on macOS and Windows.
21822185
[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.
21832186
</constant>
2184-
<constant name="WINDOW_FLAG_MAX" value="10" enum="WindowFlags">
2187+
<constant name="WINDOW_FLAG_POPUP_WM_HINT" value="10" enum="WindowFlags">
2188+
Signals the window manager that this window is supposed to be an implementation-defined "popup" (usually a floating, borderless, untileable and immovable child window).
2189+
</constant>
2190+
<constant name="WINDOW_FLAG_MAX" value="11" enum="WindowFlags">
21852191
Max value of the [enum WindowFlags].
21862192
</constant>
21872193
<constant name="WINDOW_EVENT_MOUSE_ENTER" value="0" enum="WindowEvent">
@@ -2211,6 +2217,10 @@
22112217
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).
22122218
[b]Note:[/b] This flag is implemented only on macOS.
22132219
</constant>
2220+
<constant name="WINDOW_EVENT_FORCE_CLOSE" value="8" enum="WindowEvent">
2221+
Sent when the window has been forcibly closed by the Display Server. The window shall immediately hide and clean any internal rendering references.
2222+
[b]Note:[/b] This flag is implemented only on Linux (Wayland).
2223+
</constant>
22142224
<constant name="WINDOW_EDGE_TOP_LEFT" value="0" enum="WindowResizeEdge">
22152225
Top-left edge of a window.
22162226
</constant>

doc/classes/Popup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<members>
1212
<member name="borderless" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
1313
<member name="popup_window" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
14+
<member name="popup_wm_hint" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
1415
<member name="transient" type="bool" setter="set_transient" getter="is_transient" overrides="Window" default="true" />
1516
<member name="unresizable" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
1617
<member name="visible" type="bool" setter="set_visible" getter="is_visible" overrides="Window" default="false" />

doc/classes/Window.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@
670670
<member name="popup_window" type="bool" setter="set_flag" getter="get_flag" default="false">
671671
If [code]true[/code], the [Window] will be considered a popup. Popups are sub-windows that don't show as separate windows in system's window manager's window list and will send close request when anything is clicked outside of them (unless [member exclusive] is enabled).
672672
</member>
673+
<member name="popup_wm_hint" type="bool" setter="set_flag" getter="get_flag" default="false">
674+
If [code]true[/code], the [Window] will signal to the window manager that it is supposed to be an implementation-defined "popup" (usually a floating, borderless, untileable and immovable child window).
675+
</member>
673676
<member name="position" type="Vector2i" setter="set_position" getter="get_position" default="Vector2i(0, 0)">
674677
The window's position in pixels.
675678
If [member ProjectSettings.display/window/subwindows/embed_subwindows] is [code]false[/code], the position is in absolute screen coordinates. This typically applies to editor plugins. If the setting is [code]true[/code], the window's position is in the coordinates of its parent [Viewport].
@@ -879,7 +882,10 @@
879882
[b]Note:[/b] This flag is implemented on macOS and Windows.
880883
[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.
881884
</constant>
882-
<constant name="FLAG_MAX" value="10" enum="Flags">
885+
<constant name="FLAG_POPUP_WM_HINT" value="10" enum="Flags">
886+
Signals the window manager that this window is supposed to be an implementation-defined "popup" (usually a floating, borderless, untileable and immovable child window).
887+
</constant>
888+
<constant name="FLAG_MAX" value="11" enum="Flags">
883889
Max value of the [enum Flags].
884890
</constant>
885891
<constant name="CONTENT_SCALE_MODE_DISABLED" value="0" enum="ContentScaleMode">

0 commit comments

Comments
 (0)