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

cursor grab no longer grabbed when mouse leave and enter #242

Open
gui1117 opened this issue Jul 23, 2017 · 1 comment
Open

cursor grab no longer grabbed when mouse leave and enter #242

gui1117 opened this issue Jul 23, 2017 · 1 comment
Labels
B - bug Dang, that shouldn't have happened D - easy Likely easier than most tasks here DS - x11 H - help wanted Someone please save us P - normal Great to have

Comments

@gui1117
Copy link

gui1117 commented Jul 23, 2017

On X11 using Xmonad window manager:

minimal program: a winit window with cursor state set to grab:

fn main() {
    let mut events_loop = winit::EventsLoop::new();
    let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
    window.set_cursor_state(winit::CursorState::Grab).unwrap();
    events_loop.run_forever(|event| {
        ControlFlow::Continue
    });
}

issue:
I run the program. (cursor is grabbed)
I leave the window with xmonad key.
I enter the window: cursor is not longer grabbed

to solve this issue and grab the cursor again I wrote: set cursor grab on mouse entered

fn main() {
    let mut events_loop = winit::EventsLoop::new();
    let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
    window.set_cursor_state(winit::CursorState::Grab).unwrap();
    events_loop.run_forever(|event| {
        match event {
            winit::Event::WindowEvent { event: winit::WindowEvent::MouseEntered { .. }, .. } => window.set_cursor_state(winit::CursorState::Grab).unwrap(),
            _ => (),
        }
        ControlFlow::Continue
    });
}

That didn't solve anything. But then I wrote: set cursor state to normal and then to grab on mouse entered
and it works (cursor is grabbed again):

fn main() {
    let mut events_loop = winit::EventsLoop::new();
    let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
    window.set_cursor_state(winit::CursorState::Grab).unwrap();
    events_loop.run_forever(|event| {
        match event {
            winit::Event::WindowEvent { event: winit::WindowEvent::MouseEntered { .. }, .. } => {
                window.set_cursor_state(winit::CursorState::Normal).unwrap();
                window.set_cursor_state(winit::CursorState::Grab).unwrap();
            },
            _ => (),
        }
        ControlFlow::Continue
    });
}

I think this is an issue and winit should grab the cursor again automatically on mouse entered.
If so I can look to make a PR.

@Ralith
Copy link
Contributor

Ralith commented Jul 23, 2017

winit's X11 backend tracks the grab state manually, and is probably falling out of date in this case because nobody expected the window manager to forcibly ungrab. I think a good fix would be for the X11 backend to automatically re-grab if we think we're grabbed and we receive a Focused(true), rather than on mouse entry.

@francesca64 francesca64 added B - bug Dang, that shouldn't have happened H - help wanted Someone please save us D - easy Likely easier than most tasks here P - normal Great to have labels May 6, 2018
tmfink pushed a commit to tmfink/winit that referenced this issue Jan 5, 2022
Bump lyon, font-kit and skribo versions to fix crashes
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 D - easy Likely easier than most tasks here DS - x11 H - help wanted Someone please save us P - normal Great to have
Development

No branches or pull requests

5 participants