wayland: implement pointer-warp-v1
This commit is contained in:
parent
35adc21ca6
commit
c68e47f457
6 changed files with 137 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ mod touch_owner;
|
|||
pub mod wl_keyboard;
|
||||
pub mod wl_pointer;
|
||||
pub mod wl_touch;
|
||||
pub mod wp_pointer_warp_v1;
|
||||
pub mod zwp_pointer_constraints_v1;
|
||||
pub mod zwp_pointer_gesture_hold_v1;
|
||||
pub mod zwp_pointer_gesture_pinch_v1;
|
||||
|
|
|
|||
120
src/ifs/wl_seat/wp_pointer_warp_v1.rs
Normal file
120
src/ifs/wl_seat/wp_pointer_warp_v1.rs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::wl_seat::PositionHintRequest,
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
tree::Node,
|
||||
wire::{
|
||||
WpPointerWarpV1Id,
|
||||
wp_pointer_warp_v1::{Destroy, WarpPointer, WpPointerWarpV1RequestHandler},
|
||||
},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct WpPointerWarpV1Global {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
impl WpPointerWarpV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: WpPointerWarpV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: Version,
|
||||
) -> Result<(), WpPointerWarpV1Error> {
|
||||
let obj = Rc::new(WpPointerWarpV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
version,
|
||||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(WpPointerWarpV1Global, WpPointerWarpV1, WpPointerWarpV1Error);
|
||||
|
||||
impl Global for WpPointerWarpV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_global!(WpPointerWarpV1Global);
|
||||
|
||||
pub struct WpPointerWarpV1 {
|
||||
pub id: WpPointerWarpV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub version: Version,
|
||||
}
|
||||
|
||||
impl WpPointerWarpV1RequestHandler for WpPointerWarpV1 {
|
||||
type Error = WpPointerWarpV1Error;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn warp_pointer(&self, req: WarpPointer, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let Some(serial) = self.client.map_serial(req.serial) else {
|
||||
return Ok(());
|
||||
};
|
||||
if Some(serial) != self.client.last_enter_serial.get() {
|
||||
return Ok(());
|
||||
}
|
||||
let pointer = self.client.lookup(req.pointer)?;
|
||||
let seat = &pointer.seat.global;
|
||||
let Some(pointer_node) = seat.pointer_node() else {
|
||||
return Ok(());
|
||||
};
|
||||
if pointer_node.node_client_id() != Some(self.client.id) {
|
||||
return Ok(());
|
||||
}
|
||||
let (x, y) = (req.x, req.y);
|
||||
let surface = self.client.lookup(req.surface)?;
|
||||
let buffer = surface.node_absolute_position();
|
||||
let (x_int, y_int) = buffer.translate_inv(x.round_down(), y.round_down());
|
||||
self.client
|
||||
.state
|
||||
.position_hint_requests
|
||||
.push(PositionHintRequest {
|
||||
seat: seat.clone(),
|
||||
node: surface.node_id.into(),
|
||||
old_pos: seat.pointer_cursor.position(),
|
||||
new_pos: (x.apply_fract(x_int), y.apply_fract(y_int)),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = WpPointerWarpV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for WpPointerWarpV1 {}
|
||||
|
||||
simple_add_obj!(WpPointerWarpV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WpPointerWarpV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(WpPointerWarpV1Error, ClientError);
|
||||
Loading…
Add table
Add a link
Reference in a new issue