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

This commit is contained in:
bruvzg 2024-03-04 20:21:10 +02:00
parent a07dd0d6a5
commit cfdb968848
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
3 changed files with 29 additions and 0 deletions

View file

@ -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");