Skip to content

Commit

Permalink
Help WASM target compile
Browse files Browse the repository at this point in the history
We cannot compile zbus in WASM context, so this branch's use of `Message` in
the `BusProperties::try_from_message` method is problematic.

Because `BusProperties` is used to blanket-implement some other traits, this
commit tries to be least intrusive and avoids having `try_from_message`
in the trait when zbus is not set as feature.

The obvious downside is that `BusProperties` now has two sets of behaviour,
depending on the "zbus" feature.
That being said, `try_from_message` is not relevant anyway without zbus support.
  • Loading branch information
luukvanderduim committed May 17, 2024
1 parent 61c13e2 commit 7f2b6c4
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 2 deletions.
6 changes: 6 additions & 0 deletions atspi-common/src/events/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl BusProperties for LoadCompleteEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -168,6 +169,7 @@ impl BusProperties for ReloadEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -187,6 +189,7 @@ impl BusProperties for LoadStoppedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -206,6 +209,7 @@ impl BusProperties for ContentChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -225,6 +229,7 @@ impl BusProperties for AttributesChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -244,6 +249,7 @@ impl BusProperties for PageChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand Down
2 changes: 2 additions & 0 deletions atspi-common/src/events/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct FocusEvent {
pub item: crate::events::ObjectRef,
}

#[cfg(feature = "zbus")]
impl BusProperties for FocusEvent {
const DBUS_MEMBER: &'static str = "Focus";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Focus";
Expand All @@ -72,6 +73,7 @@ impl BusProperties for FocusEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand Down
9 changes: 7 additions & 2 deletions atspi-common/src/events/keyboard.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -66,6 +69,7 @@ pub struct ModifiersEvent {
pub current_modifiers: i32,
}

#[cfg(feature = "zbus")]
impl BusProperties for ModifiersEvent {
const DBUS_MEMBER: &'static str = "Modifiers";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Keyboard";
Expand All @@ -75,6 +79,7 @@ impl BusProperties for ModifiersEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body: EventBodyOwned = msg.try_into()?;
Expand Down
10 changes: 10 additions & 0 deletions atspi-common/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ impl BusProperties for LegacyAddAccessibleEvent {

type Body = LegacyCacheItem;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let body = msg.body();
let node_added: Self::Body = body.deserialize::<Self::Body>()?;
Expand Down Expand Up @@ -472,6 +473,7 @@ impl BusProperties for AddAccessibleEvent {

type Body = CacheItem;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let body = msg.body();
let node_added: Self::Body = body.deserialize::<Self::Body>()?;
Expand Down Expand Up @@ -512,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 =
Expand All @@ -521,6 +524,7 @@ impl BusProperties for RemoveAccessibleEvent {

type Body = ObjectRef;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let body = msg.body();
let node_removed: Self::Body = body.deserialize::<Self::Body>()?;
Expand Down Expand Up @@ -723,6 +727,7 @@ impl BusProperties for EventListenerDeregisteredEvent {

type Body = EventListeners;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body: Self::Body = msg.body().deserialize::<Self::Body>()?;
Expand Down Expand Up @@ -759,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 =
Expand All @@ -768,6 +774,7 @@ impl BusProperties for EventListenerRegisteredEvent {

type Body = EventListeners;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body: Self::Body = msg.body().deserialize::<Self::Body>()?;
Expand Down Expand Up @@ -805,6 +812,7 @@ impl TryFrom<Event> for AvailableEvent {
}
}
event_test_cases!(AvailableEvent);

impl BusProperties for AvailableEvent {
const REGISTRY_EVENT_STRING: &'static str = "Socket:Available";
const MATCH_RULE_STRING: &'static str =
Expand All @@ -814,6 +822,7 @@ impl BusProperties for AvailableEvent {

type Body = ObjectRef;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = msg.try_into()?;
let body = msg.body();
Expand Down Expand Up @@ -997,6 +1006,7 @@ pub trait BusProperties {
///
/// 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.
#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> std::result::Result<Self, AtspiError>
where
Self: Sized;
Expand Down
3 changes: 3 additions & 0 deletions atspi-common/src/events/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl BusProperties for AbsEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -128,6 +129,7 @@ impl BusProperties for RelEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -149,6 +151,7 @@ impl BusProperties for ButtonEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand Down
22 changes: 22 additions & 0 deletions atspi-common/src/events/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl BusProperties for PropertyChangeEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -609,6 +610,7 @@ impl BusProperties for BoundsChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -628,6 +630,7 @@ impl BusProperties for LinkSelectedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -647,6 +650,7 @@ impl BusProperties for StateChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -668,6 +672,7 @@ impl BusProperties for ChildrenChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand Down Expand Up @@ -695,6 +700,7 @@ impl BusProperties for VisibleDataChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -714,6 +720,7 @@ impl BusProperties for SelectionChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -733,6 +740,7 @@ impl BusProperties for ModelChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -752,6 +760,7 @@ impl BusProperties for ActiveDescendantChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -773,6 +782,7 @@ impl BusProperties for AnnouncementEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand All @@ -798,6 +808,7 @@ impl BusProperties for AttributesChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -816,6 +827,7 @@ impl BusProperties for RowInsertedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -834,6 +846,7 @@ impl BusProperties for RowReorderedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -852,6 +865,7 @@ impl BusProperties for RowDeletedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -870,6 +884,7 @@ impl BusProperties for ColumnInsertedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -888,6 +903,7 @@ impl BusProperties for ColumnReorderedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -906,6 +922,7 @@ impl BusProperties for ColumnDeletedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -925,6 +942,7 @@ impl BusProperties for TextBoundsChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -944,6 +962,7 @@ impl BusProperties for TextSelectionChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -963,6 +982,7 @@ impl BusProperties for TextChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand Down Expand Up @@ -990,6 +1010,7 @@ impl BusProperties for TextAttributesChangedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
Ok(Self { item: msg.try_into()? })
}
Expand All @@ -1009,6 +1030,7 @@ impl BusProperties for TextCaretMovedEvent {

type Body = EventBodyOwned;

#[cfg(feature = "zbus")]
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError> {
let item = ObjectRef::try_from(msg)?;
let body = EventBodyOwned::try_from(msg)?;
Expand Down
Loading

0 comments on commit 7f2b6c4

Please sign in to comment.