1 | use crate::{ |
2 | error::AtspiError, |
3 | events::{Accessible, EventBodyOwned, GenericEvent, HasMatchRule, HasRegistryEventString}, |
4 | Event, |
5 | }; |
6 | use zvariant::ObjectPath; |
7 | |
8 | #[derive (Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)] |
9 | pub enum FocusEvents { |
10 | /// See: [`FocusEvent`]. |
11 | Focus(FocusEvent), |
12 | } |
13 | |
14 | impl_from_interface_event_enum_for_event!(FocusEvents, Event::Focus); |
15 | impl_try_from_event_for_user_facing_event_type!(FocusEvents, Event::Focus); |
16 | |
17 | event_wrapper_test_cases!(FocusEvents, FocusEvent); |
18 | |
19 | impl HasMatchRule for FocusEvents { |
20 | const MATCH_RULE_STRING: &'static str = "type='signal',interface='org.a11y.atspi.Event.Focus'" ; |
21 | } |
22 | |
23 | #[derive (Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] |
24 | pub struct FocusEvent { |
25 | /// The [`Accessible`] which the event applies to. |
26 | pub item: crate::events::Accessible, |
27 | } |
28 | |
29 | impl GenericEvent<'_> for FocusEvent { |
30 | const DBUS_MEMBER: &'static str = "Focus" ; |
31 | const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Focus" ; |
32 | const MATCH_RULE_STRING: &'static str = |
33 | "type='signal',interface='org.a11y.atspi.Event.Focus',member='Focus'" ; |
34 | const REGISTRY_EVENT_STRING: &'static str = "Focus:" ; |
35 | |
36 | type Body = EventBodyOwned; |
37 | |
38 | fn build(item: Accessible, _body: Self::Body) -> Result<Self, AtspiError> { |
39 | Ok(Self { item }) |
40 | } |
41 | fn sender(&self) -> String { |
42 | self.item.name.clone() |
43 | } |
44 | fn path<'a>(&self) -> ObjectPath<'_> { |
45 | self.item.path.clone().into() |
46 | } |
47 | fn body(&self) -> Self::Body { |
48 | let copy: FocusEvent = self.clone(); |
49 | copy.into() |
50 | } |
51 | } |
52 | |
53 | #[cfg (feature = "zbus" )] |
54 | impl TryFrom<&zbus::Message> for FocusEvents { |
55 | type Error = AtspiError; |
56 | fn try_from(ev: &zbus::Message) -> Result<Self, Self::Error> { |
57 | let member: MemberName<'_> = ev |
58 | .member() |
59 | .ok_or(err:AtspiError::MemberMatch("Event without member" .into()))?; |
60 | match member.as_str() { |
61 | "Focus" => Ok(FocusEvents::Focus(ev.try_into()?)), |
62 | _ => Err(AtspiError::MemberMatch("No matching member for Focus" .into())), |
63 | } |
64 | } |
65 | } |
66 | |
67 | impl_from_user_facing_event_for_interface_event_enum!(FocusEvent, FocusEvents, FocusEvents::Focus); |
68 | impl_from_user_facing_type_for_event_enum!(FocusEvent, Event::Focus); |
69 | impl_try_from_event_for_user_facing_type!(FocusEvent, FocusEvents::Focus, Event::Focus); |
70 | |
71 | event_test_cases!(FocusEvent); |
72 | impl_to_dbus_message!(FocusEvent); |
73 | impl_from_dbus_message!(FocusEvent); |
74 | impl From<FocusEvent> for EventBodyOwned { |
75 | fn from(_event: FocusEvent) -> Self { |
76 | EventBodyOwned { |
77 | properties: std::collections::HashMap::new(), |
78 | kind: String::default(), |
79 | detail1: i32::default(), |
80 | detail2: i32::default(), |
81 | any_data: zvariant::Value::U8(0).into(), |
82 | } |
83 | } |
84 | } |
85 | |
86 | impl HasRegistryEventString for FocusEvents { |
87 | const REGISTRY_EVENT_STRING: &'static str = "Focus:" ; |
88 | } |
89 | |