godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.34k stars 21.06k forks source link

`warp_mouse()` function does not trigger `mouse_entered` signal on Controls on macOS #61502

Open squabix opened 2 years ago

squabix commented 2 years ago

Godot version

v3.4.1.stable.official

System information

MacBook Air

Issue description

I was working on making a controller/joystick-compatible cursor for my game to add controller support. I ended up using the function get_viewport().warp_mouse(pos) which correctly warps the mouse to the given position.

When I was testing this out though, I noticed that buttons did not seem to respond when the mouse was moved over them. I then tried using the function Input.warp_mouse_position(pos) to move the mouse instead, but the same problem reoccured.

In fact, no Control nodes seem to detect when the mouse is moved over them.

Steps to reproduce

  1. Open a Godot project
  2. Add a Control node to the scene
  3. Add a Button node to the scene and scale it so that it's easy to click on
  4. Add a script to the Control node
  5. Copy and paste the following code into the Control node:

extends Control

var mouse: Vector2

func _input(event): if event is InputEventMouseMotion: mouse = event.position elif InputEventKey and event.scancode == KEY_SHIFT: mouse.y -= 10 get_viewport().warp_mouse(mouse)

indent the code as needed

  1. Save and run the scene
  2. Move the mouse under the Button and press the shift key repeatedly
  3. When the mouse reaches theButton, the hover animation for the Button shouldn't play
  4. Click on the Button and the press animation should play, but if you continue to press the shift key, the mouse will go past the Button without the hover animation stopping

Minimal reproduction project

MouseWarpBug.zip

Sauermann commented 2 years ago

I am unable to replicate this issue on Linux in v4.0.beta.custom_build [e69b7083d]. Seems to be restricted to v3.x or to Mac.

MatthewBernardon commented 1 year ago

Still an issue in v4.1.2 on Mac.

BimDav commented 7 months ago

Could this please be looked at by someone who knows the macos platform part of Godot? It's a relatively big undocumented limitation of MacOS builds. My guess is that since warp_mouse() uses CGWarpMouseCursorPosition, which does not send any event corresponding to the (simulated) mouse movement, events should be sent manually, but I was not able to fix this.