atspi_common/events/
mouse.rs1#[cfg(feature = "zbus")]
2use crate::{
3 error::AtspiError,
4 events::{MessageConversion, MessageConversionExt},
5 ObjectRef,
6};
7use crate::{
8 events::{BusProperties, EventBodyOwned},
9 EventProperties,
10};
11use zbus_names::UniqueName;
12use zvariant::ObjectPath;
13
14#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
15pub struct AbsEvent {
16 pub item: crate::events::ObjectRef,
18 pub x: i32,
19 pub y: i32,
20}
21
22#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
23pub struct RelEvent {
24 pub item: crate::events::ObjectRef,
26 pub x: i32,
27 pub y: i32,
28}
29
30#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
31pub struct ButtonEvent {
32 pub item: crate::events::ObjectRef,
34 pub detail: String,
35 pub mouse_x: i32,
36 pub mouse_y: i32,
37}
38
39impl BusProperties for AbsEvent {
40 const DBUS_MEMBER: &'static str = "Abs";
41 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Mouse";
42 const MATCH_RULE_STRING: &'static str =
43 "type='signal',interface='org.a11y.atspi.Event.Mouse',member='Abs'";
44 const REGISTRY_EVENT_STRING: &'static str = "Mouse:";
45}
46
47#[cfg(feature = "zbus")]
48impl MessageConversion for AbsEvent {
49 type Body = EventBodyOwned;
50
51 fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
52 Ok(Self { item, x: body.detail1, y: body.detail2 })
53 }
54 fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
55 let item = msg.try_into()?;
56 let body = msg.body();
57 let body: Self::Body = body.deserialize_unchecked()?;
58 Self::from_message_unchecked_parts(item, body)
59 }
60 fn body(&self) -> Self::Body {
61 let copy = self.clone();
62 copy.into()
63 }
64}
65
66impl BusProperties for RelEvent {
67 const DBUS_MEMBER: &'static str = "Rel";
68 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Mouse";
69 const MATCH_RULE_STRING: &'static str =
70 "type='signal',interface='org.a11y.atspi.Event.Mouse',member='Rel'";
71 const REGISTRY_EVENT_STRING: &'static str = "Mouse:";
72}
73
74#[cfg(feature = "zbus")]
75impl MessageConversion for RelEvent {
76 type Body = EventBodyOwned;
77
78 fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
79 Ok(Self { item, x: body.detail1, y: body.detail2 })
80 }
81 fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
82 let item = msg.try_into()?;
83 let body = msg.body();
84 let body: Self::Body = body.deserialize_unchecked()?;
85 Self::from_message_unchecked_parts(item, body)
86 }
87 fn body(&self) -> Self::Body {
88 let copy = self.clone();
89 copy.into()
90 }
91}
92
93impl BusProperties for ButtonEvent {
94 const DBUS_MEMBER: &'static str = "Button";
95 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Mouse";
96 const MATCH_RULE_STRING: &'static str =
97 "type='signal',interface='org.a11y.atspi.Event.Mouse',member='Button'";
98 const REGISTRY_EVENT_STRING: &'static str = "Mouse:";
99}
100
101#[cfg(feature = "zbus")]
102impl MessageConversion for ButtonEvent {
103 type Body = EventBodyOwned;
104
105 fn from_message_unchecked_parts(item: ObjectRef, body: Self::Body) -> Result<Self, AtspiError> {
106 Ok(Self { item, detail: body.kind, mouse_x: body.detail1, mouse_y: body.detail2 })
107 }
108 fn from_message_unchecked(msg: &zbus::Message) -> Result<Self, AtspiError> {
109 let item = msg.try_into()?;
110 let body = msg.body();
111 let body: Self::Body = body.deserialize_unchecked()?;
112 Self::from_message_unchecked_parts(item, body)
113 }
114 fn body(&self) -> Self::Body {
115 let copy = self.clone();
116 copy.into()
117 }
118}
119
120event_test_cases!(AbsEvent);
121impl_to_dbus_message!(AbsEvent);
122impl_from_dbus_message!(AbsEvent);
123impl_event_properties!(AbsEvent);
124impl From<AbsEvent> for EventBodyOwned {
125 fn from(event: AbsEvent) -> Self {
126 EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
127 }
128}
129
130event_test_cases!(RelEvent);
131impl_to_dbus_message!(RelEvent);
132impl_from_dbus_message!(RelEvent);
133impl_event_properties!(RelEvent);
134impl From<RelEvent> for EventBodyOwned {
135 fn from(event: RelEvent) -> Self {
136 EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
137 }
138}
139
140event_test_cases!(ButtonEvent);
141impl_to_dbus_message!(ButtonEvent);
142impl_from_dbus_message!(ButtonEvent);
143impl_event_properties!(ButtonEvent);
144impl From<ButtonEvent> for EventBodyOwned {
145 fn from(event: ButtonEvent) -> Self {
146 EventBodyOwned {
147 kind: event.detail,
148 detail1: event.mouse_x,
149 detail2: event.mouse_y,
150 ..Default::default()
151 }
152 }
153}