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

Drop physics mouseover as soon as the mouse moves over a Control #68019

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

Sauermann
Copy link
Contributor

@Sauermann Sauermann commented Oct 29, 2022

fix #61924
alternative to #68018

_drop_physics_mouseover() was added into set_input_as_handled as a fix for #29575 to drop physics mouseover when the mouse is over a control.
The current implementation however doesn't check, if the mouse is actually over a Control, which leads to #61924, where physics-mouseover is dropped even if the mouse is not over a Control.
This patch changes the behavior, so that it is verified that the mouse is actually over a Control, before dropping physics mouseover.
This patch doesn't call _drop_physics_mouseover() in set_input_as_handled but as soon as the mouse enters the area of a Control.

@Sauermann Sauermann requested a review from a team as a code owner October 29, 2022 14:25
@Sauermann Sauermann changed the title Restrict physics mouseover dropping in set_input_as_handled Drop physics mouseover only if mouse is over a Control in set_input_as_handled Oct 29, 2022
@kleonc kleonc added this to the 4.0 milestone Oct 30, 2022
@Sauermann
Copy link
Contributor Author

It should be safe to cherry-pick this for Godot 3.

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Nov 14, 2022
Copy link
Member

@RandomShaper RandomShaper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's something fishy in all this, but for the time being I can't propose anything better than this patch. I hope at some point I can really look deeply into some of the corner cases and hard edges of input handling that don't quite settle as robust enough to me.

@Sauermann
Copy link
Contributor Author

Sauermann commented Nov 14, 2022

@RandomShaper
Thinking about it, this could be a different - maybe more robust - approach (will test it later):
This will drop physics mouse-over whenever the mouse moves on a Control, so that the physics-mouseover is dropped, before the Controls receive their MOUSE_ENTER notification.
This change is closely related to #67791.

diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 43a2c9473e..ddf9cac7dd 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1669,6 +1669,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
                        _gui_cancel_tooltip();
 
                        if (over) {
+                               if (!gui.mouse_over) {
+                                       _drop_physics_mouseover();
+                               }
                                _gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER);
                                gui.mouse_over = over;
                        }
@@ -3039,8 +3042,6 @@ bool Viewport::gui_is_drag_successful() const {
 }
 
 void Viewport::set_input_as_handled() {
-       _drop_physics_mouseover();
-
        if (!handle_input_locally) {
                ERR_FAIL_COND(!is_inside_tree());
                Viewport *vp = this;

@Sauermann Sauermann changed the title Drop physics mouseover only if mouse is over a Control in set_input_as_handled Drop physics mouseover as soon as the mouse moves over a Control Nov 14, 2022
@Sauermann
Copy link
Contributor Author

Sauermann commented Nov 14, 2022

I have updated this patch with the mentioned change. This is a better method, because

  • in the previous solution _drop_physics_mouseover was called during every set_input_as_handled, even for events, that have no impact on physics-mouseover
  • in the new solution _drop_physics_mouseover is called only once, when the mouse moves to the area of a Control, and not for every mouse-move-event.

That way the previously reported issue #29575 doesn't get reintroduced, while #61924 still gets solved. This kind of reverts #29579.

Copy link
Member

@RandomShaper RandomShaper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@akien-mga akien-mga merged commit 40163b9 into godotengine:master Nov 14, 2022
@akien-mga
Copy link
Member

Thanks!

@Sauermann Sauermann deleted the fix-physics-mouseover-drop branch November 14, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:3.x Considered for cherry-picking into a future 3.x release regression topic:gui topic:physics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using shortcut on Button generates mouse_exited signal on the selected collider
6 participants