diff --git a/src/backends/traits.rs b/src/backends/traits.rs index 5ed966c..e72f861 100644 --- a/src/backends/traits.rs +++ b/src/backends/traits.rs @@ -5,6 +5,7 @@ use super::{ pub trait WindowServerBackend { type Window; + //type WindowEvent = super::window_event::WindowEvent; fn build() -> Self; @@ -46,6 +47,10 @@ pub trait WindowServerBackend { fn screen_size(&self) -> Point; fn get_window_size(&self, window: Self::Window) -> Option>; + fn grab_cursor(&self); + fn ungrab_cursor(&self); + fn move_cursor(&self, window: Option, position: Point); + fn resize_window(&self, window: Self::Window, new_size: Point) { self.configure_window(window, Some(new_size), None); } diff --git a/src/backends/xlib/mod.rs b/src/backends/xlib/mod.rs index df12e9a..9738f2e 100644 --- a/src/backends/xlib/mod.rs +++ b/src/backends/xlib/mod.rs @@ -491,8 +491,6 @@ impl XLib { XKeySym::new(keysym as u32) } - - fn modifier_state_to_modmask(&self) {} } trait ModifierStateExt { @@ -722,6 +720,46 @@ impl WindowServerBackend for XLib { self.get_window_attributes(window) .map(|wa| (wa.width, wa.height).into()) } + + fn grab_cursor(&self) { + unsafe { + xlib::XGrabPointer( + self.dpy(), + self.root, + 0, + (xlib::ButtonPressMask + | xlib::ButtonReleaseMask + | xlib::PointerMotionMask) as u32, + xlib::GrabModeAsync, + xlib::GrabModeAsync, + 0, + 0, + xlib::CurrentTime, + ); + } + } + + fn ungrab_cursor(&self) { + unsafe { + xlib::XUngrabPointer(self.dpy(), xlib::CurrentTime); + } + } + + fn move_cursor(&self, window: Option, position: Point) { + unsafe { + xlib::XWarpPointer( + self.dpy(), + 0, + window.unwrap_or(self.root), + 0, + 0, + 0, + 0, + position.x, + position.y, + ); + } + } } struct XLibAtoms { diff --git a/src/state.rs b/src/state.rs index 701a9bc..566c4af 100644 --- a/src/state.rs +++ b/src/state.rs @@ -714,9 +714,8 @@ where ) }; - // TODO fix backend cursor api - //self.xlib.move_cursor(None, corner_pos); - //self.xlib.grab_cursor(); + self.backend.move_cursor(None, corner_pos.into()); + self.backend.grab_cursor(); self.move_resize_window = MoveResizeInfo::Resize(ResizeInfoInner { @@ -736,8 +735,7 @@ where } MouseButton::Right => { self.move_resize_window = MoveResizeInfo::None; - // TODO fix backend cursor api - //self.xlib.release_cursor(); + self.backend.ungrab_cursor(); } _ => {} }