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

Mouse Warp events are not filtered out from mouse velocity calculations #57119

Open
madmiraal opened this issue Jan 24, 2022 · 0 comments
Open

Comments

@madmiraal
Copy link
Contributor

Godot version

3.4.2, 3.5.beta and master 57a057f

System information

Ubuntu 21.10 but confirmed on macOS too

Issue description

When the mouse is warped the instantaneous change in position is not being filtered out for mouse velocity (speed in 3.x) calculations.

On the linuxbsd platform, there is code that is supposed to filter these events, but it doesn't appear to be working:

case MotionNotify: {
// The X11 API requires filtering one-by-one through the motion
// notify events, in order to figure out which event is the one
// generated by warping the mouse pointer.
while (true) {
if (mouse_mode == MOUSE_MODE_CAPTURED && event.xmotion.x == windows[MAIN_WINDOW_ID].size.width / 2 && event.xmotion.y == windows[MAIN_WINDOW_ID].size.height / 2) {
//this is likely the warp event since it was warped here
center = Vector2(event.xmotion.x, event.xmotion.y);
break;
}
if (event_index + 1 < events.size()) {
const XEvent &next_event = events[event_index + 1];
if (next_event.type == MotionNotify) {
++event_index;
event = next_event;
} else {
break;
}
} else {
break;
}
}

This is an old issue: see #8414, which was closed even though the issue was still happening. It also happens when the mouse enters the window (the difference between the exit and enter positions are added to the velocity calculation).

Note: #56754 (and it's 3.x version #56755) makes #8414 (MOUSE_MODE_CAPTURED) and the mouse entering the window problem less noticeable, but it's still very noticeable when using Input.warp_mouse_position().

Steps to reproduce

Use Input.warp_mouse_position(), and check Input.get_last_mouse_velocity() (Input.get_last_mouse_speed() on 3.x).

Minimal reproduction project

3.x: MouseWarpSpeed-3.x.zip
4.0: MouseWarpVelocity-4.0.zip

Note: On 4.0, without #56548, #53894 requires the window to be moved, or unfocused and focused again for InputEventMouseMotion events to be received.

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

No branches or pull requests

2 participants