Skip to content

[Wayland] Slow keypress handler causes the event to trigger multiple times #1614

Closed

Description

@JMS55

When you do something like this

Some(VirtualKeyCode::Key2) => {
    std::thread::sleep(Duration::from_secs(2)); // Could be any long operation, sleep is just an example
    dbg!("done");
}

You would expect that the window freezes for 2s, prints "done", and then continues. This is what happens on x11.
On Wayland however, instead it freezes for 2s, prints done, then freezes for 2s, prints done again, repeat infinitely.

winit = 0.22.2

Activity

  1. changed the title [-][Wayland] Long keypress handler causes the event to trigger multiple times[/-] [+][Wayland] Slow keypress handler causes the event to trigger multiple times[/+] on Jun 28, 2020
  2. added
    DS - wayland
    C - needs investigation
    on Jun 28, 2020
  3. kchibisov commented on Jun 28, 2020

    @kchibisov
    Member

    This could be related to a thing that on Wayland, repeat is done by clients, not by display server, so something could go out of sync on a client side, and I guess it's much more sensitive to sleeps like that. But yeah, I can repro your issue and I bet timers are borken in that case. Or winit somehow messes things up here...

  4. JMS55 commented on Jun 30, 2020

    @JMS55
    Author

    On x11, doing this prints "done" 3 times, instead of the expected 2. Uncommenting the Pressed check gives the expected 1 print only. So x11 is also kinda broken?

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Poll;
    
        match event {
            Event::WindowEvent { event, .. } => match event {
                WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
                WindowEvent::KeyboardInput { input, .. } => {
                    // if input.state == ElementState::Pressed {
                        thread::sleep(Duration::from_secs(2));
                        dbg!("done");
                    // }
                }
                _ => {}
            },
            _ => (),
        }
    });
  5. kchibisov commented on Aug 23, 2020

    @kchibisov
    Member

    Could you try #1653 for Wayland part of it?

  6. JMS55 commented on Aug 23, 2020

    @JMS55
    Author

    Everything's fixed! On both X11 and Wayland, it prints 2 times, or 1 time if wrapped in if input.state == ElementState::Pressed.

  7. kchibisov commented on Aug 23, 2020

    @kchibisov
    Member

    I haven't touched X11 at all, so it's placebo. Though Wayland backend is brand new on that PR.

  8. JMS55 commented on Aug 23, 2020

    @JMS55
    Author

    Weird that X11 works now then, maybe my game was just being weird before. Thanks for all the work on fixing wayland stuff though!

  9. kchibisov commented on Aug 23, 2020

    @kchibisov
    Member

    The patch haven't yet merged, so opening it for now.

  10. added 3 commits that reference this issue on Aug 28, 2020
    61a8d7d
    2b31c4b
    d831957
  11. added 5 commits that reference this issue on Sep 15, 2020
    53d58d5
    992e49c
    53c36ca
    1590826
    a4f2db6
  12. added a commit that references this issue on Sep 28, 2020
    3d85af0
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

    C - needs investigationDS - wayland

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions