Struct atspi_connection::AccessibilityConnection

source ·
pub struct AccessibilityConnection { /* private fields */ }
Expand description

A connection to the at-spi bus

Implementations§

source§

impl AccessibilityConnection

source

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.

source

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

source

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 }
    }
source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn connection(&self) -> &Connection

Shorthand for a reference to the underlying zbus::Connection

source

pub async fn send_event<T>(&self, event: T) -> Result<(), AtspiError>

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:

  1. zbus::Message fails at any point, or
  2. 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>>§

source

pub fn inner(&self) -> &Proxy<'p>

The reference to the underlying zbus::Proxy.

source

pub async fn deregister_event(&self, event: &str) -> Result<(), Error>

DeregisterEvent method

source

pub async fn registered_events( &self, ) -> Result<Vec<(OwnedBusName, String)>, Error>

GetRegisteredEvents method

source

pub async fn register_event(&self, event: &str) -> Result<(), Error>

RegisterEvent method

Trait Implementations§

source§

impl Deref for AccessibilityConnection

§

type Target = RegistryProxy<'static>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more