Skip to content

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

@apessino

Description

@apessino

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=

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedDS - win32Affects the Win32/Windows backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions