pub struct AccessibilityConnection { /* private fields */ }Expand description
A connection to the at-spi bus
Implementations§
Source§impl AccessibilityConnection
impl AccessibilityConnection
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Open a new connection to the bus
§Errors
May error when a bus is not available, or when the accessibility bus (AT-SPI) can not be found.
Sourcepub async fn from_address(bus_addr: Address) -> Result<Self>
pub async fn from_address(bus_addr: Address) -> Result<Self>
Returns an AccessibilityConnection, a wrapper for the RegistryProxy; a handle for the registry provider
on the accessibility bus.
You may want to call this if you have the accessibility bus address and want a connection with a convenient async event stream provisioning.
Without address, you will want to call open, which tries to obtain the accessibility bus’ address
on your behalf.
§Errors
RegistryProxy is configured with invalid path, interface or destination
Sourcepub fn event_stream(&self) -> impl Stream<Item = Result<Event, AtspiError>>
pub fn event_stream(&self) -> impl Stream<Item = Result<Event, AtspiError>>
Stream yielding all Event types.
Monitor this stream to be notified and receive events on the a11y bus.
§Example
Basic use:
use atspi_connection::AccessibilityConnection;
use enumflags2::BitFlag;
use atspi_connection::common::events::object::{ObjectEvents, StateChangedEvent};
use zbus::{fdo::DBusProxy, MatchRule, MessageType};
use atspi_connection::common::events::Event;
let atspi = AccessibilityConnection::new().await?;
atspi.register_event::<ObjectEvents>().await?;
let mut events = atspi.event_stream();
std::pin::pin!(&mut events);
while let Some(Ok(ev)) = events.next().await {
// Handle Object events
if let Ok(event) = StateChangedEvent::try_from(ev) {
// do something else here
} else { continue }
}Sourcepub async fn add_match_rule<T: HasMatchRule>(&self) -> Result<(), AtspiError>
pub async fn add_match_rule<T: HasMatchRule>(&self) -> Result<(), AtspiError>
Registers an events as defined in [atspi-types::events]. This function registers a single event, like so:
use atspi_connection::common::events::object::StateChangedEvent;
let connection = atspi_connection::AccessibilityConnection::new().await.unwrap();
connection.register_event::<StateChangedEvent>().await.unwrap();§Errors
This function may return an error if a zbus::Error is caused by all the various calls to zbus::fdo::DBusProxy and zbus::MatchRule::try_from.
Sourcepub async fn remove_match_rule<T: HasMatchRule>(&self) -> Result<(), AtspiError>
pub async fn remove_match_rule<T: HasMatchRule>(&self) -> Result<(), AtspiError>
Deregisters an events as defined in [atspi-types::events]. This function registers a single event, like so:
use atspi_connection::common::events::object::StateChangedEvent;
let connection = atspi_connection::AccessibilityConnection::new().await.unwrap();
connection.add_match_rule::<StateChangedEvent>().await.unwrap();
connection.remove_match_rule::<StateChangedEvent>().await.unwrap();§Errors
This function may return an error if a zbus::Error is caused by all the various calls to zbus::fdo::DBusProxy and zbus::MatchRule::try_from.
Sourcepub async fn add_registry_event<T: HasRegistryEventString>(
&self,
) -> Result<(), AtspiError>
pub async fn add_registry_event<T: HasRegistryEventString>( &self, ) -> Result<(), AtspiError>
Add a registry event.
This tells accessible applications which events should be forwarded to the accessibility bus.
This is called by Self::register_event.
use atspi_connection::common::events::object::StateChangedEvent;
let connection = atspi_connection::AccessibilityConnection::new().await.unwrap();
connection.add_registry_event::<StateChangedEvent>().await.unwrap();
connection.remove_registry_event::<StateChangedEvent>().await.unwrap();§Errors
May cause an error if the DBus method atspi_proxies::registry::RegistryProxy::register_event fails.
Sourcepub async fn remove_registry_event<T: HasRegistryEventString>(
&self,
) -> Result<(), AtspiError>
pub async fn remove_registry_event<T: HasRegistryEventString>( &self, ) -> Result<(), AtspiError>
Remove a registry event.
This tells accessible applications which events should be forwarded to the accessibility bus.
This is called by Self::deregister_event.
It may be called like so:
use atspi_connection::common::events::object::StateChangedEvent;
let connection = atspi_connection::AccessibilityConnection::new().await.unwrap();
connection.add_registry_event::<StateChangedEvent>().await.unwrap();
connection.remove_registry_event::<StateChangedEvent>().await.unwrap();§Errors
May cause an error if the DBus method RegistryProxy::deregister_event fails.
Sourcepub async fn register_event<T: HasRegistryEventString + HasMatchRule>(
&self,
) -> Result<(), AtspiError>
pub async fn register_event<T: HasRegistryEventString + HasMatchRule>( &self, ) -> Result<(), AtspiError>
This calls Self::add_registry_event and Self::add_match_rule, two components necessary to receive accessibility events.
§Errors
This will only fail if [Self::add_registry_event[ or Self::add_match_rule fails.
Sourcepub async fn deregister_event<T: HasRegistryEventString + HasMatchRule>(
&self,
) -> Result<(), AtspiError>
pub async fn deregister_event<T: HasRegistryEventString + HasMatchRule>( &self, ) -> Result<(), AtspiError>
This calls Self::remove_registry_event and Self::remove_match_rule, two components necessary to receive accessibility events.
§Errors
This will only fail if Self::remove_registry_event or Self::remove_match_rule fails.
Sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
Shorthand for a reference to the underlying zbus::Connection
Sourcepub async fn send_event<T>(&self, event: T) -> Result<(), AtspiError>where
T: BusProperties + EventProperties,
pub async fn send_event<T>(&self, event: T) -> Result<(), AtspiError>where
T: BusProperties + EventProperties,
Send an event over the accessibility bus.
This converts the event into a zbus::Message using the BusProperties trait.
§Errors
This will only fail if:
zbus::Messagefails at any point, or- sending the event fails for some reason.
Both of these conditions should never happen as long as you have a valid event.
Methods from Deref<Target = RegistryProxy<'static>>§
Sourcepub async fn registered_events(
&self,
) -> Result<Vec<(OwnedBusName, String)>, Error>
pub async fn registered_events( &self, ) -> Result<Vec<(OwnedBusName, String)>, Error>
GetRegisteredEvents method