1use crate::{
2 error::AtspiError,
3 events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
4 Event, EventProperties, EventTypeProperties,
5};
6use zbus_names::UniqueName;
7use zvariant::{ObjectPath, OwnedValue};
8
9#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
10pub enum FocusEvents {
11 /// See: [`FocusEvent`].
12 Focus(FocusEvent),
13}
14
15impl EventTypeProperties for FocusEvents {
16 fn member(&self) -> &'static str {
17 match self {
18 Self::Focus(inner: &FocusEvent) => inner.member(),
19 }
20 }
21 fn match_rule(&self) -> &'static str {
22 match self {
23 Self::Focus(inner: &FocusEvent) => inner.match_rule(),
24 }
25 }
26 fn interface(&self) -> &'static str {
27 match self {
28 Self::Focus(inner: &FocusEvent) => inner.interface(),
29 }
30 }
31 fn registry_string(&self) -> &'static str {
32 match self {
33 Self::Focus(inner: &FocusEvent) => inner.registry_string(),
34 }
35 }
36}
37
38impl EventProperties for FocusEvents {
39 fn path(&self) -> ObjectPath<'_> {
40 match self {
41 Self::Focus(inner: &FocusEvent) => inner.path(),
42 }
43 }
44 fn sender(&self) -> UniqueName<'_> {
45 match self {
46 Self::Focus(inner: &FocusEvent) => inner.sender(),
47 }
48 }
49}
50
51impl_from_interface_event_enum_for_event!(FocusEvents, Event::Focus);
52impl_try_from_event_for_user_facing_event_type!(FocusEvents, Event::Focus);
53
54event_wrapper_test_cases!(FocusEvents, FocusEvent);
55
56impl HasMatchRule for FocusEvents {
57 const MATCH_RULE_STRING: &'static str = "type='signal',interface='org.a11y.atspi.Event.Focus'";
58}
59
60#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
61pub struct FocusEvent {
62 /// The [`ObjectRef`] which the event applies to.
63 pub item: crate::events::ObjectRef,
64}
65
66impl BusProperties for FocusEvent {
67 const DBUS_MEMBER: &'static str = "Focus";
68 const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Focus";
69 const MATCH_RULE_STRING: &'static str =
70 "type='signal',interface='org.a11y.atspi.Event.Focus',member='Focus'";
71 const REGISTRY_EVENT_STRING: &'static str = "Focus:";
72
73 type Body = EventBodyOwned;
74
75 fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result<Self, AtspiError> {
76 Ok(Self { item })
77 }
78 fn body(&self) -> Self::Body {
79 let copy: FocusEvent = self.clone();
80 copy.into()
81 }
82}
83
84#[cfg(feature = "zbus")]
85impl TryFrom<&zbus::Message> for FocusEvents {
86 type Error = AtspiError;
87 fn try_from(ev: &zbus::Message) -> Result<Self, Self::Error> {
88 let header: Header<'_> = ev.header();
89 let member: &MemberName<'_> = header
90 .member()
91 .ok_or(err:AtspiError::MemberMatch("Event without member".into()))?;
92 match member.as_str() {
93 "Focus" => Ok(FocusEvents::Focus(ev.try_into()?)),
94 _ => Err(AtspiError::MemberMatch("No matching member for Focus".into())),
95 }
96 }
97}
98
99impl_from_user_facing_event_for_interface_event_enum!(FocusEvent, FocusEvents, FocusEvents::Focus);
100impl_from_user_facing_type_for_event_enum!(FocusEvent, Event::Focus);
101impl_try_from_event_for_user_facing_type!(FocusEvent, FocusEvents::Focus, Event::Focus);
102
103event_test_cases!(FocusEvent);
104impl_to_dbus_message!(FocusEvent);
105impl_from_dbus_message!(FocusEvent);
106impl_event_properties!(FocusEvent);
107impl From<FocusEvent> for EventBodyOwned {
108 fn from(_event: FocusEvent) -> Self {
109 EventBodyOwned {
110 properties: std::collections::HashMap::new(),
111 kind: String::default(),
112 detail1: i32::default(),
113 detail2: i32::default(),
114 any_data: OwnedValue::from(0u8),
115 }
116 }
117}
118
119impl HasRegistryEventString for FocusEvents {
120 const REGISTRY_EVENT_STRING: &'static str = "Focus:";
121}
122