diff --git a/atspi-common/src/error.rs b/atspi-common/src/error.rs index 32b407dd..ab82e3c7 100644 --- a/atspi-common/src/error.rs +++ b/atspi-common/src/error.rs @@ -30,6 +30,9 @@ pub enum AtspiError { /// No Signature. MissingSignature, + /// When matching on a signal with an event, but the event does not match the signal. + EventMismatch, + /// When matching on an unknown role UnknownRole(u32), @@ -86,6 +89,7 @@ impl std::fmt::Display for AtspiError { Self::MissingInterface => f.write_str("Missing interface."), Self::MissingMember => f.write_str("Missing member."), Self::MissingSignature => f.write_str("Missing signature."), + Self::EventMismatch => f.write_str("Event <--> Message mismatch"), Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")), Self::UnknownSignal => f.write_str("atspi: Unknown signal"), Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"), diff --git a/atspi-common/src/events/document.rs b/atspi-common/src/events/document.rs index 7d13aaaf..8b0cae90 100644 --- a/atspi-common/src/events/document.rs +++ b/atspi-common/src/events/document.rs @@ -1,6 +1,6 @@ use crate::{ error::AtspiError, - events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef}, + events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString}, Event, EventProperties, EventTypeProperties, }; use zbus_names::BusName; @@ -102,7 +102,7 @@ impl HasMatchRule for DocumentEvents { /// `LibreOffice` has loaded a document from disk. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct LoadCompleteEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::object_ref::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -110,7 +110,7 @@ pub struct LoadCompleteEvent { /// For example: pressing F5, or `Control + r` will reload a page in a web browser. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct ReloadEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -118,25 +118,25 @@ pub struct ReloadEvent { /// For example: during the loading of a large web page, a user may press `Escape` to stop loading the page. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct LoadStoppedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct ContentChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct AttributesChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct PageChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -149,9 +149,11 @@ impl BusProperties for LoadCompleteEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -167,15 +169,16 @@ impl BusProperties for ReloadEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() } } - impl BusProperties for LoadStoppedEvent { const DBUS_MEMBER: &'static str = "LoadStopped"; const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Document"; @@ -185,9 +188,11 @@ impl BusProperties for LoadStoppedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -203,9 +208,11 @@ impl BusProperties for ContentChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -221,9 +228,11 @@ impl BusProperties for AttributesChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -239,9 +248,11 @@ impl BusProperties for PageChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() diff --git a/atspi-common/src/events/focus.rs b/atspi-common/src/events/focus.rs index 25831bd0..bff5a979 100644 --- a/atspi-common/src/events/focus.rs +++ b/atspi-common/src/events/focus.rs @@ -1,6 +1,6 @@ use crate::{ error::AtspiError, - events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef}, + events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString}, Event, EventProperties, EventTypeProperties, }; use zbus_names::BusName; @@ -59,7 +59,7 @@ impl HasMatchRule for FocusEvents { #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct FocusEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -72,9 +72,11 @@ impl BusProperties for FocusEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() diff --git a/atspi-common/src/events/keyboard.rs b/atspi-common/src/events/keyboard.rs index 4b2d5b3c..1fe14560 100644 --- a/atspi-common/src/events/keyboard.rs +++ b/atspi-common/src/events/keyboard.rs @@ -1,7 +1,10 @@ use crate::{ error::AtspiError, - events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef}, - Event, EventProperties, EventTypeProperties, + events::{ + BusProperties, EventBodyOwned, EventProperties, HasMatchRule, HasRegistryEventString, + ObjectRef, + }, + Event, EventTypeProperties, }; use zbus_names::BusName; use zvariant::{ObjectPath, OwnedValue}; @@ -75,9 +78,13 @@ impl BusProperties for ModifiersEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body: EventBodyOwned = msg.try_into()?; Ok(Self { item, previous_modifiers: body.detail1, current_modifiers: body.detail2 }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() diff --git a/atspi-common/src/events/mod.rs b/atspi-common/src/events/mod.rs index d25b9829..75670816 100644 --- a/atspi-common/src/events/mod.rs +++ b/atspi-common/src/events/mod.rs @@ -431,8 +431,13 @@ impl BusProperties for LegacyAddAccessibleEvent { type Body = LegacyCacheItem; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { - Ok(Self { item, node_added: body }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let body = msg.body(); + let node_added: Self::Body = body.deserialize::()?; + let item = msg.try_into()?; + + Ok(Self { item, node_added }) } fn body(&self) -> Self::Body { @@ -468,8 +473,13 @@ impl BusProperties for AddAccessibleEvent { type Body = CacheItem; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { - Ok(Self { item, node_added: body }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let body = msg.body(); + let node_added: Self::Body = body.deserialize::()?; + let item = msg.try_into()?; + + Ok(Self { item, node_added }) } fn body(&self) -> Self::Body { @@ -504,6 +514,7 @@ impl_from_user_facing_event_for_interface_event_enum!( impl_from_user_facing_type_for_event_enum!(RemoveAccessibleEvent, Event::Cache); impl_try_from_event_for_user_facing_type!(RemoveAccessibleEvent, CacheEvents::Remove, Event::Cache); event_test_cases!(RemoveAccessibleEvent); + impl BusProperties for RemoveAccessibleEvent { const REGISTRY_EVENT_STRING: &'static str = "Cache:Remove"; const MATCH_RULE_STRING: &'static str = @@ -513,9 +524,15 @@ impl BusProperties for RemoveAccessibleEvent { type Body = ObjectRef; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { - Ok(Self { item, node_removed: body }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let body = msg.body(); + let node_removed: Self::Body = body.deserialize::()?; + let item = msg.try_into()?; + + Ok(Self { item, node_removed }) } + fn body(&self) -> Self::Body { self.node_removed.clone() } @@ -569,11 +586,11 @@ impl TryFrom<&zbus::Message> for ObjectRef { fn try_from(message: &zbus::Message) -> Result { let header = message.header(); let path = header.path().expect("returned path is either `Some` or panics"); - let owned_path: OwnedObjectPath = path.clone().into(); + let owned_path: OwnedObjectPath = path.as_ref().into(); - let sender: UniqueName<'_> = header.sender().expect("No sender in header").into(); + let sender: UniqueName<'_> = header.sender().expect("No sender in header").as_ref(); let bus_name: BusName<'_> = sender.into(); - let name: OwnedBusName = bus_name.to_owned().into(); + let name = OwnedBusName::from(bus_name); Ok(ObjectRef { name, path: owned_path }) } @@ -710,9 +727,13 @@ impl BusProperties for EventListenerDeregisteredEvent { type Body = EventListeners; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = msg.try_into()?; + let body: Self::Body = msg.body().deserialize::()?; Ok(Self { item, deregistered_event: body }) } + fn body(&self) -> Self::Body { self.deregistered_event.clone() } @@ -743,6 +764,7 @@ impl_try_from_event_for_user_facing_type!( Event::Listener ); event_test_cases!(EventListenerRegisteredEvent); + impl BusProperties for EventListenerRegisteredEvent { const REGISTRY_EVENT_STRING: &'static str = "Registry:EventListenerRegistered"; const MATCH_RULE_STRING: &'static str = @@ -752,9 +774,13 @@ impl BusProperties for EventListenerRegisteredEvent { type Body = EventListeners; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = msg.try_into()?; + let body: Self::Body = msg.body().deserialize::()?; Ok(Self { item, registered_event: body }) } + fn body(&self) -> Self::Body { self.registered_event.clone() } @@ -786,6 +812,7 @@ impl TryFrom for AvailableEvent { } } event_test_cases!(AvailableEvent); + impl BusProperties for AvailableEvent { const REGISTRY_EVENT_STRING: &'static str = "Socket:Available"; const MATCH_RULE_STRING: &'static str = @@ -795,8 +822,12 @@ impl BusProperties for AvailableEvent { type Body = ObjectRef; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { - Ok(Self { item, socket: body }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = msg.try_into()?; + let body = msg.body(); + let socket: Self::Body = body.deserialize::()?; + Ok(Self { item, socket }) } fn body(&self) -> Self::Body { self.socket.clone() @@ -957,13 +988,26 @@ pub trait BusProperties { /// What is the body type of this event. type Body: Type + Serialize + for<'a> Deserialize<'a>; - /// Build the event from the object pair (`ObjectRef` and the Body). + /// Build the event from the `zbus::Message`. + /// + /// When called on a `&zbus::Message` from a message stream, you may want to make + /// sure event and message match. There is a helper to check for the match: + /// + /// ```ignore + /// if !msg.matches_event::()? { + /// return Err(AtspiError::EventMismatch); + /// } + /// let event = EventType::try_from_message(msg)?; + /// ``` + /// + /// These checks are already performed in the `Event::try_from` implementation, therefore the check is omited in the implementations of `BusProperties`. /// /// # Errors /// /// When the body type, which is what the raw message looks like over `DBus`, does not match the type that is expected for the given event. /// It is not possible for this to error on most events, but on events whose raw message [`Self::Body`] type contains a [`enum@zvariant::Value`], you may get errors when constructing the structure. - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> std::result::Result where Self: Sized; diff --git a/atspi-common/src/events/mouse.rs b/atspi-common/src/events/mouse.rs index b5de3f0e..8cc08122 100644 --- a/atspi-common/src/events/mouse.rs +++ b/atspi-common/src/events/mouse.rs @@ -107,9 +107,13 @@ impl BusProperties for AbsEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, x: body.detail1, y: body.detail2 }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -125,9 +129,13 @@ impl BusProperties for RelEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, x: body.detail1, y: body.detail2 }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -143,7 +151,10 @@ impl BusProperties for ButtonEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, detail: body.kind, mouse_x: body.detail1, mouse_y: body.detail2 }) } fn body(&self) -> Self::Body { diff --git a/atspi-common/src/events/object.rs b/atspi-common/src/events/object.rs index e6d5bbcc..02506a88 100644 --- a/atspi-common/src/events/object.rs +++ b/atspi-common/src/events/object.rs @@ -587,7 +587,10 @@ impl BusProperties for PropertyChangeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; let property = body.kind.clone(); let value: Property = body.try_into()?; Ok(Self { item, property, value }) @@ -607,9 +610,11 @@ impl BusProperties for BoundsChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -625,9 +630,11 @@ impl BusProperties for LinkSelectedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -643,9 +650,13 @@ impl BusProperties for StateChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, state: body.kind.into(), enabled: body.detail1 }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -661,7 +672,11 @@ impl BusProperties for ChildrenChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; + Ok(Self { item, operation: body.kind, @@ -669,6 +684,7 @@ impl BusProperties for ChildrenChangedEvent { child: body.any_data.try_into()?, }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -684,9 +700,11 @@ impl BusProperties for VisibleDataChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -702,9 +720,11 @@ impl BusProperties for SelectionChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -720,9 +740,11 @@ impl BusProperties for ModelChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -738,9 +760,13 @@ impl BusProperties for ActiveDescendantChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, child: body.any_data.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -756,7 +782,11 @@ impl BusProperties for AnnouncementEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; + Ok(Self { item, text: body.any_data.try_into().map_err(|_| AtspiError::Conversion("text"))?, @@ -778,8 +808,9 @@ impl BusProperties for AttributesChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -796,8 +827,9 @@ impl BusProperties for RowInsertedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -814,8 +846,9 @@ impl BusProperties for RowReorderedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -832,8 +865,9 @@ impl BusProperties for RowDeletedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -850,8 +884,9 @@ impl BusProperties for ColumnInsertedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -868,8 +903,9 @@ impl BusProperties for ColumnReorderedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -886,9 +922,11 @@ impl BusProperties for ColumnDeletedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -904,9 +942,11 @@ impl BusProperties for TextBoundsChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -922,9 +962,11 @@ impl BusProperties for TextSelectionChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -940,7 +982,11 @@ impl BusProperties for TextChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; + Ok(Self { item, operation: body.kind, @@ -964,9 +1010,11 @@ impl BusProperties for TextAttributesChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -982,9 +1030,14 @@ impl BusProperties for TextCaretMovedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; + Ok(Self { item, position: body.detail1 }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() diff --git a/atspi-common/src/events/terminal.rs b/atspi-common/src/events/terminal.rs index 2a5749a9..28d5223a 100644 --- a/atspi-common/src/events/terminal.rs +++ b/atspi-common/src/events/terminal.rs @@ -1,6 +1,6 @@ use crate::{ error::AtspiError, - events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef}, + events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString}, Event, EventProperties, EventTypeProperties, }; use zbus_names::BusName; @@ -94,7 +94,7 @@ impl HasMatchRule for TerminalEvents { /// A line of text has been changed. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct LineChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -102,7 +102,7 @@ pub struct LineChangedEvent { /// able to fit on one *visual* line has changed. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct ColumnCountChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -110,13 +110,13 @@ pub struct ColumnCountChangedEvent { /// able to fit within the terminal has changed. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct LineCountChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct ApplicationChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -124,7 +124,7 @@ pub struct ApplicationChangedEvent { /// able to fit on one *visual* line has changed. #[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)] pub struct CharWidthChangedEvent { - /// The [`ObjectRef`] which the event applies to. + /// The [`ObjectRef`][crate::events::ObjectRef] which the event applies to. pub item: crate::events::ObjectRef, } @@ -137,8 +137,9 @@ impl BusProperties for LineChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -155,8 +156,9 @@ impl BusProperties for ColumnCountChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -173,8 +175,9 @@ impl BusProperties for LineCountChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -191,8 +194,9 @@ impl BusProperties for ApplicationChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -209,8 +213,9 @@ impl BusProperties for CharWidthChangedEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); diff --git a/atspi-common/src/events/window.rs b/atspi-common/src/events/window.rs index 30f64df4..84685fcd 100644 --- a/atspi-common/src/events/window.rs +++ b/atspi-common/src/events/window.rs @@ -333,9 +333,13 @@ impl BusProperties for PropertyChangeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, body: Self::Body) -> Result { + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + let item = ObjectRef::try_from(msg)?; + let body = EventBodyOwned::try_from(msg)?; Ok(Self { item, property: body.kind }) } + fn body(&self) -> Self::Body { let copy = self.clone(); copy.into() @@ -351,8 +355,9 @@ impl BusProperties for MinimizeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -369,8 +374,9 @@ impl BusProperties for MaximizeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -387,8 +393,9 @@ impl BusProperties for RestoreEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -405,8 +412,9 @@ impl BusProperties for CloseEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -423,8 +431,9 @@ impl BusProperties for CreateEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -441,8 +450,9 @@ impl BusProperties for ReparentEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -459,8 +469,9 @@ impl BusProperties for DesktopCreateEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -477,8 +488,9 @@ impl BusProperties for DesktopDestroyEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -495,8 +507,9 @@ impl BusProperties for DestroyEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -513,8 +526,9 @@ impl BusProperties for ActivateEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -531,8 +545,9 @@ impl BusProperties for DeactivateEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -549,8 +564,9 @@ impl BusProperties for RaiseEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -567,8 +583,9 @@ impl BusProperties for LowerEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -585,8 +602,9 @@ impl BusProperties for MoveEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -603,8 +621,9 @@ impl BusProperties for ResizeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -621,8 +640,9 @@ impl BusProperties for ShadeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -639,8 +659,9 @@ impl BusProperties for UUshadeEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); @@ -657,8 +678,9 @@ impl BusProperties for RestyleEvent { type Body = EventBodyOwned; - fn from_message_parts(item: ObjectRef, _body: Self::Body) -> Result { - Ok(Self { item }) + #[cfg(feature = "zbus")] + fn try_from_message(msg: &zbus::Message) -> Result { + Ok(Self { item: msg.try_into()? }) } fn body(&self) -> Self::Body { let copy = self.clone(); diff --git a/atspi-common/src/lib.rs b/atspi-common/src/lib.rs index 7fa830df..72400a59 100644 --- a/atspi-common/src/lib.rs +++ b/atspi-common/src/lib.rs @@ -232,6 +232,37 @@ impl TryFrom for Live { } } +#[cfg(feature = "zbus")] +pub trait MessageExt { + /// Check if the message matches the event. + /// + /// # Errors + /// - If the message does not have a signature. + /// - If the message does not have a member. + /// - If the message does not have an interface. + fn matches_event(&self) -> crate::Result; +} + +#[cfg(feature = "zbus")] +impl MessageExt for zbus::Message { + fn matches_event(&self) -> crate::Result { + let event_signature = ::Body::signature(); + let event_member = ::DBUS_MEMBER; + let event_iface = ::DBUS_INTERFACE; + + let body = self.body(); + let msg_signature = body.signature().ok_or(AtspiError::MissingSignature)?; + + let header = self.header(); + let msg_member = header.member().ok_or(AtspiError::MissingMember)?; + let msg_iface = header.interface().ok_or(AtspiError::MissingInterface)?; + + Ok(event_signature == msg_signature + && event_member == msg_member.as_str() + && event_iface == msg_iface.as_str()) + } +} + #[cfg(test)] mod tests { use super::*; @@ -303,4 +334,22 @@ mod tests { let signature = method_args_signature!(member: "GetMatches", interface: "org.a11y.atspi.Collection", argument: "sortby"); assert_eq!(SortOrder::signature(), signature); } + + #[test] + fn message_ext_matches_event() { + use crate::events::mouse::AbsEvent; + + let builder = zbus::Message::signal( + "/org/a11y/atspi/accessible/null", + "org.a11y.atspi.Event.Mouse", + "Abs", + ) + .unwrap(); + + let event = AbsEvent::default(); + let body = event.body(); + let msg = builder.build(&body).unwrap(); + + assert!(msg.matches_event::().unwrap()); + } } diff --git a/atspi-common/src/macros.rs b/atspi-common/src/macros.rs index 2d693649..ee4fa422 100644 --- a/atspi-common/src/macros.rs +++ b/atspi-common/src/macros.rs @@ -118,9 +118,9 @@ macro_rules! impl_from_user_facing_event_for_interface_event_enum { /// Expands to a conversion given two arguments, /// 1. the user facing event type `(inner_type)` -/// which relies on a conversion to its interface variant enum type variant. +/// which relies on a conversion to its interface variant enum type variant. /// 2. the outer `Event::)>` wrapper., -/// the enum type and outtermost variant. +/// the enum type and outtermost variant. /// /// ```ignore user facing type, outer event variant /// impl_from_user_facing_type_for_event_enum!(StateChangedEvent, Event::Object); @@ -237,16 +237,8 @@ macro_rules! impl_to_dbus_message { /// type Error = AtspiError; /// fn try_from(msg: &zbus::Message) -> Result { /// if msg.header().interface().ok_or(AtspiError::MissingInterface)? != StateChangedEvent::DBUS_INTERFACE { -/// return Err(AtspiError::InterfaceMatch(format!("The interface {} does not match the signal's interface: {}", -/// msg.header().interface().unwrap(), -/// StateChangedEvent::DBUS_INTERFACE))); -/// } -/// if msg.header().member().ok_or(AtspiError::MissingMember)? != StateChangedEvent::DBUS_MEMBER { -/// return Err(AtspiError::MemberMatch(format!("The member {} does not match the signal's member: {}", -/// msg.header().member().unwrap(), -/// StateChangedEvent::DBUS_MEMBER))); -/// } -/// StateChangedEvent::from_message_parts(msg.try_into()?, msg.body().deserialize::()?) +/// StateChangedEvent::try_from_message(msg) +/// } /// } /// } /// ``` @@ -256,28 +248,36 @@ macro_rules! impl_from_dbus_message { impl TryFrom<&zbus::Message> for $type { type Error = AtspiError; fn try_from(msg: &zbus::Message) -> Result { - let header = msg.header(); - if header.interface().ok_or(AtspiError::MissingInterface)? - != <$type as BusProperties>::DBUS_INTERFACE - { - return Err(AtspiError::InterfaceMatch(format!( - "The interface {} does not match the signal's interface: {}", - header.interface().unwrap(), - <$type as BusProperties>::DBUS_INTERFACE - ))); - } - if header.member().ok_or(AtspiError::MissingMember)? != <$type>::DBUS_MEMBER { - return Err(AtspiError::MemberMatch(format!( - "The member {} does not match the signal's member: {}", - // unwrap is safe here because of guard above - header.member().unwrap(), - <$type as BusProperties>::DBUS_MEMBER - ))); + use crate::MessageExt; + + if msg.matches_event::<$type>()? { + <$type>::try_from_message(msg) + } else { + let header = msg.header(); + let msg_interface = header.interface().ok_or(AtspiError::MissingInterface)?; + let msg_member = header.member().ok_or(AtspiError::MissingMember)?; + + let event_interface = <$type as BusProperties>::DBUS_INTERFACE; + let event_member = <$type as BusProperties>::DBUS_MEMBER; + + let error_msg = match (msg_interface != event_interface, msg_member != event_member) { + (true, true) => format!( + "Message's interface and member (\"{msg_interface}\", \"{msg_member}\") did not match this events': (\"{event_interface}\", \"{event_member}\") " ), + (true, false) => format!( + "Message's interface (\"{msg_interface}\") did not match this events' (\"{event_interface}\") " ), + (false, true) => format!( + "Message's member (\"{msg_member}\") did not match this events' (\"{event_member}\") " ), + (false, false) => { + let msg_body = msg.body(); + let msg_body_signature = msg_body.signature().unwrap_or(zvariant::Signature::from_static_str_unchecked("")); + let msg_body_signature = msg_body_signature.as_str(); + let event_body_signature = <<$type as BusProperties>::Body as zvariant::Type>::signature(); + format!("Message's body signature and this event's body signature do not correspond: (\"{msg_body_signature}\", \"{event_body_signature}\")" ) + }, + }; + + Err(AtspiError::Owned(error_msg)) } - <$type>::from_message_parts( - msg.try_into()?, - msg.body().deserialize::<<$type as BusProperties>::Body>()?, - ) } } }; @@ -287,24 +287,38 @@ macro_rules! impl_from_dbus_message { // This prevents Clippy from complaining about the macro not being used. // It is being used, but only in test mode. // -/// Tests `Default` and `BusProperties::from_message_parts` for a given event struct. +/// Tests `Default` and `BusProperties::try_from_message` for a given event struct. /// /// Obtains a default for the given event struct. /// Asserts that the path and sender are the default. /// -/// Breaks the struct down into item (the associated object) and body. -/// Then tests `BusProperties::from_message_parts` with the item and body. +/// Retreives a body from the event type, creates a message from the event type and body. +/// Then tests `BusProperties::try_from_message` with the message. #[cfg(test)] macro_rules! generic_event_test_case { ($type:ty) => { + #[cfg(feature = "zbus")] #[test] fn generic_event_uses() { let struct_event = <$type>::default(); assert_eq!(struct_event.path().as_str(), "/org/a11y/atspi/accessible/null"); assert_eq!(struct_event.sender().as_str(), ":0.0"); - let item = struct_event.item.clone(); let body = struct_event.body(); - let build_struct = <$type>::from_message_parts(item, body) + + let builder = zbus::Message::signal( + struct_event.path(), + <$type as BusProperties>::DBUS_INTERFACE, + <$type as BusProperties>::DBUS_MEMBER, + ) + .expect("Should build a message from the default event struct."); + + let msg = builder + .sender(":0.0") + .unwrap() + .build(&body) + .expect("Should build a message from the default event struct."); + + let build_struct = <$type>::try_from_message(&msg) .expect("<$type as Default>'s parts should build a valid ObjectRef"); assert_eq!(struct_event, build_struct); } @@ -477,9 +491,9 @@ macro_rules! zbus_message_test_case { "org.a11y.atspi.accessible.technically.valid", "FakeMember", ) - .unwrap() + .expect("Should build a message from the valid args.") .sender(":0.0") - .unwrap() + .expect("Valid sender \":0.0\" should be set.") .build(&<$type>::default().body()) .unwrap(); let event = <$type>::try_from(&fake_msg); @@ -530,6 +544,7 @@ macro_rules! event_wrapper_test_cases { #[rename_item::rename(name($type), prefix = "events_tests_", case = "snake")] mod foo { use super::{$any_subtype, $type, Event, BusProperties}; + #[cfg(feature = "zbus")] #[test] fn into_and_try_from_event() { // Create a default event struct from its type's `Default::default()` impl. diff --git a/atspi/Cargo.toml b/atspi/Cargo.toml index c894fb44..4e889e83 100644 --- a/atspi/Cargo.toml +++ b/atspi/Cargo.toml @@ -28,12 +28,12 @@ connection-async-std = ["atspi-connection/async-std", "connection"] connection-tokio = ["atspi-connection/tokio", "connection"] tracing = ["atspi-connection/tracing"] + [dependencies] atspi-common = { path = "../atspi-common", version = "0.5.0", default-features = false } atspi-connection = { path = "../atspi-connection", version = "0.5.0", default-features = false, optional = true } atspi-proxies = { path = "../atspi-proxies", version = "0.5.0", default-features = false, optional = true } -zbus = { workspace = true, optional = true } - +zbus = { workspace = true, optional = true, default-features = false } [[bench]] name = "event_parsing"