Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

[Linux] Implement `window_set_mouse_passthrough` and `WINDOW_FLAG_MOUSE_PASSTHROUGH` flag support on Wayland.

Pāvels Nadtočajevsce6d760b317d
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index 8e434247b4b..763263eb297 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -1650,7 +1650,7 @@
<param index="0" name="keycode" type="int" enum="Key" />
<description>
Converts a physical (US QWERTY) [param keycode] to one in the active keyboard layout.
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="keyboard_get_label_from_physical" qualifiers="const">
@@ -1658,14 +1658,14 @@
<param index="0" name="keycode" type="int" enum="Key" />
<description>
Converts a physical (US QWERTY) [param keycode] to localized label printed on the key in the active keyboard layout.
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="keyboard_get_layout_count" qualifiers="const">
<return type="int" />
<description>
Returns the number of keyboard layouts.
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="keyboard_get_layout_language" qualifiers="const">
@@ -1673,7 +1673,7 @@
<param index="0" name="index" type="int" />
<description>
Returns the ISO-639/BCP-47 language code of the keyboard layout at position [param index].
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="keyboard_get_layout_name" qualifiers="const">
@@ -1681,7 +1681,7 @@
<param index="0" name="index" type="int" />
<description>
Returns the localized name of the keyboard layout at position [param index].
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="keyboard_set_current_layout">
@@ -1689,7 +1689,7 @@
<param index="0" name="index" type="int" />
<description>
Sets the active keyboard layout.
- [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="mouse_get_button_state" qualifiers="const">
@@ -2572,7 +2572,7 @@
[/csharp]
[/codeblocks]
[b]Note:[/b] On Windows, the portion of a window that lies outside the region is not drawn, while on Linux (X11) and macOS it is.
- [b]Note:[/b] This method is implemented on Linux (X11), macOS and Windows.
+ [b]Note:[/b] This method is implemented on Linux (X11/Wayland), macOS, and Windows.
</description>
</method>
<method name="window_set_popup_safe_rect">
@@ -3376,7 +3376,7 @@
</constant>
<constant name="WINDOW_FLAG_MOUSE_PASSTHROUGH" value="7" enum="WindowFlags">
All mouse events are passed to the underlying window of the same application.
- [b]Note:[/b] This flag is implemented on Linux (X11), macOS, and Windows.
+ [b]Note:[/b] This flag is implemented on Linux (X11/Wayland), macOS, and Windows.
</constant>
<constant name="WINDOW_FLAG_SHARP_CORNERS" value="8" enum="WindowFlags">
Window style is overridden, forcing sharp corners.
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index f41cabc5d26..147a477a23f 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -791,7 +791,7 @@
[/codeblocks]
[b]Note:[/b] This property is ignored if [member mouse_passthrough] is set to [code]true[/code].
[b]Note:[/b] On Windows, the portion of a window that lies outside the region is not drawn, while on Linux (X11) and macOS it is.
- [b]Note:[/b] This property is implemented on Linux (X11), macOS and Windows.
+ [b]Note:[/b] This property is implemented on Linux (X11/Wayland), macOS, and Windows.
</member>
<member name="nonclient_area" type="Rect2i" setter="set_nonclient_area" getter="get_nonclient_area" default="Rect2i(0, 0, 0, 0)">
If set, defines the window's custom decoration area which will receive mouse input, even if normal input to the window is blocked (such as when it has an exclusive child opened). See also [signal nonclient_window_input].
@@ -1019,7 +1019,7 @@
<constant name="FLAG_MOUSE_PASSTHROUGH" value="7" enum="Flags">
All mouse events are passed to the underlying window of the same application.
[b]Note:[/b] This flag has no effect in embedded windows.
- [b]Note:[/b] This flag is implemented on Linux (X11), macOS, Windows.
+ [b]Note:[/b] This flag is implemented on Linux (X11/Wayland), macOS, Windows.
</constant>
<constant name="FLAG_SHARP_CORNERS" value="8" enum="Flags">
Window style is overridden, forcing sharp corners.
diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp
index ca321fde6ad..a80f38ca12c 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.cpp
+++ b/platform/linuxbsd/wayland/display_server_wayland.cpp
@@ -1090,8 +1090,18 @@ void DisplayServerWayland::window_set_title(const String &p_title, DisplayServer
}
void DisplayServerWayland::window_set_mouse_passthrough(const Vector<Vector2> &p_region, DisplayServerEnums::WindowID p_window_id) {
- // TODO
- DEBUG_LOG_WAYLAND(vformat("wayland stub window_set_mouse_passthrough region %s", p_region));
+ MutexLock mutex_lock(wayland_thread.mutex);
+
+ ERR_FAIL_COND(!windows.has(p_window_id));
+
+ WindowData &wd = windows[p_window_id];
+ if (wd.mpass_region == p_region) {
+ return;
+ }
+
+ wd.mpass_region = p_region;
+
+ wayland_thread.window_set_input_region(p_window_id, window_get_flag(DisplayServerEnums::WINDOW_FLAG_MOUSE_PASSTHROUGH), wd.mpass_region);
}
void DisplayServerWayland::window_set_rect_changed_callback(const Callable &p_callable, DisplayServerEnums::WindowID p_window_id) {
@@ -1361,6 +1371,10 @@ void DisplayServerWayland::window_set_flag(DisplayServerEnums::WindowFlags p_fla
ERR_FAIL_COND_MSG(wd.created && (wd.flags & DisplayServerEnums::WINDOW_FLAG_POPUP_WM_HINT_BIT) != p_enabled, "Popup hint can't changed while window is opened.");
} break;
+ case DisplayServerEnums::WINDOW_FLAG_MOUSE_PASSTHROUGH: {
+ wayland_thread.window_set_input_region(p_window_id, p_enabled, wd.mpass_region);
+ } break;
+
default: {
}
}
diff --git a/platform/linuxbsd/wayland/display_server_wayland.h b/platform/linuxbsd/wayland/display_server_wayland.h
index e6bb73a4d8e..a0241e0b88b 100644
--- a/platform/linuxbsd/wayland/display_server_wayland.h
+++ b/platform/linuxbsd/wayland/display_server_wayland.h
@@ -81,6 +81,8 @@ class DisplayServerWayland : public DisplayServer {
bool emulate_vsync = false;
+ Vector<Vector2> mpass_region;
+
#ifdef GLES3_ENABLED
struct wl_egl_window *wl_egl_window = nullptr;
#endif
diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp
index 3ad1c48df84..42acbfae3b0 100644
--- a/platform/linuxbsd/wayland/wayland_thread.cpp
+++ b/platform/linuxbsd/wayland/wayland_thread.cpp
@@ -34,6 +34,7 @@
#include "core/config/engine.h"
#include "core/io/image.h"
+#include "core/math/geometry_2d.h"
#include "core/os/os.h"
#ifdef __FreeBSD__
@@ -5001,6 +5002,37 @@ void WaylandThread::window_try_set_mode(DisplayServerEnums::WindowID p_window_id
}
}
+void WaylandThread::window_set_input_region(DisplayServerEnums::WindowID p_window_id, bool p_empty_region, const Vector<Vector2> &p_region) {
+ ERR_FAIL_COND(!windows.has(p_window_id));
+ WindowState &ws = windows[p_window_id];
+
+ wl_region *region = nullptr;
+ if (p_empty_region) {
+ region = wl_compositor_create_region(registry.wl_compositor);
+ } else if (!p_region.is_empty()) {
+ region = wl_compositor_create_region(registry.wl_compositor);
+
+ double win_scale = window_state_get_scale_factor(&ws);
+ Size2i scaled_size = scale_vector2i(ws.rect.size, win_scale);
+ for (int x = 0; x < scaled_size.x; x++) {
+ for (int y = 0; y < scaled_size.y; y++) {
+ Vector2 point = Vector2(x, y);
+ if (Geometry2D::is_point_in_polygon(point, p_region)) {
+ // Convert region points to window logical scale.
+ point = scale_vector2i(point, 1.0 / win_scale);
+ wl_region_add(region, point.x, point.y, 1, 1);
+ }
+ }
+ }
+ }
+
+ wl_surface_set_input_region(ws.wl_surface, region);
+
+ if (region) {
+ wl_region_destroy(region);
+ }
+}
+
void WaylandThread::window_set_borderless(DisplayServerEnums::WindowID p_window_id, bool p_borderless) {
ERR_FAIL_COND(!windows.has(p_window_id));
WindowState &ws = windows[p_window_id];
diff --git a/platform/linuxbsd/wayland/wayland_thread.h b/platform/linuxbsd/wayland/wayland_thread.h
index 25f8e677779..7031b05cc0e 100644
--- a/platform/linuxbsd/wayland/wayland_thread.h
+++ b/platform/linuxbsd/wayland/wayland_thread.h
@@ -1309,6 +1309,7 @@ public:
DisplayServerEnums::WindowMode window_get_mode(DisplayServerEnums::WindowID p_window_id) const;
void window_set_borderless(DisplayServerEnums::WindowID p_window_id, bool p_borderless);
+ void window_set_input_region(DisplayServerEnums::WindowID p_window_id, bool p_empty_region, const Vector<Vector2> &p_region);
void window_set_title(DisplayServerEnums::WindowID p_window_id, const String &p_title);
void window_set_app_id(DisplayServerEnums::WindowID p_window_id, const String &p_app_id);