shell: Refactor move grab
This commit is contained in:
parent
bf0b959e4d
commit
5a0752957b
8 changed files with 358 additions and 147 deletions
|
|
@ -19,81 +19,6 @@ use smithay::{
|
|||
};
|
||||
use std::{cell::RefCell, convert::TryFrom, sync::Mutex};
|
||||
|
||||
pub struct MoveSurfaceGrab {
|
||||
start_data: PointerGrabStartData,
|
||||
window: Window,
|
||||
initial_window_location: Point<i32, Logical>,
|
||||
delta: Point<f64, Logical>,
|
||||
}
|
||||
|
||||
impl PointerGrab<State> for MoveSurfaceGrab {
|
||||
fn motion(
|
||||
&mut self,
|
||||
data: &mut State,
|
||||
_dh: &DisplayHandle,
|
||||
handle: &mut PointerInnerHandle<'_, State>,
|
||||
event: &MotionEvent,
|
||||
) {
|
||||
// While the grab is active, no client has pointer focus
|
||||
handle.motion(event.location, None, event.serial, event.time);
|
||||
self.delta = event.location - self.start_data.location;
|
||||
|
||||
if let Some(workspace) = data
|
||||
.common
|
||||
.shell
|
||||
.space_for_surface_mut(self.window.toplevel().wl_surface())
|
||||
{
|
||||
let new_location = (self.initial_window_location.to_f64() + self.delta).to_i32_round();
|
||||
workspace
|
||||
.space
|
||||
.map_window(&self.window, new_location, super::FLOATING_INDEX, true);
|
||||
}
|
||||
}
|
||||
|
||||
fn button(
|
||||
&mut self,
|
||||
_data: &mut State,
|
||||
_dh: &DisplayHandle,
|
||||
handle: &mut PointerInnerHandle<'_, State>,
|
||||
event: &ButtonEvent,
|
||||
) {
|
||||
handle.button(event.button, event.state, event.serial, event.time);
|
||||
if handle.current_pressed().is_empty() {
|
||||
// No more buttons are pressed, release the grab.
|
||||
handle.unset_grab(event.serial, event.time);
|
||||
}
|
||||
}
|
||||
|
||||
fn axis(
|
||||
&mut self,
|
||||
_data: &mut State,
|
||||
_dh: &DisplayHandle,
|
||||
handle: &mut PointerInnerHandle<'_, State>,
|
||||
details: AxisFrame,
|
||||
) {
|
||||
handle.axis(details)
|
||||
}
|
||||
|
||||
fn start_data(&self) -> &PointerGrabStartData {
|
||||
&self.start_data
|
||||
}
|
||||
}
|
||||
|
||||
impl MoveSurfaceGrab {
|
||||
pub fn new(
|
||||
start_data: PointerGrabStartData,
|
||||
window: Window,
|
||||
initial_window_location: Point<i32, Logical>,
|
||||
) -> MoveSurfaceGrab {
|
||||
MoveSurfaceGrab {
|
||||
start_data,
|
||||
window,
|
||||
initial_window_location,
|
||||
delta: (0.0, 0.0).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
struct ResizeEdge: u32 {
|
||||
const NONE = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue