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

Incorrect position with CursorMoved when dragging out of window left/top with mouse button pressed #2310

Closed
apessino opened this issue May 30, 2022 · 1 comment · Fixed by #2311
Labels
B - bug Dang, that shouldn't have happened DS - windows

Comments

@apessino
Copy link
Contributor

The position value received with WindowEvent::CursorMoved { position, .. }, ... is incorrect when a mouse button is being held and the pointer crosses over the left or top edge of the window.

Instead of the proper negative value, position contains 65536.0 - offset to window edge, this is obviously the result of some intermediate conversion to u16 before position is turned into PhysicalPosition<f64> and given to the event. I believe this problem was introduced in the last update to winit, but I am not positive.

For now, I have worked around the problem as follows:

  Event::WindowEvent {
      event: WindowEvent::CursorMoved { position, .. },
      ..
  } => {
      let px = if position.x > 32767.0 {
          (position.x - 65536.0)
      } else {
          position.x
      };
      let py = if position.y > 32767.0 {
          (position.y - 65536.0)
      } else {
          position.y
      };
   // ... use `vec2(px, py)` instead of `position`...

I have only tried this on Windows, I am not sure the problem exists on other platforms.

A=

@apessino apessino changed the title Incorrect position with CursorMoved even when dragging out of window left/top with mouse button pressed Incorrect position with CursorMoved when dragging out of window left/top with mouse button pressed May 30, 2022
@msiglreith msiglreith added B - bug Dang, that shouldn't have happened DS - windows labels May 30, 2022
@msiglreith
Copy link
Member

thanks for the report, looks like get_x/y_lparam misses a cast to i16. It slipped through during the transition to windows-sys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - windows
Development

Successfully merging a pull request may close this issue.

2 participants