diff options
Diffstat (limited to 'src/grabs/move_grab.rs')
| -rw-r--r-- | src/grabs/move_grab.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/grabs/move_grab.rs b/src/grabs/move_grab.rs new file mode 100644 index 00000000..c9aacbec --- /dev/null +++ b/src/grabs/move_grab.rs @@ -0,0 +1,75 @@ +use crate::Smallvil; +use smithay::{ + desktop::Window, + input::pointer::{ + AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, + PointerInnerHandle, RelativeMotionEvent, + }, + reexports::wayland_server::protocol::wl_surface::WlSurface, + utils::{Logical, Point}, +}; + +pub struct MoveSurfaceGrab { + pub start_data: PointerGrabStartData<Smallvil>, + pub window: Window, + pub initial_window_location: Point<i32, Logical>, +} + +impl PointerGrab<Smallvil> for MoveSurfaceGrab { + fn motion( + &mut self, + data: &mut Smallvil, + handle: &mut PointerInnerHandle<'_, Smallvil>, + _focus: Option<(WlSurface, Point<i32, Logical>)>, + event: &MotionEvent, + ) { + // While the grab is active, no client has pointer focus + handle.motion(data, None, event); + + let delta = event.location - self.start_data.location; + let new_location = self.initial_window_location.to_f64() + delta; + data.space + .map_element(self.window.clone(), new_location.to_i32_round(), true); + } + + fn relative_motion( + &mut self, + data: &mut Smallvil, + handle: &mut PointerInnerHandle<'_, Smallvil>, + focus: Option<(WlSurface, Point<i32, Logical>)>, + event: &RelativeMotionEvent, + ) { + handle.relative_motion(data, focus, event); + } + + fn button( + &mut self, + data: &mut Smallvil, + handle: &mut PointerInnerHandle<'_, Smallvil>, + event: &ButtonEvent, + ) { + handle.button(data, event); + + // The button is a button code as defined in the + // Linux kernel's linux/input-event-codes.h header file, e.g. BTN_LEFT. + const BTN_LEFT: u32 = 0x110; + + if !handle.current_pressed().contains(&BTN_LEFT) { + // No more buttons are pressed, release the grab. + handle.unset_grab(data, event.serial, event.time); + } + } + + fn axis( + &mut self, + data: &mut Smallvil, + handle: &mut PointerInnerHandle<'_, Smallvil>, + details: AxisFrame, + ) { + handle.axis(data, details) + } + + fn start_data(&self) -> &PointerGrabStartData<Smallvil> { + &self.start_data + } +} |
