Skip to content

Implement proper grabbing behavior on macOS #1093

Open

Description

@Osspial

Right now on macOS, the cursor just gets locked to its current location, instead of getting locked to the area of the window. A proper solution that locks the cursor to the window exists and is documented, but hasn't been implemented yet.

See this comment:

pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> {
// TODO: Do this for real https://stackoverflow.com/a/40922095/5435443
CGDisplay::associate_mouse_and_mouse_cursor_position(!grab)
.map_err(|status| ExternalError::Os(os_error!(OsError::CGError(status))))
}

Activity

  1. added
    DS - appkit
    D - average
    P - normal
    S - platform parity
    H - good first issue
    on Aug 5, 2019
  2. panda2134 commented on Oct 16, 2022

    @panda2134

    Can anyone merge this PR? This feature is critical for developing cross-platform video games. If we cannot set mouse grab on macOS, then camera movement will become quite weird there.

  3. kchibisov commented on Oct 16, 2022

    @kchibisov
    Member

    @panda2134 this is not a PR, it's an issue. macOS has locking, but not confining.

  4. panda2134 commented on Oct 16, 2022

    @panda2134

    Sorry for mistaking this as a PR. If it's the OS's fault, then that's acceptable limitation. Also I just found out that it works when locking is used after setting the cursor to somewhere in the window.

  5. kchibisov commented on Oct 16, 2022

    @kchibisov
    Member

    Yes, the cursor should be in the window to lock it. that's how it works on most OSes.

  6. swiftcoder commented on Oct 16, 2022

    @swiftcoder
    Contributor

    You can simulate proper cursor grabbing with the cursor lock API, by only locking after the user first clicks in the window.

    (I believe this is required for Web anyway, because you can only grab the cursor in response to user interaction?)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    D - averageDS - appkitH - good first issueP - normalS - platform parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions