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

Captured mouse mode fails to capture mouse if it's outside the window on OSX #42321

Closed
jamie-pate opened this issue Sep 24, 2020 · 1 comment · Fixed by #42327
Closed

Captured mouse mode fails to capture mouse if it's outside the window on OSX #42321

jamie-pate opened this issue Sep 24, 2020 · 1 comment · Fixed by #42327

Comments

@jamie-pate
Copy link
Contributor

jamie-pate commented Sep 24, 2020

Godot version:
3.2.3-stable

OS/device including version:

GPU: Intel Iris Pro OpenGL Engine
MacBookPro11,4
Quad-Core Intel Core i7
Intel Iris Pro VENDOR=0x80867 DEVICE=0x0d26
Mac OS X 10.15.6

Issue description:

This doesn't seem to work if the mouse cursor is over the dock when the mode is switched.

This is the code that I'm using to switch mouse modes:

func _set_active(value):
	active = value
	if $PlayerHead/Camera and value:
		$PlayerHead/Camera.current = value
	if value:
		var w: Node = world_mgr
		if w && w.has_method('get_arg'):
			if !w.get_arg('no-capture-mouse'):
				Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	else:
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
		velocity = Vector3()

Steps to reproduce:

Download https://github.com/godotengine/godot-demo-projects/tree/d4bf89d3647097443bc4f3f8625d7564a1e80a01/3d/voxel
(or the attached .zip)
Open the project and run.
Click Start Game > Flat Grass and then press esc to open the menu and uncapture the mouse.
move the mouse down to the dock, and press esc again to re-capture the mouse.
Moving the mouse around and pressing arrow keys will still interact with the game, but when you click, it will click on the dock, because mouse button input is not captured?

See these video examples: https://streamable.com/y87gbv https://streamable.com/6i7fd9

Minimal reproduction project:

voxel.zip

@jamie-pate jamie-pate changed the title Add focus tracking and confined mouse mode does not work on OSX Captured mouse mode fails to capture mouse if it's outside the window on OSX Sep 24, 2020
@jamie-pate
Copy link
Contributor Author

jamie-pate commented Sep 24, 2020

Workaround: call _fix_mouse_pos() after Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _fix_mouse_pos():
	var tree = get_tree()
	if !tree:
		return
	var vp = tree.root
	if !vp:
		return
	var r = vp.get_visible_rect()
	var center = r.position + r.size * 0.5
	Input.warp_mouse_position(center)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants