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

Create a virtual mouse move event after moving child nodes in tree (partially reverted) #66625

Merged
merged 1 commit into from
May 30, 2023

Conversation

Sauermann
Copy link
Contributor

@Sauermann Sauermann commented Sep 29, 2022

This patch updates mouse cursor and mouse-over states without the need for additional mouse movements after a Node::move_child. It utilizes the infrastructure introduced in #58995 for updating the mouse cursor on scene changes.

resolve #40012

Update 2022-10-02: Add check, that base_window exists
Update 2022-11-03: Resolve merge conflict
Update 2022-11-12: Resolve merge conflict
Update 2023-01-06: Expose update_mouse_cursor_state to GDScript in order to close godotengine/godot-proposals#6052
Update 2023-01-28: Resolve merge conflict
Update 2023-05-29: Address changes of #75701 and resolve merge conflict

@Sauermann Sauermann requested a review from a team as a code owner September 29, 2022 21:57
@Chaosus Chaosus added this to the 4.0 milestone Oct 1, 2022
@Sauermann Sauermann force-pushed the fix-move-child-update branch from f932862 to 74af0ee Compare October 2, 2022 07:26
@Sauermann Sauermann requested a review from a team as a code owner October 2, 2022 07:26
@Sauermann Sauermann force-pushed the fix-move-child-update branch from 74af0ee to e8aaced Compare November 3, 2022 17:46
@Sauermann Sauermann force-pushed the fix-move-child-update branch from e8aaced to d92b523 Compare November 12, 2022 22:28
@KoBeWi
Copy link
Member

KoBeWi commented Dec 12, 2022

I checked your MRP in the issue and the signals seem to be emitted without mouse movement (in vanilla build). Can you confirm whether this PR is still relevant?

@Sauermann
Copy link
Contributor Author

Yes, I have verified, that the bug is still happening with v4.0.beta.custom_build [bc5d67c] on Linux X11 Xfce.
Also I have verified, that this PR still fixes this bug on Linux.

I can't reproduce the bug on Windows 10 with v4.0.beta.custom_build [bc5d67c]. The likely reason for this is #20357.
But when #20357 gets fixed, then this PR will also be needed on Windows 10.

scene/main/node.cpp Outdated Show resolved Hide resolved
@KoBeWi
Copy link
Member

KoBeWi commented Dec 12, 2022

I could approve based solely on the code (as I can't test), but I'm wondering why you made update_mouse_cursor_shape() virtual.

@Sauermann
Copy link
Contributor Author

The actual update needs to happen in a Window and not in a SubViewport, because SubViewportContainers might be hidden behind other Controls.
SubViewport::update_mouse_cursor_shape simply checks, if a containing Window is available and calls the update-function Window::update_mouse_cursor_shape in the containing Window. If the call happens within a Window, then there is no need to check for a containing Window (for example when called directly in the root-Window).

My impression was, that this scenario (where SubViewport and Window need to react differently to the same function-call) would be best solved by using virtual.

A different way would be to use if (Object::cast_to<Window>(this)) {} else {} in the Viewport::-function and remove the Window::-function (But this would add a dependency from Viewport to Window).
If that would be the preferred way, please let me know.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Makes sense.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 12, 2022

Or actually... isn't this only relevant for Control nodes? Maybe the update_mouse_cursor_shape() call could be moved to some move child callback in Control?

@Sauermann
Copy link
Contributor Author

Interesting idea. I will investigate it.

@Sauermann
Copy link
Contributor Author

Sauermann commented Dec 12, 2022

I had a look at this idea, which brought me to the following setting:
image

What happens, if Node and Node2 exchange places with respect to their common parent (besides #69979)?

In this case neither Button-node currently receives any Notification, that their position in the SceneTree has changed and that the mouse cursor needs to be updated.
I found the following possible solutions that could happen in Node::_move_child:

  • Introduce a new NOTIFICATION_ANCESTOR_MOVED_IN_TREE which gets sent to every child node (restricted to the current Viewport). If any Control-node receives this notification, it triggers a mouse-cursor-state update.
  • Send a change notification directly to the Viewport.

With this setting we are getting very close to the problem described in #42822.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 12, 2022

Soo is the original solution sufficient here? Or at least is it not something that would need to be reworked later to fix the other issues you mentioned? If yes, I think the PR is fine as is (still needs the comment tho).

@Sauermann Sauermann force-pushed the fix-move-child-update branch from d92b523 to 363b827 Compare December 14, 2022 20:42
@Sauermann
Copy link
Contributor Author

Soo is the original solution sufficient here

Yes, it is.

Or at least is it not something that would need to be reworked later to fix the other issues you mentioned

The basic idea is to create a mouse move event in order to update mouse cursor and mouse-over state after a change in the SceneTree. I believe, that this method is the right way to do it, because otherwise we would need a different function, that does the same things as Viewport::_gui_input_event for mouse-move-events (and that would need to be kept in sync with).

The other mentioned issue is a display-bug, as far as I understand it and will not interfere with cursor-updates.

So I don't think, that the approach will need to be overhauled at a later time. However some fine-adjustments will be necessary, like #69318.

Also I have updated the PR and included additional comments. It makes sense to document this behavior.

@Sauermann Sauermann force-pushed the fix-move-child-update branch from 363b827 to 26f01b3 Compare January 6, 2023 20:15
@Sauermann Sauermann requested a review from a team as a code owner January 6, 2023 20:15
@Sauermann Sauermann force-pushed the fix-move-child-update branch from 26f01b3 to 3420226 Compare January 27, 2023 23:03
@Sauermann
Copy link
Contributor Author

This was discussed in PR-review-meeting.
There are changes planned after 4.0 for the process of moving nodes. So at the moment it doesn't make sense to adjust this behavior. I will change this PR to focus only on solving the linked proposal.

@Sauermann
Copy link
Contributor Author

Please move to 4.1

@bruvzg bruvzg modified the milestones: 4.0, 4.1 Feb 9, 2023
@KoBeWi
Copy link
Member

KoBeWi commented Apr 18, 2023

There are changes planned after 4.0 for the process of moving nodes.

I guess this PR can be revised after #75701 was merged.

@Sauermann Sauermann force-pushed the fix-move-child-update branch from 3420226 to e99ae86 Compare May 29, 2023 20:43
This updates mouse cursor and mouse-over-states without the need
for additional mouse movements.
@Sauermann Sauermann force-pushed the fix-move-child-update branch from e99ae86 to ce10ca6 Compare May 29, 2023 20:46
@Sauermann
Copy link
Contributor Author

I guess this PR can be revised after #75701 was merged.

I had a look at #75701 and made the necessary adjustments.

@akien-mga akien-mga requested a review from RandomShaper May 30, 2023 07:31
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.

LGTM.

@YuriSizov YuriSizov changed the title Create a virtual mouse move event after moving child nodes Create a virtual mouse move event after moving child nodes in tree May 30, 2023
@YuriSizov YuriSizov merged commit 6dd5ccd into godotengine:master May 30, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@Sauermann Sauermann deleted the fix-move-child-update branch June 5, 2023 09:26
@akien-mga akien-mga changed the title Create a virtual mouse move event after moving child nodes in tree Create a virtual mouse move event after moving child nodes in tree (partial reverted) Jun 13, 2023
@akien-mga akien-mga changed the title Create a virtual mouse move event after moving child nodes in tree (partial reverted) Create a virtual mouse move event after moving child nodes in tree (partially reverted) Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mouse_entered/exited signal not emitted on call to raise
6 participants