From 0d88aadd53fe966942fb0aa13bce2d177648a897 Mon Sep 17 00:00:00 2001
From: bruvzg <7645683+bruvzg@users.noreply.github.com>
Date: Fri, 2 Feb 2024 09:46:01 +0200
Subject: [PATCH] Automatically set viewport background to transparent when
window flag is set.
---
doc/classes/Window.xml | 2 +-
scene/main/window.cpp | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index 618a774aae16..ab14f64aa1c4 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -675,7 +675,7 @@
If [code]true[/code], the [Window]'s background can be transparent. This is best used with embedded windows.
[b]Note:[/b] Transparency support is implemented on Linux, macOS and Windows, but availability might vary depending on GPU driver, display manager, and compositor capabilities.
- [b]Note:[/b] This property has no effect if either [member ProjectSettings.display/window/per_pixel_transparency/allowed], or the window's [member Viewport.transparent_bg] is set to [code]false[/code].
+ [b]Note:[/b] This property has no effect if [member ProjectSettings.display/window/per_pixel_transparency/allowed] is set to [code]false[/code].
If [code]true[/code], the [Window] can't be focused nor interacted with. It can still be visible.
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 99f9e11b1f57..fd64220c2c34 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -484,9 +484,12 @@ void Window::set_flag(Flags p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
flags[p_flag] = p_enabled;
+ if (p_flag == FLAG_TRANSPARENT) {
+ set_transparent_background(p_enabled);
+ }
+
if (embedder) {
embedder->_sub_window_update(this);
-
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
if (!is_in_edited_scene_root()) {
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id);
@@ -1285,6 +1288,9 @@ void Window::_notification(int p_what) {
_update_viewport_size(); // Then feed back to the viewport.
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
+ if (DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(FLAG_TRANSPARENT), window_id)) {
+ set_transparent_background(true);
+ }
} else {
// Create.
if (visible) {