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

Double mouse device events with confined cursor #3773

Open
Solvir777 opened this issue Jul 2, 2024 · 0 comments
Open

Double mouse device events with confined cursor #3773

Solvir777 opened this issue Jul 2, 2024 · 0 comments
Labels
B - bug Dang, that shouldn't have happened DS - x11

Comments

@Solvir777
Copy link

Solvir777 commented Jul 2, 2024

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

@Solvir777 Solvir777 added B - bug Dang, that shouldn't have happened DS - x11 labels Jul 2, 2024
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 DS - x11
Development

No branches or pull requests

1 participant