From 64d789aba7b5f57611d503be55e9405ff389e05e Mon Sep 17 00:00:00 2001
From: bruvzg <7645683+bruvzg@users.noreply.github.com>
Date: Fri, 24 May 2024 17:32:32 +0300
Subject: [PATCH] Fix `get_position_with_decorations` and
`get_size_with_decorations` for embedded windows.
---
doc/classes/Window.xml | 2 ++
scene/main/window.cpp | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index 9c0e8011dc28..286b35d6426e 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -118,12 +118,14 @@
Returns the window's position including its border.
+ [b]Note:[/b] If [member visible] is [code]false[/code], this method returns the same value as [member position].
Returns the window's size including its border.
+ [b]Note:[/b] If [member visible] is [code]false[/code], this method returns the same value as [member size].
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index e9a7123da071..1649f8b73c7c 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -397,6 +397,16 @@ Point2i Window::get_position_with_decorations() const {
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
return DisplayServer::get_singleton()->window_get_position_with_decorations(window_id);
}
+ if (visible && is_embedded() && !get_flag(Window::FLAG_BORDERLESS)) {
+ Size2 border_offset;
+ if (theme_cache.embedded_border.is_valid()) {
+ border_offset = theme_cache.embedded_border->get_offset();
+ }
+ if (theme_cache.embedded_unfocused_border.is_valid()) {
+ border_offset = border_offset.max(theme_cache.embedded_unfocused_border->get_offset());
+ }
+ return position - border_offset;
+ }
return position;
}
@@ -405,6 +415,16 @@ Size2i Window::get_size_with_decorations() const {
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
return DisplayServer::get_singleton()->window_get_size_with_decorations(window_id);
}
+ if (visible && is_embedded() && !get_flag(Window::FLAG_BORDERLESS)) {
+ Size2 border_size;
+ if (theme_cache.embedded_border.is_valid()) {
+ border_size = theme_cache.embedded_border->get_minimum_size();
+ }
+ if (theme_cache.embedded_unfocused_border.is_valid()) {
+ border_size = border_size.max(theme_cache.embedded_unfocused_border->get_minimum_size());
+ }
+ return size + border_size;
+ }
return size;
}