rust-windowing / rust-windowing/winit
Double mouse device events with confined cursor
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
Description
When confining the cursor to a window all DeviceEvents from that mouse are doubled (note: not a duplicate of #2332, as the accepted fix is already implemented in the winit version im using. Behavior is very similar though).
Here is some code to reproduce:
use std::{
thread,
time::Duration
};
use winit::{
event::{
Event,
WindowEvent,
DeviceEvent
},
event_loop::{
EventLoop,
ControlFlow
},
keyboard::{KeyCode, PhysicalKey},
window::{CursorGrabMode, WindowAttributes}
};
fn main() {
let event_loop = EventLoop::new().unwrap();
let window = event_loop.create_window(WindowAttributes::default()).unwrap();
thread::sleep(Duration::from_millis(50));
window.set_cursor_grab(CursorGrabMode::Confined).unwrap();
event_loop.run(move |event, event_loop| {
event_loop.set_control_flow(ControlFlow::Poll);
match event {
Event::DeviceEvent {event, ..} => {
match event {
DeviceEvent::Key(e) => {
if e.physical_key == PhysicalKey::Code(KeyCode::Escape) {
event_loop.exit();
}
}
DeviceEvent::Button { button, state } => {
println!("mouse button {} was {:?}", button, state);
},
DeviceEvent::MouseWheel {delta} => {
//println!("delta: {:?}", delta);
},
DeviceEvent::MouseMotion {delta} => {
//println!("move_delta: {:?}", delta);
}
_ => {}
}
}
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
event_loop.exit();
}
_ => (),
},
_ => (),
}
}).unwrap();
}
OS and window mananger
Ubuntu with GNOME Shell
Winit version
0.30.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided Rust reproducer with winit 0.30.3 on Ubuntu with GNOME Shell, focusing on CursorGrabMode::Confined and the DeviceEvent handlers. Trace the relevant confined-cursor event path and compare button, wheel, and motion counts. Done means each physical mouse event is delivered once rather than doubled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100