wayland_bridge/
relative_pointer.rs1use crate::client::{Client, EventQueue};
6use crate::object::{NewObjectExt, ObjectRef, RequestReceiver};
7use anyhow::Error;
8use fuchsia_wayland_core as wl;
9use zwp_relative_pointer_v1_server_protocol::{
10 ZwpRelativePointerManagerV1, ZwpRelativePointerManagerV1Request, ZwpRelativePointerV1,
11 ZwpRelativePointerV1Event, ZwpRelativePointerV1Request,
12};
13
14pub struct RelativePointerManager;
16
17impl RequestReceiver<ZwpRelativePointerManagerV1> for RelativePointerManager {
18 fn receive(
19 this: ObjectRef<Self>,
20 request: ZwpRelativePointerManagerV1Request,
21 client: &mut Client,
22 ) -> Result<(), Error> {
23 match request {
24 ZwpRelativePointerManagerV1Request::Destroy => {
25 client.delete_id(this.id())?;
26 }
27 ZwpRelativePointerManagerV1Request::GetRelativePointer { id, pointer: _ } => {
28 let relative_pointer = id.implement(client, RelativePointer)?;
29 assert!(client.input_dispatcher.relative_pointers.add(relative_pointer));
34 }
35 }
36 Ok(())
37 }
38}
39
40pub struct RelativePointer;
41
42impl RelativePointer {
43 pub fn post_relative_motion(
44 this: ObjectRef<Self>,
45 event_queue: &EventQueue,
46 time_in_us: u64,
47 dx: wl::Fixed,
48 dy: wl::Fixed,
49 ) -> Result<(), Error> {
50 event_queue.post(
51 this.id(),
52 ZwpRelativePointerV1Event::RelativeMotion {
53 utime_hi: (time_in_us >> 32) as u32,
54 utime_lo: (time_in_us & 0xffffffff) as u32,
55 dx,
56 dy,
57 dx_unaccel: dx,
58 dy_unaccel: dy,
59 },
60 )
61 }
62}
63
64impl RequestReceiver<ZwpRelativePointerV1> for RelativePointer {
65 fn receive(
66 this: ObjectRef<Self>,
67 request: ZwpRelativePointerV1Request,
68 client: &mut Client,
69 ) -> Result<(), Error> {
70 match request {
71 ZwpRelativePointerV1Request::Destroy => {
72 client.input_dispatcher.relative_pointers.remove(this);
73 client.delete_id(this.id())?;
74 }
75 }
76 Ok(())
77 }
78}