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::Message
fails 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