2022-03-29 18:03:21 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-03-31 13:44:16 +02:00
|
|
|
use super::Orientation;
|
|
|
|
|
use atomic_float::AtomicF64;
|
2022-03-29 18:03:21 +02:00
|
|
|
use smithay::{
|
|
|
|
|
reexports::wayland_server::protocol::{wl_pointer::ButtonState, wl_surface},
|
2022-03-31 13:44:16 +02:00
|
|
|
utils::{Logical, Point, Size},
|
2022-03-29 18:03:21 +02:00
|
|
|
wayland::{
|
|
|
|
|
seat::{AxisFrame, PointerGrab, PointerGrabStartData, PointerInnerHandle},
|
|
|
|
|
Serial,
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-03-31 13:44:16 +02:00
|
|
|
use std::sync::{atomic::Ordering, Arc};
|
2022-03-29 18:03:21 +02:00
|
|
|
|
|
|
|
|
pub struct ResizeForkGrab {
|
|
|
|
|
pub start_data: PointerGrabStartData,
|
2022-03-31 13:44:16 +02:00
|
|
|
pub orientation: Orientation,
|
|
|
|
|
pub initial_size: Size<i32, Logical>,
|
2022-03-29 18:03:21 +02:00
|
|
|
pub initial_ratio: f64,
|
2022-03-31 13:44:16 +02:00
|
|
|
pub ratio: Arc<AtomicF64>,
|
2022-03-29 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PointerGrab for ResizeForkGrab {
|
|
|
|
|
fn motion(
|
|
|
|
|
&mut self,
|
|
|
|
|
handle: &mut PointerInnerHandle<'_>,
|
|
|
|
|
location: Point<f64, Logical>,
|
|
|
|
|
_focus: Option<(wl_surface::WlSurface, Point<i32, Logical>)>,
|
|
|
|
|
serial: Serial,
|
|
|
|
|
time: u32,
|
|
|
|
|
) {
|
|
|
|
|
// While the grab is active, no client has pointer focus
|
|
|
|
|
handle.motion(location, None, serial, time);
|
|
|
|
|
|
|
|
|
|
let delta = location - self.start_data.location;
|
2022-03-31 13:44:16 +02:00
|
|
|
let delta = match self.orientation {
|
|
|
|
|
Orientation::Vertical => delta.x / self.initial_size.w as f64,
|
|
|
|
|
Orientation::Horizontal => delta.y / self.initial_size.h as f64,
|
|
|
|
|
};
|
|
|
|
|
self.ratio.store(
|
|
|
|
|
0.9f64.min(0.1f64.max(self.initial_ratio + delta)),
|
|
|
|
|
Ordering::SeqCst,
|
|
|
|
|
);
|
2022-03-29 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn button(
|
|
|
|
|
&mut self,
|
|
|
|
|
handle: &mut PointerInnerHandle<'_>,
|
|
|
|
|
button: u32,
|
|
|
|
|
state: ButtonState,
|
|
|
|
|
serial: Serial,
|
|
|
|
|
time: u32,
|
|
|
|
|
) {
|
|
|
|
|
handle.button(button, state, serial, time);
|
|
|
|
|
if handle.current_pressed().is_empty() {
|
|
|
|
|
// No more buttons are pressed, release the grab.
|
|
|
|
|
handle.unset_grab(serial, time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn axis(&mut self, handle: &mut PointerInnerHandle<'_>, details: AxisFrame) {
|
|
|
|
|
handle.axis(details)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn start_data(&self) -> &PointerGrabStartData {
|
|
|
|
|
&self.start_data
|
|
|
|
|
}
|
|
|
|
|
}
|