From 036c056de0aebf55888951285ba4f3726eac7db5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 29 Aug 2023 18:02:05 -0700 Subject: [PATCH] press tab to lock mouse (no workie on X11) --- src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.rs b/src/main.rs index c618099..23ade7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -350,6 +350,24 @@ fn main() { ElementState::Pressed => controls|=CONTROL_MOVEDOWN, ElementState::Released => controls&=!CONTROL_MOVEDOWN, } + (k,VirtualKeyCode::Tab) => match k { + ElementState::Pressed => { + let window = surface.object().unwrap().downcast_ref::().unwrap(); + let garb = window.set_cursor_grab(winit::window::CursorGrabMode::None); + match garb { + Err(err) => println!("set_cursor_grab error: {}",err), + _ => (), + } + } + ElementState::Released => { + let window = surface.object().unwrap().downcast_ref::().unwrap(); + let garb = window.set_cursor_grab(winit::window::CursorGrabMode::Locked); + match garb { + Err(err) => println!("set_cursor_grab error: {}",err), + _ => (), + } + } + } _ => (), } }