Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Window] Allow to override viewport and project settings and force use of native window. #89172

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
22 changes: 22 additions & 0 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Window : public Viewport {
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;
Expand Down Expand Up @@ -273,6 +274,9 @@ class Window : public Viewport {
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;

Expand Down
Loading