2022-03-29 18:03:21 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-07-04 15:28:03 +02:00
|
|
|
|
2022-07-04 16:00:29 +02:00
|
|
|
use crate::{shell::layout::Orientation, utils::prelude::*};
|
2022-03-31 13:44:16 +02:00
|
|
|
use atomic_float::AtomicF64;
|
2022-03-29 18:03:21 +02:00
|
|
|
use smithay::{
|
2022-08-31 13:01:23 +02:00
|
|
|
input::pointer::{
|
|
|
|
|
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
|
|
|
|
|
PointerInnerHandle,
|
2022-07-04 16:00:29 +02:00
|
|
|
},
|
2022-08-31 13:01:23 +02:00
|
|
|
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
|
|
|
|
utils::{Logical, Point, Size},
|
2022-03-29 18:03:21 +02:00
|
|
|
};
|
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 {
|
2022-08-31 13:01:23 +02:00
|
|
|
pub start_data: PointerGrabStartData<State>,
|
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
|
|
|
}
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
impl PointerGrab<State> for ResizeForkGrab {
|
2022-03-29 18:03:21 +02:00
|
|
|
fn motion(
|
|
|
|
|
&mut self,
|
2022-08-31 13:01:23 +02:00
|
|
|
data: &mut State,
|
2022-07-04 16:00:29 +02:00
|
|
|
handle: &mut PointerInnerHandle<'_, State>,
|
2022-08-31 13:01:23 +02:00
|
|
|
_focus: Option<(WlSurface, Point<i32, Logical>)>,
|
2022-07-04 16:00:29 +02:00
|
|
|
event: &MotionEvent,
|
2022-03-29 18:03:21 +02:00
|
|
|
) {
|
|
|
|
|
// While the grab is active, no client has pointer focus
|
2022-08-31 13:01:23 +02:00
|
|
|
handle.motion(data, None, event);
|
2022-03-29 18:03:21 +02:00
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
let delta = event.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,
|
2022-08-31 13:01:23 +02:00
|
|
|
data: &mut State,
|
2022-07-04 15:28:03 +02:00
|
|
|
handle: &mut PointerInnerHandle<'_, State>,
|
|
|
|
|
event: &ButtonEvent,
|
2022-03-29 18:03:21 +02:00
|
|
|
) {
|
2022-08-31 13:01:23 +02:00
|
|
|
handle.button(data, event);
|
2022-03-29 18:03:21 +02:00
|
|
|
if handle.current_pressed().is_empty() {
|
|
|
|
|
// No more buttons are pressed, release the grab.
|
2022-08-31 13:01:23 +02:00
|
|
|
handle.unset_grab(data, event.serial, event.time);
|
2022-03-29 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 16:00:29 +02:00
|
|
|
fn axis(
|
|
|
|
|
&mut self,
|
2022-08-31 13:01:23 +02:00
|
|
|
data: &mut State,
|
2022-07-04 15:28:03 +02:00
|
|
|
handle: &mut PointerInnerHandle<'_, State>,
|
|
|
|
|
details: AxisFrame,
|
|
|
|
|
) {
|
2022-08-31 13:01:23 +02:00
|
|
|
handle.axis(data, details)
|
2022-03-29 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-31 13:01:23 +02:00
|
|
|
fn start_data(&self) -> &PointerGrabStartData<State> {
|
2022-03-29 18:03:21 +02:00
|
|
|
&self.start_data
|
|
|
|
|
}
|
|
|
|
|
}
|