summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-03-05 09:56:26 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-03-05 09:56:26 +0100
commit7d80635fce1d0c44fa69d4d8cf3da40fa998f9c7 (patch)
tree7f58ac7272b8041ff2addb30ebc7b10d97aed801
parentb59166d77ad46a924aa919c334c973756a892cea (diff)
parentcfdb9688481657f0b395dddfd7d91620979df85d (diff)
downloadredot-engine-7d80635fce1d0c44fa69d4d8cf3da40fa998f9c7.tar.gz
Merge pull request #89172 from bruvzg/force_native_windows
[Window] Allow to override viewport and project settings and force use of native window.
-rw-r--r--doc/classes/Window.xml3
-rw-r--r--scene/main/window.cpp22
-rw-r--r--scene/main/window.h4
3 files changed, 29 insertions, 0 deletions
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index 2acf0532e8..9c0e8011dc 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -590,6 +590,9 @@
[b]Note:[/b] This property is implemented only on macOS.
[b]Note:[/b] This property only works with native windows.
</member>
+ <member name="force_native" type="bool" setter="set_force_native" getter="get_force_native" default="false">
+ If [code]true[/code], native window will be used regardless of parent viewport and project settings.
+ </member>
<member name="initial_position" type="int" setter="set_initial_position" getter="get_initial_position" enum="Window.WindowInitialPosition" default="0">
Specifies the initial type of position for the [Window]. See [enum WindowInitialPosition] constants.
</member>
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 9c2509404c..6632dd9033 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1209,8 +1209,26 @@ void Window::_update_window_callbacks() {
DisplayServer::get_singleton()->window_set_drop_files_callback(callable_mp(this, &Window::_window_drop_files), window_id);
}
+void Window::set_force_native(bool p_force_native) {
+ if (force_native == p_force_native) {
+ return;
+ }
+ force_native = p_force_native;
+ if (is_visible()) {
+ WARN_PRINT("Can't change \"force_native\" while a window is displayed. Consider hiding window before changing this value.");
+ }
+}
+
+bool Window::get_force_native() const {
+ return force_native;
+}
+
Viewport *Window::get_embedder() const {
ERR_READ_THREAD_GUARD_V(nullptr);
+ if (force_native && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SUBWINDOWS)) {
+ return nullptr;
+ }
+
Viewport *vp = get_parent_viewport();
while (vp) {
@@ -2802,6 +2820,9 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_contents_minimum_size"), &Window::get_contents_minimum_size);
+ ClassDB::bind_method(D_METHOD("set_force_native", "force_native"), &Window::set_force_native);
+ ClassDB::bind_method(D_METHOD("get_force_native"), &Window::get_force_native);
+
ClassDB::bind_method(D_METHOD("set_content_scale_size", "size"), &Window::set_content_scale_size);
ClassDB::bind_method(D_METHOD("get_content_scale_size"), &Window::get_content_scale_size);
@@ -2926,6 +2947,7 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_window"), "set_flag", "get_flag", FLAG_POPUP);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "extend_to_title"), "set_flag", "get_flag", FLAG_EXTEND_TO_TITLE);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_native"), "set_force_native", "get_force_native");
ADD_GROUP("Limits", "");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size", PROPERTY_HINT_NONE, "suffix:px"), "set_min_size", "get_min_size");
diff --git a/scene/main/window.h b/scene/main/window.h
index e37a98bd2d..ffcf50ccdd 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -122,6 +122,7 @@ private:
bool visible = true;
bool focused = false;
WindowInitialPosition initial_position = WINDOW_INITIAL_POSITION_ABSOLUTE;
+ bool force_native = false;
bool use_font_oversampling = false;
bool transient = false;
@@ -273,6 +274,9 @@ public:
void set_initial_position(WindowInitialPosition p_initial_position);
WindowInitialPosition get_initial_position() const;
+ void set_force_native(bool p_force_native);
+ bool get_force_native() const;
+
void set_current_screen(int p_screen);
int get_current_screen() const;