Drop mouse focus and over when gui input is globally disabled

Since some porjects may be relying on the former behavior, this is opt-in via a new project setting, disabled by default, but enabled for new projects, since it's the new standard behavior (and the only one in 4.0).
This commit is contained in:
Pedro J. Estébanez 2022-03-13 12:43:27 +01:00
parent 3eee2f45a3
commit 3d7821bf1f
5 changed files with 26 additions and 6 deletions

View file

@ -538,6 +538,12 @@
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0"> <member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden. Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
</member> </member>
<member name="gui/common/drop_mouse_on_gui_input_disabled" type="bool" setter="" getter="" default="false">
If enabled, the moment [member Viewport.gui_disable_input] is set to [code]false[/code] to disable GUI input in a viewport, current mouse over and mouse focus will be dropped.
That behavior helps to keep a robust GUI state, with no surprises when input is resumed regardless what has happened in the meantime.
If disabled, the legacy behavior is used, which consists in just not doing anything besides the GUI input disable itself.
[b]Note:[/b] This is set to [code]true[/code] by default for new projects and is the recommended setting.
</member>
<member name="gui/common/swap_ok_cancel" type="bool" setter="" getter=""> <member name="gui/common/swap_ok_cancel" type="bool" setter="" getter="">
If [code]true[/code], swaps OK and Cancel buttons in dialogs on Windows and UWP to follow interface conventions. If [code]true[/code], swaps OK and Cancel buttons in dialogs on Windows and UWP to follow interface conventions.
</member> </member>

View file

@ -470,6 +470,7 @@ private:
initial_settings["application/config/icon"] = "res://icon.png"; initial_settings["application/config/icon"] = "res://icon.png";
initial_settings["rendering/environment/default_environment"] = "res://default_env.tres"; initial_settings["rendering/environment/default_environment"] = "res://default_env.tres";
initial_settings["physics/common/enable_pause_aware_picking"] = true; initial_settings["physics/common/enable_pause_aware_picking"] = true;
initial_settings["gui/common/drop_mouse_on_gui_input_disabled"] = true;
if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) { if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) {
set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR); set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR);

View file

@ -1219,6 +1219,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0)); Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0));
ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/fps/force_fps", PropertyInfo(Variant::INT, "debug/settings/fps/force_fps", PROPERTY_HINT_RANGE, "0,1000,1")); ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/fps/force_fps", PropertyInfo(Variant::INT, "debug/settings/fps/force_fps", PROPERTY_HINT_RANGE, "0,1000,1"));
GLOBAL_DEF("physics/common/enable_pause_aware_picking", false); GLOBAL_DEF("physics/common/enable_pause_aware_picking", false);
GLOBAL_DEF("gui/common/drop_mouse_on_gui_input_disabled", false);
GLOBAL_DEF("debug/settings/stdout/print_fps", false); GLOBAL_DEF("debug/settings/stdout/print_fps", false);
GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false); GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);

View file

@ -2058,9 +2058,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
} }
if (gui.mouse_focus_mask == 0 && over != gui.mouse_over) { if (gui.mouse_focus_mask == 0 && over != gui.mouse_over) {
if (gui.mouse_over) { _drop_mouse_over();
_gui_call_notification(gui.mouse_over, Control::NOTIFICATION_MOUSE_EXIT);
}
_gui_cancel_tooltip(); _gui_cancel_tooltip();
@ -2177,9 +2175,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
} }
if (over != gui.mouse_over) { if (over != gui.mouse_over) {
if (gui.mouse_over) { _drop_mouse_over();
_gui_call_notification(gui.mouse_over, Control::NOTIFICATION_MOUSE_EXIT);
}
_gui_cancel_tooltip(); _gui_cancel_tooltip();
@ -2715,6 +2711,13 @@ void Viewport::_drop_mouse_focus() {
} }
} }
void Viewport::_drop_mouse_over() {
if (gui.mouse_over) {
_gui_call_notification(gui.mouse_over, Control::NOTIFICATION_MOUSE_EXIT);
gui.mouse_over = nullptr;
}
}
void Viewport::_drop_physics_mouseover(bool p_paused_only) { void Viewport::_drop_physics_mouseover(bool p_paused_only) {
physics_has_last_mousepos = false; physics_has_last_mousepos = false;
@ -2958,6 +2961,14 @@ bool Viewport::gui_has_modal_stack() const {
} }
void Viewport::set_disable_input(bool p_disable) { void Viewport::set_disable_input(bool p_disable) {
if (p_disable == disable_input) {
return;
}
if (p_disable && GLOBAL_GET("gui/common/drop_mouse_on_gui_input_disabled")) {
_drop_mouse_focus();
_drop_mouse_over();
_gui_cancel_tooltip();
}
disable_input = p_disable; disable_input = p_disable;
} }

View file

@ -413,6 +413,7 @@ private:
void _canvas_layer_remove(CanvasLayer *p_canvas_layer); void _canvas_layer_remove(CanvasLayer *p_canvas_layer);
void _drop_mouse_focus(); void _drop_mouse_focus();
void _drop_mouse_over();
void _drop_physics_mouseover(bool p_paused_only = false); void _drop_physics_mouseover(bool p_paused_only = false);
void _update_canvas_items(Node *p_node); void _update_canvas_items(Node *p_node);