feat(client): redesign native UI, themes, settings and avatars
Separate conversation drafts and voice view state, add native settings and restricted CSS themes, implement validated avatar cropping, and refresh dependencies with documented desktop compatibility backports.
This commit is contained in:
parent
44d284a568
commit
8e5ab56611
276 changed files with 53546 additions and 3399 deletions
28
patches/atspi-common/src/action.rs
vendored
Normal file
28
patches/atspi-common/src/action.rs
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use zbus::wire::Type;
|
||||
|
||||
/// An action which may be triggered through the accessibility API.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
pub struct Action {
|
||||
/// The name of the action
|
||||
pub name: String,
|
||||
/// Description of the action
|
||||
pub description: String,
|
||||
// TODO: should be an enum/stricter type; this is why it's in its own file.
|
||||
/// The keybinding(s) used to trigger it (without the AT).
|
||||
pub keybinding: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Action;
|
||||
use zbus_lockstep::method_return_signature;
|
||||
use zbus::wire::Type;
|
||||
#[test]
|
||||
fn validate_action_signature() {
|
||||
// signature is of type `a(sss)`, where `(sss)` is the type we're validating.
|
||||
let action_signature =
|
||||
method_return_signature!(member: "GetActions", interface: "org.a11y.atspi.Action");
|
||||
assert_eq!(Vec::<Action>::SIGNATURE, &action_signature);
|
||||
}
|
||||
}
|
||||
122
patches/atspi-common/src/cache.rs
vendored
Normal file
122
patches/atspi-common/src/cache.rs
vendored
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
//! Common types for `org.a11y.atspi.Cache` events.
|
||||
//!
|
||||
|
||||
use crate::{object_ref::ObjectRefOwned, InterfaceSet, ObjectRef, Role, StateSet};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zbus_lockstep_macros::validate;
|
||||
use zbus::wire::Type;
|
||||
|
||||
/// The item type provided by `Cache:Add` signals
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
|
||||
#[validate(signal: "AddAccessible")]
|
||||
pub struct CacheItem {
|
||||
/// The accessible object (within the application) (so)
|
||||
pub object: ObjectRefOwned,
|
||||
/// The application (root object(?) (so)
|
||||
pub app: ObjectRefOwned,
|
||||
/// The parent object. (so)
|
||||
pub parent: ObjectRefOwned,
|
||||
/// The accessbile index in parent. i
|
||||
pub index: i32,
|
||||
/// Child count of the accessible i
|
||||
pub children: i32,
|
||||
/// The exposed interface(s) set. as
|
||||
pub ifaces: InterfaceSet,
|
||||
/// The short localized name. s
|
||||
pub short_name: String,
|
||||
/// `ObjectRef` role. u
|
||||
pub role: Role,
|
||||
/// More detailed localized name.
|
||||
pub name: String,
|
||||
/// The states applicable to the accessible. au
|
||||
pub states: StateSet,
|
||||
}
|
||||
|
||||
impl Default for CacheItem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
object: ObjectRefOwned::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/object",
|
||||
),
|
||||
app: ObjectRefOwned::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/application",
|
||||
),
|
||||
parent: ObjectRefOwned::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/parent",
|
||||
),
|
||||
index: 0,
|
||||
children: 0,
|
||||
ifaces: InterfaceSet::empty(),
|
||||
short_name: String::default(),
|
||||
role: Role::Invalid,
|
||||
name: String::default(),
|
||||
states: StateSet::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The item type provided by `Cache:Add` signals
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
|
||||
pub struct LegacyCacheItem {
|
||||
/// The accessible object (within the application) (so)
|
||||
pub object: ObjectRefOwned,
|
||||
/// The application (root object(?) (so)
|
||||
pub app: ObjectRefOwned,
|
||||
/// The parent object. (so)
|
||||
pub parent: ObjectRefOwned,
|
||||
/// List of references to the accessible's children. a(so)
|
||||
pub children: Vec<ObjectRefOwned>,
|
||||
/// The exposed interface(s) set. as
|
||||
pub ifaces: InterfaceSet,
|
||||
/// The short localized name. s
|
||||
pub short_name: String,
|
||||
/// `ObjectRef` role. u
|
||||
pub role: Role,
|
||||
/// More detailed localized name.
|
||||
pub name: String,
|
||||
/// The states applicable to the accessible. au
|
||||
pub states: StateSet,
|
||||
}
|
||||
|
||||
impl Default for LegacyCacheItem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
object: ObjectRef::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/object",
|
||||
)
|
||||
.into(),
|
||||
app: ObjectRef::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/application",
|
||||
)
|
||||
.into(),
|
||||
parent: ObjectRef::from_static_str_unchecked(
|
||||
":0.0",
|
||||
"/org/a11y/atspi/accessible/parent",
|
||||
)
|
||||
.into(),
|
||||
children: Vec::new(),
|
||||
ifaces: InterfaceSet::empty(),
|
||||
short_name: String::default(),
|
||||
role: Role::Invalid,
|
||||
name: String::default(),
|
||||
states: StateSet::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn zvariant_type_signature_of_legacy_cache_item() {
|
||||
use std::str::FromStr;
|
||||
assert_eq!(
|
||||
*<LegacyCacheItem as Type>::SIGNATURE,
|
||||
zbus::wire::Signature::from_str("((so)(so)(so)a(so)assusau)").unwrap()
|
||||
);
|
||||
}
|
||||
210
patches/atspi-common/src/error.rs
vendored
Normal file
210
patches/atspi-common/src/error.rs
vendored
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
/// An error type that can describe atspi and `std` and different `zbus` errors.
|
||||
pub enum AtspiError {
|
||||
/// Converting one type into another failure
|
||||
Conversion(&'static str),
|
||||
|
||||
/// When testing on either variant, we might find the we are not interested in.
|
||||
CacheVariantMismatch,
|
||||
|
||||
/// On specific types, if the event / message member does not match the Event's name.
|
||||
MemberMatch(String),
|
||||
|
||||
/// On specific types, if the event / message member does not match the Event's name.
|
||||
InterfaceMatch(String),
|
||||
|
||||
/// On specific types, if the kind (string variant) does not match the Event's kind.
|
||||
KindMatch(String),
|
||||
|
||||
/// When an interface is not available.
|
||||
InterfaceNotAvailable(&'static str),
|
||||
|
||||
/// To indicate a match or equality test on a signal body signature failed.
|
||||
SignatureMatch(String),
|
||||
|
||||
/// When matching on an unknown interface
|
||||
UnknownInterface,
|
||||
|
||||
/// No interface on event.
|
||||
MissingInterface,
|
||||
|
||||
/// No member on event.
|
||||
MissingMember,
|
||||
|
||||
/// No path on event.
|
||||
MissingPath,
|
||||
|
||||
/// When matching on an unknown role
|
||||
UnknownRole(u32),
|
||||
|
||||
/// No name on bus.
|
||||
MissingName,
|
||||
|
||||
/// The signal that was encountered is unknown.
|
||||
UnknownSignal,
|
||||
|
||||
/// Other errors.
|
||||
Owned(String),
|
||||
|
||||
/// Null-reference error. This is used when an `ObjectRef` is expected to be non-null, but it is null.
|
||||
NullRef(&'static str),
|
||||
|
||||
/// A `zbus` or `zbus::Fdo` error. variant.
|
||||
Zbus(String),
|
||||
|
||||
/// A `zbus_names` error variant
|
||||
ZBusNames(zbus::Error),
|
||||
|
||||
/// A `zbus_names` error variant
|
||||
Zvariant(zbus::Error),
|
||||
|
||||
/// Failed to parse a string into an enum variant
|
||||
ParseError(&'static str),
|
||||
|
||||
/// Failed to get the ID of a path.
|
||||
PathConversionError(ObjectPathConversionError),
|
||||
|
||||
/// Std i/o error variant.
|
||||
IO(std::io::Error),
|
||||
|
||||
/// Failed to convert an integer into another type of integer (usually i32 -> usize).
|
||||
IntConversionError(std::num::TryFromIntError),
|
||||
|
||||
/// An infallible error; this is just something to satisfy the compiler.
|
||||
Infallible,
|
||||
}
|
||||
|
||||
impl std::error::Error for AtspiError {}
|
||||
|
||||
impl std::fmt::Display for AtspiError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
|
||||
Self::MemberMatch(e) => {
|
||||
f.write_str("atspi: member mismatch in conversion: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::InterfaceMatch(e) => {
|
||||
f.write_str("atspi: interface mismatch in conversion: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::KindMatch(e) => {
|
||||
f.write_str(format!("atspi: kind mismatch in conversion: {e}").as_str())
|
||||
}
|
||||
Self::SignatureMatch(e) => {
|
||||
f.write_str(format!("atspi: body signature mismatch in conversion: {e:?}").as_str())
|
||||
}
|
||||
Self::InterfaceNotAvailable(e) => {
|
||||
f.write_str(format!("atspi: interface not available: {e}").as_str())
|
||||
}
|
||||
Self::UnknownInterface => f.write_str("Unknown interface."),
|
||||
Self::MissingInterface => f.write_str("Missing interface."),
|
||||
Self::MissingMember => f.write_str("Missing member."),
|
||||
Self::MissingPath => f.write_str("Missing path."),
|
||||
Self::UnknownRole(e) => {
|
||||
f.write_str("atspi: Unknown role: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
|
||||
Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
|
||||
Self::Owned(e) => {
|
||||
f.write_str("atspi: other error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::NullRef(e) => {
|
||||
f.write_str("atspi: null reference: ")?;
|
||||
f.write_str(e)
|
||||
}
|
||||
Self::Zbus(e) => {
|
||||
f.write_str("ZBus Error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::Zvariant(e) => {
|
||||
f.write_str("Zvariant error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::ZBusNames(e) => {
|
||||
f.write_str("ZBus_names Error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::ParseError(e) => f.write_str(e),
|
||||
Self::PathConversionError(e) => {
|
||||
f.write_str("ID cannot be extracted from the path: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::IO(e) => {
|
||||
f.write_str("std IO Error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::IntConversionError(e) => {
|
||||
f.write_str("Integer conversion error: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
Self::MissingName => f.write_str("Missing name for a bus."),
|
||||
Self::Infallible => {
|
||||
f.write_str("Infallible; only to trick the compiler. This should never happen.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::convert::Infallible> for AtspiError {
|
||||
fn from(_e: std::convert::Infallible) -> Self {
|
||||
Self::Infallible
|
||||
}
|
||||
}
|
||||
impl From<std::num::TryFromIntError> for AtspiError {
|
||||
fn from(e: std::num::TryFromIntError) -> Self {
|
||||
Self::IntConversionError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl From<zbus::fdo::Error> for AtspiError {
|
||||
fn from(e: zbus::fdo::Error) -> Self {
|
||||
Self::Zbus(format!("{e:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<zbus::Error> for AtspiError {
|
||||
fn from(e: zbus::Error) -> Self {
|
||||
Self::Zbus(format!("{e:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
impl From<std::io::Error> for AtspiError {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Self::IO(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectPathConversionError> for AtspiError {
|
||||
fn from(e: ObjectPathConversionError) -> AtspiError {
|
||||
Self::PathConversionError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ObjectPathConversionError {
|
||||
NoIdAvailable,
|
||||
ParseError(<i64 as std::str::FromStr>::Err),
|
||||
}
|
||||
impl std::fmt::Display for ObjectPathConversionError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::NoIdAvailable => f.write_str("No ID available in the path."),
|
||||
Self::ParseError(e) => {
|
||||
f.write_str("Failure to parse: ")?;
|
||||
e.fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ObjectPathConversionError {}
|
||||
168
patches/atspi-common/src/events/cache.rs
vendored
Normal file
168
patches/atspi-common/src/events/cache.rs
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
use crate::cache::{CacheItem, LegacyCacheItem};
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::error::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::object_ref::ObjectRef;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
use crate::{
|
||||
events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString},
|
||||
object_ref::ObjectRefOwned,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use super::{MessageConversion, MessageConversionExt};
|
||||
|
||||
/// Type that contains the `zbus::Message` for meta information and
|
||||
/// the [`crate::cache::LegacyCacheItem`]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
|
||||
pub struct LegacyAddAccessibleEvent {
|
||||
/// The [`ObjectRef`] the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
/// A cache item to add to the internal cache.
|
||||
pub node_added: LegacyCacheItem,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(LegacyAddAccessibleEvent);
|
||||
|
||||
event_test_cases!(LegacyAddAccessibleEvent, Explicit);
|
||||
impl_from_dbus_message!(LegacyAddAccessibleEvent, Explicit);
|
||||
impl_event_properties!(LegacyAddAccessibleEvent);
|
||||
impl_to_dbus_message!(LegacyAddAccessibleEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LegacyAddAccessibleEvent,
|
||||
"AddAccessible",
|
||||
"org.a11y.atspi.Cache",
|
||||
"cache:add",
|
||||
"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for LegacyAddAccessibleEvent {
|
||||
type Body<'msg> = LegacyCacheItem;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
Ok(Self { item: item.into(), node_added: body.deserialize_ignore_signature::<Self::Body<'_>>()? })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.node_added.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that contains the `zbus::Message` for meta information and
|
||||
/// the [`crate::cache::CacheItem`]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
|
||||
pub struct AddAccessibleEvent {
|
||||
/// The [`ObjectRef`] the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
/// A cache item to add to the internal cache.
|
||||
pub node_added: CacheItem,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(AddAccessibleEvent);
|
||||
|
||||
event_test_cases!(AddAccessibleEvent, Explicit);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
AddAccessibleEvent,
|
||||
"AddAccessible",
|
||||
"org.a11y.atspi.Cache",
|
||||
"cache:add",
|
||||
"type='signal',interface='org.a11y.atspi.Cache',member='AddAccessible'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for AddAccessibleEvent {
|
||||
type Body<'msg> = CacheItem;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
Ok(Self { item: item.into(), node_added: body.deserialize_ignore_signature::<Self::Body<'_>>()? })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.node_added.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type_with_specified_body_type!(target: AddAccessibleEvent, body: CacheItem);
|
||||
impl_from_dbus_message!(AddAccessibleEvent, Explicit);
|
||||
impl_event_properties!(AddAccessibleEvent);
|
||||
impl_to_dbus_message!(AddAccessibleEvent);
|
||||
|
||||
/// `Cache::RemoveAccessible` signal event type.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
|
||||
pub struct RemoveAccessibleEvent {
|
||||
/// The application that emitted the signal TODO Check Me
|
||||
/// The [`ObjectRef`] the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
/// The node that was removed from the application tree TODO Check Me
|
||||
pub node_removed: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(RemoveAccessibleEvent);
|
||||
|
||||
event_test_cases!(RemoveAccessibleEvent, Explicit);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
RemoveAccessibleEvent,
|
||||
"RemoveAccessible",
|
||||
"org.a11y.atspi.Cache",
|
||||
"cache:remove",
|
||||
"type='signal',interface='org.a11y.atspi.Cache',member='RemoveAccessible'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for RemoveAccessibleEvent {
|
||||
type Body<'msg> = ObjectRefOwned;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
Ok(Self {
|
||||
item: item.into(),
|
||||
node_removed: body.deserialize_ignore_signature::<Self::Body<'_>>()?,
|
||||
})
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.node_removed.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversionExt<'_, LegacyCacheItem> for LegacyAddAccessibleEvent {
|
||||
fn try_from_message(msg: &zbus::Message, hdr: &Header) -> Result<Self, AtspiError> {
|
||||
<LegacyAddAccessibleEvent as MessageConversionExt<crate::LegacyCacheItem>>::validate_interface(hdr)?;
|
||||
<LegacyAddAccessibleEvent as MessageConversionExt<crate::LegacyCacheItem>>::validate_member(hdr)?;
|
||||
<LegacyAddAccessibleEvent as MessageConversionExt<crate::LegacyCacheItem>>::validate_body(
|
||||
msg,
|
||||
)?;
|
||||
<LegacyAddAccessibleEvent as MessageConversion>::from_message_unchecked(msg, hdr)
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type_with_specified_body_type!(target: RemoveAccessibleEvent, body: ObjectRefOwned);
|
||||
impl_from_dbus_message!(RemoveAccessibleEvent, Explicit);
|
||||
impl_event_properties!(RemoveAccessibleEvent);
|
||||
impl_to_dbus_message!(RemoveAccessibleEvent);
|
||||
166
patches/atspi-common/src/events/document.rs
vendored
Normal file
166
patches/atspi-common/src/events/document.rs
vendored
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
use crate::events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString};
|
||||
use crate::object_ref::ObjectRefOwned;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::Header;
|
||||
|
||||
/// An event triggered by the completion of a document load action.
|
||||
/// For example: a web page has finished loading its initial payload, or
|
||||
/// `LibreOffice` has loaded a document from disk.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct LoadCompleteEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
/// An event triggered by a reloading of a document.
|
||||
/// 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 [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
/// An event triggered by the cancelling of a document load.
|
||||
/// 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 [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ContentChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct AttributesChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
/// The focused page has changed.
|
||||
///
|
||||
/// This event is usually sent only by document readers, signaling
|
||||
/// that the _physical page equivalent is now different.
|
||||
/// This event does not encode _which_ page is the new one, only that a new page is now the primary
|
||||
/// one.
|
||||
///
|
||||
/// See `atspi_proxies::document::DocumentProxy::current_page_number` to actively find the
|
||||
/// page number.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct PageChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LoadCompleteEvent,
|
||||
"LoadComplete",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:load-complete",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='LoadComplete'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ReloadEvent,
|
||||
"Reload",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:reload",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='LoadStopped'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LoadStoppedEvent,
|
||||
"LoadStopped",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:load-stopped",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='LoadStopped'"
|
||||
);
|
||||
|
||||
// TODO confirm registry event string, not found in grep at at-spi2-core
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ContentChangedEvent,
|
||||
"ContentChanged",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:content-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='ContentChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
AttributesChangedEvent,
|
||||
"AttributesChanged",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:attributes-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='AttributesChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
PageChangedEvent,
|
||||
"PageChanged",
|
||||
"org.a11y.atspi.Event.Document",
|
||||
"document:page-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Document',member='PageChanged'"
|
||||
);
|
||||
|
||||
impl_event_type_properties_for_event!(LoadCompleteEvent);
|
||||
|
||||
event_test_cases!(LoadCompleteEvent);
|
||||
impl_to_dbus_message!(LoadCompleteEvent);
|
||||
impl_from_dbus_message!(LoadCompleteEvent);
|
||||
impl_event_properties!(LoadCompleteEvent);
|
||||
impl_from_object_ref!(LoadCompleteEvent);
|
||||
|
||||
impl_event_type_properties_for_event!(ReloadEvent);
|
||||
event_test_cases!(ReloadEvent);
|
||||
impl_to_dbus_message!(ReloadEvent);
|
||||
impl_from_dbus_message!(ReloadEvent);
|
||||
impl_event_properties!(ReloadEvent);
|
||||
impl_from_object_ref!(ReloadEvent);
|
||||
|
||||
impl_event_type_properties_for_event!(LoadStoppedEvent);
|
||||
event_test_cases!(LoadStoppedEvent);
|
||||
impl_to_dbus_message!(LoadStoppedEvent);
|
||||
impl_from_dbus_message!(LoadStoppedEvent);
|
||||
impl_event_properties!(LoadStoppedEvent);
|
||||
impl_from_object_ref!(LoadStoppedEvent);
|
||||
|
||||
impl_event_type_properties_for_event!(ContentChangedEvent);
|
||||
event_test_cases!(ContentChangedEvent);
|
||||
impl_to_dbus_message!(ContentChangedEvent);
|
||||
impl_from_dbus_message!(ContentChangedEvent);
|
||||
impl_event_properties!(ContentChangedEvent);
|
||||
impl_from_object_ref!(ContentChangedEvent);
|
||||
|
||||
impl_event_type_properties_for_event!(AttributesChangedEvent);
|
||||
event_test_cases!(AttributesChangedEvent);
|
||||
impl_to_dbus_message!(AttributesChangedEvent);
|
||||
impl_from_dbus_message!(AttributesChangedEvent);
|
||||
impl_event_properties!(AttributesChangedEvent);
|
||||
impl_from_object_ref!(AttributesChangedEvent);
|
||||
|
||||
impl_event_type_properties_for_event!(PageChangedEvent);
|
||||
event_test_cases!(PageChangedEvent);
|
||||
impl_to_dbus_message!(PageChangedEvent);
|
||||
impl_from_dbus_message!(PageChangedEvent);
|
||||
impl_event_properties!(PageChangedEvent);
|
||||
impl_from_object_ref!(PageChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(LoadCompleteEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ReloadEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(LoadStoppedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ContentChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(AttributesChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(PageChangedEvent);
|
||||
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(LoadCompleteEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ReloadEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(LoadStoppedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ContentChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(AttributesChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(PageChangedEvent);
|
||||
1078
patches/atspi-common/src/events/event_body.rs
vendored
Normal file
1078
patches/atspi-common/src/events/event_body.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
2220
patches/atspi-common/src/events/event_wrappers.rs
vendored
Normal file
2220
patches/atspi-common/src/events/event_wrappers.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
36
patches/atspi-common/src/events/focus.rs
vendored
Normal file
36
patches/atspi-common/src/events/focus.rs
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use crate::error::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
use crate::{
|
||||
events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString},
|
||||
object_ref::ObjectRefOwned,
|
||||
};
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::Header;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct FocusEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(FocusEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event! {
|
||||
FocusEvent,
|
||||
"Focus",
|
||||
"org.a11y.atspi.Event.Focus",
|
||||
"focus:",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Focus',member='Focus'"
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type!(FocusEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(FocusEvent);
|
||||
|
||||
event_test_cases!(FocusEvent);
|
||||
impl_to_dbus_message!(FocusEvent);
|
||||
impl_from_dbus_message!(FocusEvent);
|
||||
impl_event_properties!(FocusEvent);
|
||||
impl_from_object_ref!(FocusEvent);
|
||||
77
patches/atspi-common/src/events/keyboard.rs
vendored
Normal file
77
patches/atspi-common/src/events/keyboard.rs
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use super::event_body::EventBody;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::error::AtspiError;
|
||||
use crate::{
|
||||
events::{DBusInterface, DBusMatchRule, DBusMember, EventBodyOwned, RegistryEventString},
|
||||
object_ref::ObjectRefOwned,
|
||||
};
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::{events::MessageConversion, EventProperties, ObjectRef};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ModifiersEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
pub previous_modifiers: i32,
|
||||
pub current_modifiers: i32,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ModifiersEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event! {
|
||||
ModifiersEvent,
|
||||
"Modifiers",
|
||||
"org.a11y.atspi.Event.Keyboard",
|
||||
"keyboard:modifiers",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Keyboard',member='Modifiers'"
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for ModifiersEvent {
|
||||
type Body<'msg> = EventBody<'msg>;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let body = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self {
|
||||
item: item.into(),
|
||||
previous_modifiers: body.detail1(),
|
||||
current_modifiers: body.detail2(),
|
||||
})
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
EventBodyOwned {
|
||||
detail1: self.previous_modifiers,
|
||||
detail2: self.current_modifiers,
|
||||
..Default::default()
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type!(ModifiersEvent);
|
||||
|
||||
event_test_cases!(ModifiersEvent);
|
||||
impl_to_dbus_message!(ModifiersEvent);
|
||||
impl_from_dbus_message!(ModifiersEvent);
|
||||
impl_event_properties!(ModifiersEvent);
|
||||
|
||||
impl From<ModifiersEvent> for EventBodyOwned {
|
||||
fn from(event: ModifiersEvent) -> Self {
|
||||
EventBodyOwned {
|
||||
detail1: event.previous_modifiers,
|
||||
detail2: event.current_modifiers,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
27
patches/atspi-common/src/events/mod.rs
vendored
Normal file
27
patches/atspi-common/src/events/mod.rs
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
pub mod cache;
|
||||
pub mod document;
|
||||
pub mod event_body;
|
||||
#[cfg(feature = "wrappers")]
|
||||
pub mod event_wrappers;
|
||||
pub mod focus;
|
||||
pub mod keyboard;
|
||||
pub mod mouse;
|
||||
pub mod object;
|
||||
pub mod registry;
|
||||
pub mod terminal;
|
||||
pub mod traits;
|
||||
pub mod window;
|
||||
pub use event_body::{
|
||||
EventBody, EventBodyBorrowed, EventBodyOwned, EventBodyQtBorrowed, EventBodyQtOwned,
|
||||
};
|
||||
#[cfg(feature = "wrappers")]
|
||||
pub use event_wrappers::{
|
||||
CacheEvents, DocumentEvents, Event, EventListenerEvents, FocusEvents, KeyboardEvents,
|
||||
MouseEvents, ObjectEvents, TerminalEvents, WindowEvents,
|
||||
};
|
||||
pub use traits::{
|
||||
DBusInterface, DBusMatchRule, DBusMember, DBusProperties, EventProperties, EventTypeProperties,
|
||||
RegistryEventString,
|
||||
};
|
||||
#[cfg(feature = "zbus")]
|
||||
pub use traits::{MessageConversion, MessageConversionExt};
|
||||
213
patches/atspi-common/src/events/mouse.rs
vendored
Normal file
213
patches/atspi-common/src/events/mouse.rs
vendored
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use crate::events::MessageConversion;
|
||||
use crate::events::{
|
||||
DBusInterface, DBusMatchRule, DBusMember, EventBody, EventBodyOwned, RegistryEventString,
|
||||
};
|
||||
use crate::object_ref::ObjectRefOwned;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::{error::AtspiError, ObjectRef};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct AbsEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(AbsEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct RelEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(RelEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ButtonEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
pub detail: String,
|
||||
pub mouse_x: i32,
|
||||
pub mouse_y: i32,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ButtonEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event! {
|
||||
AbsEvent,
|
||||
"Abs",
|
||||
"org.a11y.atspi.Event.Mouse",
|
||||
"mouse:abs",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Mouse',member='Abs'"
|
||||
}
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event! {
|
||||
RelEvent,
|
||||
"Rel",
|
||||
"org.a11y.atspi.Event.Mouse",
|
||||
"mouse:rel",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Mouse',member='Rel'"
|
||||
}
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event! {
|
||||
ButtonEvent,
|
||||
"Button",
|
||||
"org.a11y.atspi.Event.Mouse",
|
||||
"mouse:button",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Mouse',member='Button'"
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for AbsEvent {
|
||||
type Body<'a> = EventBody<'a>;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let body = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self { item: item.into(), x: body.detail1(), y: body.detail2() })
|
||||
}
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
EventBodyOwned { detail1: self.x, detail2: self.y, ..Default::default() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for RelEvent {
|
||||
type Body<'a> = EventBody<'a>;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let body = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self { item: item.into(), x: body.detail1(), y: body.detail2() })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
EventBodyOwned { detail1: self.x, detail2: self.y, ..Default::default() }.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for ButtonEvent {
|
||||
type Body<'a> = EventBody<'a>;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let mut body = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self {
|
||||
item: item.into(),
|
||||
detail: body.take_kind(),
|
||||
mouse_x: body.detail1(),
|
||||
mouse_y: body.detail2(),
|
||||
})
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
EventBodyOwned::from(self).into()
|
||||
}
|
||||
}
|
||||
|
||||
event_test_cases!(AbsEvent);
|
||||
impl_to_dbus_message!(AbsEvent);
|
||||
impl_from_dbus_message!(AbsEvent);
|
||||
impl_event_properties!(AbsEvent);
|
||||
|
||||
impl From<AbsEvent> for EventBodyOwned {
|
||||
fn from(event: AbsEvent) -> Self {
|
||||
EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&AbsEvent> for EventBodyOwned {
|
||||
fn from(event: &AbsEvent) -> Self {
|
||||
EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AbsEvent> for EventBody<'_> {
|
||||
fn from(event: AbsEvent) -> Self {
|
||||
EventBodyOwned::from(event).into()
|
||||
}
|
||||
}
|
||||
|
||||
event_test_cases!(RelEvent);
|
||||
impl_to_dbus_message!(RelEvent);
|
||||
impl_from_dbus_message!(RelEvent);
|
||||
impl_event_properties!(RelEvent);
|
||||
|
||||
impl From<RelEvent> for EventBodyOwned {
|
||||
fn from(event: RelEvent) -> Self {
|
||||
EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&RelEvent> for EventBodyOwned {
|
||||
fn from(event: &RelEvent) -> Self {
|
||||
EventBodyOwned { detail1: event.x, detail2: event.y, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RelEvent> for EventBody<'_> {
|
||||
fn from(event: RelEvent) -> Self {
|
||||
EventBodyOwned::from(event).into()
|
||||
}
|
||||
}
|
||||
|
||||
event_test_cases!(ButtonEvent);
|
||||
impl_to_dbus_message!(ButtonEvent);
|
||||
impl_from_dbus_message!(ButtonEvent);
|
||||
|
||||
impl_event_properties!(ButtonEvent);
|
||||
impl From<ButtonEvent> for EventBodyOwned {
|
||||
fn from(event: ButtonEvent) -> Self {
|
||||
EventBodyOwned {
|
||||
kind: event.detail,
|
||||
detail1: event.mouse_x,
|
||||
detail2: event.mouse_y,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ButtonEvent> for EventBody<'_> {
|
||||
fn from(event: ButtonEvent) -> Self {
|
||||
EventBodyOwned::from(event).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ButtonEvent> for EventBodyOwned {
|
||||
fn from(event: &ButtonEvent) -> Self {
|
||||
EventBodyOwned {
|
||||
kind: event.detail.clone(),
|
||||
detail1: event.mouse_x,
|
||||
detail2: event.mouse_y,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type!(AbsEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(RelEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ButtonEvent);
|
||||
1237
patches/atspi-common/src/events/object.rs
vendored
Normal file
1237
patches/atspi-common/src/events/object.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
231
patches/atspi-common/src/events/registry.rs
vendored
Normal file
231
patches/atspi-common/src/events/registry.rs
vendored
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
//! This module contains the events that are emitted by the registry daemon.
|
||||
//! The events are [`EventListenerRegisteredEvent`] and [`EventListenerDeregisteredEvent`].
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::object_ref::ObjectRef;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::{error::AtspiError, events::MessageConversion, EventProperties};
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
use zbus_lockstep_macros::validate;
|
||||
use zbus::names::{OwnedUniqueName, UniqueName};
|
||||
use zbus::wire::Type;
|
||||
|
||||
use crate::{
|
||||
events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString},
|
||||
object_ref::ObjectRefOwned,
|
||||
};
|
||||
|
||||
/// An event that is emitted by the registry daemon, to inform that an event has been deregistered
|
||||
/// to no longer listen for.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
|
||||
pub struct EventListenerDeregisteredEvent {
|
||||
/// The [`ObjectRef`] the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
/// A list of events that have been deregistered via the registry interface.
|
||||
/// See `atspi-connection`.
|
||||
pub deregistered_event: EventListeners,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(EventListenerDeregisteredEvent);
|
||||
|
||||
event_test_cases!(EventListenerDeregisteredEvent, Explicit);
|
||||
|
||||
// The registry string cannot be found in upstrream at-spi2-core.
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
EventListenerDeregisteredEvent,
|
||||
"EventListenerDeregistered",
|
||||
"org.a11y.atspi.Registry",
|
||||
"registry:event-listener-deregistered",
|
||||
"type='signal',interface='org.a11y.atspi.Registry',member='EventListenerDeregistered'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for EventListenerDeregisteredEvent {
|
||||
type Body<'a> = EventListeners;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let deregistered_event = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self { item: item.into(), deregistered_event })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.deregistered_event.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type_with_specified_body_type!(target: EventListenerDeregisteredEvent, body: EventListeners);
|
||||
impl_from_dbus_message!(EventListenerDeregisteredEvent, Explicit);
|
||||
impl_event_properties!(EventListenerDeregisteredEvent);
|
||||
impl_to_dbus_message!(EventListenerDeregisteredEvent);
|
||||
|
||||
/// An event that is emitted by the regostry daemon to signal that an event has been registered to listen for.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, Eq, Hash)]
|
||||
pub struct EventListenerRegisteredEvent {
|
||||
/// The [`ObjectRef`] the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
/// A list of events that have been registered via the registry interface.
|
||||
/// See `atspi-connection`.
|
||||
pub registered_event: EventListeners,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(EventListenerRegisteredEvent);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for EventListenerRegisteredEvent {
|
||||
type Body<'a> = EventListeners;
|
||||
|
||||
fn from_message_unchecked_parts(
|
||||
item: ObjectRef,
|
||||
registered_event: DbusBody,
|
||||
) -> Result<Self, AtspiError> {
|
||||
let registered_event = registered_event.deserialize_ignore_signature()?;
|
||||
Ok(Self { item: item.into(), registered_event })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.registered_event.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type_with_specified_body_type!(target: EventListenerRegisteredEvent, body: EventListeners);
|
||||
impl_from_dbus_message!(EventListenerRegisteredEvent, Explicit);
|
||||
impl_event_properties!(EventListenerRegisteredEvent);
|
||||
impl_to_dbus_message!(EventListenerRegisteredEvent);
|
||||
|
||||
event_test_cases!(EventListenerRegisteredEvent, Explicit);
|
||||
|
||||
// The registry string cannot be found in upstrream at-spi2-core.
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
EventListenerRegisteredEvent,
|
||||
"EventListenerRegistered",
|
||||
"org.a11y.atspi.Registry",
|
||||
"registry:event-listener-registered",
|
||||
"type='signal',interface='org.a11y.atspi.Registry',member='EventListenerRegistered'"
|
||||
);
|
||||
|
||||
/// Signal type emitted by `EventListenerRegistered` and `EventListenerDeregistered` signals,
|
||||
/// which belong to the `Registry` interface, implemented by the registry-daemon.
|
||||
#[validate(signal: "EventListenerRegistered")]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
|
||||
pub struct EventListeners {
|
||||
pub bus_name: OwnedUniqueName,
|
||||
// TODO: `path` should be a `zbus::wire::ObjectPath` but that requires changing the signature with an attribute
|
||||
// and `Serialize`/`Deserialize` impls.
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
impl Default for EventListeners {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bus_name: UniqueName::from_static_str_unchecked(":0.0").into(),
|
||||
path: String::from("/org/a11y/atspi/null"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod event_listener_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_event_listener_default_no_panic() {
|
||||
let el = EventListeners::default();
|
||||
assert_eq!(el.bus_name.as_str(), ":0.0");
|
||||
assert_eq!(el.path.as_str(), "/org/a11y/atspi/null");
|
||||
}
|
||||
}
|
||||
|
||||
pub mod socket {
|
||||
//! This module contains the event that is emitted by the registry daemon's `Socket` interface.
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::events::MessageConversion;
|
||||
use crate::events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString};
|
||||
use crate::object_ref::ObjectRefOwned;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::ObjectRef;
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// An event that is emitted when the registry daemon has started.
|
||||
///
|
||||
/// The accessibility registry emits this signal early during startup,
|
||||
/// when it has registered with the `DBus` daemon and is available for
|
||||
/// calls from applications.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, Eq, Hash)]
|
||||
pub struct AvailableEvent {
|
||||
/// The emitting [`ObjectRef`].
|
||||
pub item: ObjectRefOwned,
|
||||
|
||||
/// The [`ObjectRef`] for the Registry's root object.
|
||||
pub socket: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(AvailableEvent);
|
||||
|
||||
event_test_cases!(AvailableEvent, Explicit);
|
||||
|
||||
// We cannot register at Registry for this event, as it is emitted by the Registry itself at early startup.
|
||||
// So, we do not have a registry event string for this event.
|
||||
// The `Available` event is unconditionally emitted:
|
||||
// [at-spi2-core/registryd/registry.c:1437](https://github.com/GNOME/at-spi2-core/blob/019d1a4013216d7d01040cf4eb3b8647bffc0dc9/registryd/registry.c#L1437)
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
AvailableEvent,
|
||||
"Available",
|
||||
"org.a11y.atspi.Socket",
|
||||
"",
|
||||
"type='signal',interface='org.a11y.atspi.Socket',member='Available'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for AvailableEvent {
|
||||
type Body<'a> = ObjectRef<'a>;
|
||||
|
||||
fn from_message_unchecked_parts(
|
||||
item: ObjectRef<'_>,
|
||||
body: DbusBody,
|
||||
) -> Result<Self, AtspiError> {
|
||||
let socket = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self { item: item.into(), socket: socket.into() })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(
|
||||
msg: &zbus::Message,
|
||||
header: &Header,
|
||||
) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
self.socket.clone().into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl_msg_conversion_ext_for_target_type_with_specified_body_type!(target: AvailableEvent, body: ObjectRef<'a>);
|
||||
impl_from_dbus_message!(AvailableEvent, Explicit);
|
||||
impl_event_properties!(AvailableEvent);
|
||||
impl_to_dbus_message!(AvailableEvent);
|
||||
}
|
||||
139
patches/atspi-common/src/events/terminal.rs
vendored
Normal file
139
patches/atspi-common/src/events/terminal.rs
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use crate::error::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::EventProperties;
|
||||
use crate::{
|
||||
events::{DBusInterface, DBusMatchRule, DBusMember, RegistryEventString},
|
||||
object_ref::ObjectRefOwned,
|
||||
};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::Header;
|
||||
|
||||
/// A line of text has been changed.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct LineChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(LineChangedEvent);
|
||||
|
||||
/// The width of a terminal emulator has changed sufficiently such that the number of characters
|
||||
/// able to fit on one *visual* line has changed.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ColumnCountChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ColumnCountChangedEvent);
|
||||
|
||||
/// The height of a terminal emulator has changed sufficiently such that the number of lines
|
||||
/// able to fit within the terminal has changed.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct LineCountChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(LineCountChangedEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ApplicationChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ApplicationChangedEvent);
|
||||
|
||||
/// The width of a terminal emulator has changed sufficiently such that the number of characters
|
||||
/// able to fit on one *visual* line has changed.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct CharWidthChangedEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(CharWidthChangedEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LineChangedEvent,
|
||||
"LineChanged",
|
||||
"org.a11y.atspi.Event.Terminal",
|
||||
"terminal:line-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Terminal',member='LineChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ColumnCountChangedEvent,
|
||||
"ColumncountChanged",
|
||||
"org.a11y.atspi.Event.Terminal",
|
||||
"terminal:columncount-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Terminal',member='ColumncountChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LineCountChangedEvent,
|
||||
"LinecountChanged",
|
||||
"org.a11y.atspi.Event.Terminal",
|
||||
"terminal:linecount-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Terminal',member='LinecountChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ApplicationChangedEvent,
|
||||
"ApplicationChanged",
|
||||
"org.a11y.atspi.Event.Terminal",
|
||||
"terminal:application-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Terminal',member='ApplicationChanged'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
CharWidthChangedEvent,
|
||||
"CharwidthChanged",
|
||||
"org.a11y.atspi.Event.Terminal",
|
||||
"terminal:char-width-changed",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Terminal',member='CharwidthChanged'"
|
||||
);
|
||||
|
||||
event_test_cases!(LineChangedEvent);
|
||||
impl_to_dbus_message!(LineChangedEvent);
|
||||
impl_from_dbus_message!(LineChangedEvent);
|
||||
impl_event_properties!(LineChangedEvent);
|
||||
impl_from_object_ref!(LineChangedEvent);
|
||||
|
||||
event_test_cases!(ColumnCountChangedEvent);
|
||||
impl_to_dbus_message!(ColumnCountChangedEvent);
|
||||
impl_from_dbus_message!(ColumnCountChangedEvent);
|
||||
impl_event_properties!(ColumnCountChangedEvent);
|
||||
impl_from_object_ref!(ColumnCountChangedEvent);
|
||||
|
||||
event_test_cases!(LineCountChangedEvent);
|
||||
impl_to_dbus_message!(LineCountChangedEvent);
|
||||
impl_from_dbus_message!(LineCountChangedEvent);
|
||||
impl_event_properties!(LineCountChangedEvent);
|
||||
impl_from_object_ref!(LineCountChangedEvent);
|
||||
|
||||
event_test_cases!(ApplicationChangedEvent);
|
||||
impl_to_dbus_message!(ApplicationChangedEvent);
|
||||
impl_from_dbus_message!(ApplicationChangedEvent);
|
||||
impl_event_properties!(ApplicationChangedEvent);
|
||||
impl_from_object_ref!(ApplicationChangedEvent);
|
||||
|
||||
event_test_cases!(CharWidthChangedEvent);
|
||||
impl_to_dbus_message!(CharWidthChangedEvent);
|
||||
impl_from_dbus_message!(CharWidthChangedEvent);
|
||||
impl_event_properties!(CharWidthChangedEvent);
|
||||
impl_from_object_ref!(CharWidthChangedEvent);
|
||||
|
||||
impl_msg_conversion_ext_for_target_type!(LineChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ColumnCountChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(LineCountChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ApplicationChangedEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(CharWidthChangedEvent);
|
||||
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(LineChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ColumnCountChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(LineCountChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ApplicationChangedEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(CharWidthChangedEvent);
|
||||
239
patches/atspi-common/src/events/traits.rs
vendored
Normal file
239
patches/atspi-common/src/events/traits.rs
vendored
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use crate::AtspiError;
|
||||
use crate::ObjectRef;
|
||||
#[cfg(feature = "zbus")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
use zbus::names::UniqueName;
|
||||
use zbus::wire::ObjectPath;
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::wire::Type;
|
||||
|
||||
/// Describes properties of a specific event _type_.
|
||||
///
|
||||
/// - `DBus` member name
|
||||
/// - `DBus` interface name
|
||||
///
|
||||
/// Together, the member and interface name can describe a specific event _type_.
|
||||
/// Likewise, the path and sender bus name collectively make up an [`ObjectRef`], which is a way to uniquely identify an individual accessible item available to `atspi`.
|
||||
/// The latter is available via the [`EventProperties`] trait.
|
||||
///
|
||||
/// This can also be generalized, for example this is implemented for [`crate::Event`] by dispatching to the matching variants.
|
||||
/// NOTE: to use `EventProperties` on wrapper types, like `Event`, you must enable the "enum-dispatch" feature.
|
||||
///
|
||||
/// This trait *is* object-safe.
|
||||
pub trait EventTypeProperties {
|
||||
fn member(&self) -> &'static str;
|
||||
fn interface(&self) -> &'static str;
|
||||
fn match_rule(&self) -> &'static str;
|
||||
fn registry_string(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// `EventProperties` allows access to the internals of an event, specifically:
|
||||
///
|
||||
/// - The `DBUs` name which sent the event.
|
||||
/// - The `ObjectPath`, a unique id for a given application.
|
||||
/// - Collectively, this is called an [`ObjectRef`].
|
||||
///
|
||||
/// This trait *is* object-safe.
|
||||
pub trait EventProperties {
|
||||
fn sender(&self) -> UniqueName<'_>;
|
||||
fn path(&self) -> ObjectPath<'_>;
|
||||
fn object_ref(&self) -> ObjectRef<'_> {
|
||||
ObjectRef::new(self.sender(), self.path())
|
||||
}
|
||||
}
|
||||
|
||||
assert_obj_safe!(EventTypeProperties);
|
||||
assert_obj_safe!(EventProperties);
|
||||
|
||||
/// A way to convert a [`zbus::Message`] without checking its interface.
|
||||
#[cfg(all(feature = "zbus", feature = "wrappers"))]
|
||||
pub(crate) trait EventWrapperMessageConversion {
|
||||
/// # Errors
|
||||
/// Will fail if no matching member or body signature is found.
|
||||
fn try_from_message_interface_checked(
|
||||
msg: &zbus::Message,
|
||||
hdr: &Header,
|
||||
) -> Result<Self, AtspiError>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
// TODO: Document why this can't be `TryFrom<&zbus::Message>`.
|
||||
#[cfg(all(feature = "zbus", feature = "wrappers"))]
|
||||
pub(crate) trait TryFromMessage {
|
||||
fn try_from_message(msg: &zbus::Message) -> Result<Self, AtspiError>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
/// The `DBus` member for the event.
|
||||
/// For example, for an [`crate::events::object::TextChangedEvent`] this should be `"TextChanged"`
|
||||
pub trait DBusMember {
|
||||
/// The event's `DBus` member.
|
||||
const DBUS_MEMBER: &'static str;
|
||||
}
|
||||
|
||||
/// The `DBus` interface name for an event - or a wrapper type.
|
||||
/// For example, for any event within the "Object" interface, this should be "org.a11y.atspi.Event.Object".
|
||||
pub trait DBusInterface {
|
||||
/// A static interface string for `DBus`.
|
||||
/// This should usually be a string that looks like this: `"org.a11y.atspi.Event.*"`;
|
||||
const DBUS_INTERFACE: &'static str;
|
||||
}
|
||||
|
||||
/// A static `DBus` match rule string.
|
||||
/// This should usually be a string that looks like this:
|
||||
/// `"type='signal',interface='org.a11y.atspi.Event.Object',member='PropertyChange'"`;
|
||||
// We cannot concat! consts, so we (at time of writing) need to have a separate trait for this.
|
||||
// Otherwise composing from `DBusMember` and `DBusInterface` would be preferred.
|
||||
pub trait DBusMatchRule {
|
||||
/// A static match rule string for `DBus`.
|
||||
const MATCH_RULE_STRING: &'static str;
|
||||
}
|
||||
|
||||
/// A static `Registry` event string for registering with the `RegistryProxy` for receiving events.
|
||||
pub trait RegistryEventString {
|
||||
/// A registry event string for registering for event receiving via the `RegistryProxy`.
|
||||
/// This should be deprecated in favour of composing the string from [`DBusMember::DBUS_MEMBER`] and [`DBusInterface::DBUS_INTERFACE`].
|
||||
const REGISTRY_EVENT_STRING: &'static str;
|
||||
}
|
||||
|
||||
/// A 'alias'-trait that combines all the `DBus` related traits.
|
||||
pub trait DBusProperties: DBusMember + DBusInterface + DBusMatchRule + RegistryEventString {}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
pub trait MessageConversionExt<'a, B>: 'a + MessageConversion<'a, Body<'a> = B>
|
||||
where
|
||||
B: Type + Serialize + Deserialize<'a>,
|
||||
{
|
||||
/// Convert a [`zbus::Message`] into this event type.
|
||||
/// Does all the validation for you.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The message does not have an interface: [`type@AtspiError::MissingInterface`]
|
||||
/// - The message interface does not match the one for the event: [`type@AtspiError::InterfaceMatch`]
|
||||
/// - The message does not have an member: [`type@AtspiError::MissingMember`]
|
||||
/// - The message member does not match the one for the event: [`type@AtspiError::MemberMatch`]
|
||||
/// - The message signature does not match the one for the event: [`type@AtspiError::SignatureMatch`]
|
||||
///
|
||||
/// See [`MessageConversion::from_message_unchecked`] for info on panic condition that should never
|
||||
/// happen.
|
||||
fn try_from_message(msg: &'a zbus::Message, hdr: &Header) -> Result<Self, AtspiError>
|
||||
where
|
||||
Self: Sized + 'a;
|
||||
|
||||
/// Validate the interface string via [`zbus::message::Header::interface`] against `Self`'s assignment of [`DBusInterface::DBUS_INTERFACE`]
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - [`type@AtspiError::MissingInterface`] if there is no interface
|
||||
/// - [`type@AtspiError::InterfaceMatch`] if the interfaces do not match
|
||||
fn validate_interface(header: &Header) -> Result<(), AtspiError> {
|
||||
let interface = header.interface().ok_or(AtspiError::MissingInterface)?;
|
||||
if interface != Self::DBUS_INTERFACE {
|
||||
return Err(AtspiError::InterfaceMatch(format!(
|
||||
"The interface {} does not match the signal's interface: {}",
|
||||
interface,
|
||||
Self::DBUS_INTERFACE,
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validate the member string via [`zbus::message::Header::member`] against `Self`'s assignment of [`DBusMember::DBUS_MEMBER`]
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - [`type@AtspiError::MissingMember`] if there is no member
|
||||
/// - [`type@AtspiError::MemberMatch`] if the members do not match
|
||||
fn validate_member(hdr: &Header) -> Result<(), AtspiError> {
|
||||
let member = hdr.member().ok_or(AtspiError::MissingMember)?;
|
||||
if member != Self::DBUS_MEMBER {
|
||||
return Err(AtspiError::MemberMatch(format!(
|
||||
"The member {} does not match the signal's member: {}",
|
||||
// unwrap is safe here because of guard above
|
||||
member,
|
||||
Self::DBUS_MEMBER,
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Validate the body signature against the [`zbus::wire::Signature`] of [`MessageConversion::Body`]
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - [`type@AtspiError::SignatureMatch`] if the signatures do not match
|
||||
fn validate_body(msg: &zbus::Message) -> Result<(), AtspiError> {
|
||||
let body = msg.body();
|
||||
let body_signature = body.signature();
|
||||
|
||||
let expected_signature = B::SIGNATURE;
|
||||
if body_signature != expected_signature {
|
||||
return Err(AtspiError::SignatureMatch(format!(
|
||||
"The message signature {} does not match the signal's body signature: {}",
|
||||
body_signature,
|
||||
&expected_signature.to_string(),
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
pub trait MessageConversion<'a>: DBusProperties {
|
||||
/// What is the body type of this event.
|
||||
type Body<'msg>: Type + Deserialize<'msg> + Serialize
|
||||
where
|
||||
Self: 'msg;
|
||||
|
||||
/// Build an event from a [`zbus::Message`] reference.
|
||||
/// This function will not check for any of the following error conditions:
|
||||
///
|
||||
/// - That the message has an interface: [`type@AtspiError::MissingInterface`]
|
||||
/// - That the message interface matches the one for the event: [`type@AtspiError::InterfaceMatch`]
|
||||
/// - That the message has an member: [`type@AtspiError::MissingMember`]
|
||||
/// - That the message member matches the one for the event: [`type@AtspiError::MemberMatch`]
|
||||
/// - That the message signature matches the one for the event: [`type@AtspiError::SignatureMatch`]
|
||||
///
|
||||
/// Therefore, this should only be used when one has checked the above conditions.
|
||||
/// These must be checked manually.
|
||||
/// Alternatively, there is the [`MessageConversionExt::try_from_message`] that will check these
|
||||
/// conditions for you.
|
||||
///
|
||||
/// This type also implements `TryFrom<&zbus::Message>`; consider using this if you are not an
|
||||
/// internal developer.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// It is possible to get a [`type@AtspiError::Zvariant`] error if you do not check the proper
|
||||
/// conditions before calling this.
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError>
|
||||
where
|
||||
Self: Sized + 'a;
|
||||
|
||||
/// Build an event from an [`ObjectRef`] and [`Self::Body`].
|
||||
/// This function will not check for any of the following error conditions:
|
||||
///
|
||||
/// - That the message has an interface: [`type@AtspiError::MissingInterface`]
|
||||
/// - That the message interface matches the one for the event: [`type@AtspiError::InterfaceMatch`]
|
||||
/// - That the message has an member: [`type@AtspiError::MissingMember`]
|
||||
/// - That the message member matches the one for the event: [`type@AtspiError::MemberMatch`]
|
||||
///
|
||||
/// Therefore, this should only be used when one has checked the above conditions.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Some [`Self::Body`] types may fallibly convert data fields contained in the body.
|
||||
/// If this happens, then the function will return an error.
|
||||
fn from_message_unchecked_parts(obj_ref: ObjectRef, body: DbusBody) -> Result<Self, AtspiError>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
/// The body of the object.
|
||||
fn body(&self) -> Self::Body<'_>;
|
||||
}
|
||||
504
patches/atspi-common/src/events/window.rs
vendored
Normal file
504
patches/atspi-common/src/events/window.rs
vendored
Normal file
|
|
@ -0,0 +1,504 @@
|
|||
#[cfg(feature = "zbus")]
|
||||
use crate::error::AtspiError;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::events::EventBody;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::events::MessageConversion;
|
||||
use crate::events::{
|
||||
DBusInterface, DBusMatchRule, DBusMember, EventBodyOwned, RegistryEventString,
|
||||
};
|
||||
use crate::object_ref::ObjectRefOwned;
|
||||
#[cfg(feature = "zbus")]
|
||||
use crate::{EventProperties, ObjectRef};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "zbus")]
|
||||
use zbus::message::{Body as DbusBody, Header};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct PropertyChangeEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
pub property: String,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(PropertyChangeEvent);
|
||||
|
||||
/// The window has been minimized.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct MinimizeEvent {
|
||||
/// The application which has been minimized.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(MinimizeEvent);
|
||||
|
||||
/// The window has been maximized.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct MaximizeEvent {
|
||||
/// The application which has been maximized.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(MaximizeEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct RestoreEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(RestoreEvent);
|
||||
|
||||
/// A window has been closed.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct CloseEvent {
|
||||
/// The application which has been closed.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(CloseEvent);
|
||||
|
||||
/// A new window has been created.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct CreateEvent {
|
||||
/// An application to query for additional events from.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(CreateEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct ReparentEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ReparentEvent);
|
||||
|
||||
/// A new virtual desktop has been created.
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub struct DesktopCreateEvent {
|
||||
/// A reference to a new desktop
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(DesktopCreateEvent);
|
||||
|
||||
/// A virtual desktop has been deleted.
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct DesktopDestroyEvent {
|
||||
/// A reference to the destroyed desktop.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(DesktopDestroyEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct DestroyEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
impl_event_type_properties_for_event!(DestroyEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct ActivateEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ActivateEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct DeactivateEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(DeactivateEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct RaiseEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(RaiseEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct LowerEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(LowerEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct MoveEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(MoveEvent);
|
||||
|
||||
/// A window has been resized.
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct ResizeEvent {
|
||||
/// The application which has been resized.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ResizeEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct ShadeEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(ShadeEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct UUshadeEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(UUshadeEvent);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Hash, Default)]
|
||||
pub struct RestyleEvent {
|
||||
/// The [`crate::ObjectRef`] which the event applies to.
|
||||
pub item: ObjectRefOwned,
|
||||
}
|
||||
|
||||
impl_event_type_properties_for_event!(RestyleEvent);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
PropertyChangeEvent,
|
||||
"PropertyChange",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:property-change",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='PropertyChange'"
|
||||
);
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl MessageConversion<'_> for PropertyChangeEvent {
|
||||
type Body<'a> = EventBody<'a>;
|
||||
|
||||
fn from_message_unchecked_parts(item: ObjectRef, body: DbusBody) -> Result<Self, AtspiError> {
|
||||
let mut body = body.deserialize_ignore_signature::<Self::Body<'_>>()?;
|
||||
Ok(Self { item: item.into(), property: body.take_kind() })
|
||||
}
|
||||
|
||||
fn from_message_unchecked(msg: &zbus::Message, header: &Header) -> Result<Self, AtspiError> {
|
||||
let item = header.try_into()?;
|
||||
let body = msg.body();
|
||||
Self::from_message_unchecked_parts(item, body)
|
||||
}
|
||||
|
||||
fn body(&self) -> Self::Body<'_> {
|
||||
EventBody::Owned(EventBodyOwned { kind: self.property.clone(), ..Default::default() })
|
||||
}
|
||||
}
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
MinimizeEvent,
|
||||
"Minimize",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:minimize",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Minimize'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
MaximizeEvent,
|
||||
"Maximize",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:maximize",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Maximize'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
RestoreEvent,
|
||||
"Restore",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:restore",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Restore'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
CloseEvent,
|
||||
"Close",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:close",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Close'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
CreateEvent,
|
||||
"Create",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:create",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Create'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ReparentEvent,
|
||||
"Reparent",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:reparent",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Reparent'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
DesktopCreateEvent,
|
||||
"DesktopCreate",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:desktop-create",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='DesktopCreate'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
DesktopDestroyEvent,
|
||||
"DesktopDestroy",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:desktop-destroy",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='DesktopDestroy'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
DestroyEvent,
|
||||
"Destroy",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:destroy",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Destroy'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ActivateEvent,
|
||||
"Activate",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:activate",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Activate'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
DeactivateEvent,
|
||||
"Deactivate",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:deactivate",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Deactivate'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
RaiseEvent,
|
||||
"Raise",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:raise",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Raise'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
LowerEvent,
|
||||
"Lower",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:lower",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Lower'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
MoveEvent,
|
||||
"Move",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:move",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Move'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ResizeEvent,
|
||||
"Resize",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:resize",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Resize'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
ShadeEvent,
|
||||
"Shade",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:shade",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Shade'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
UUshadeEvent,
|
||||
"uUshade",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:uushade",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='uUshade'"
|
||||
);
|
||||
|
||||
impl_member_interface_registry_string_and_match_rule_for_event!(
|
||||
RestyleEvent,
|
||||
"Restyle",
|
||||
"org.a11y.atspi.Event.Window",
|
||||
"window:restyle",
|
||||
"type='signal',interface='org.a11y.atspi.Event.Window',member='Restyle'"
|
||||
);
|
||||
|
||||
event_test_cases!(PropertyChangeEvent);
|
||||
impl_to_dbus_message!(PropertyChangeEvent);
|
||||
impl_from_dbus_message!(PropertyChangeEvent);
|
||||
impl_event_properties!(PropertyChangeEvent);
|
||||
impl From<PropertyChangeEvent> for EventBodyOwned {
|
||||
fn from(event: PropertyChangeEvent) -> Self {
|
||||
EventBodyOwned { kind: event.property, ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
event_test_cases!(MinimizeEvent);
|
||||
impl_to_dbus_message!(MinimizeEvent);
|
||||
impl_from_dbus_message!(MinimizeEvent);
|
||||
impl_event_properties!(MinimizeEvent);
|
||||
impl_from_object_ref!(MinimizeEvent);
|
||||
|
||||
event_test_cases!(MaximizeEvent);
|
||||
impl_to_dbus_message!(MaximizeEvent);
|
||||
impl_from_dbus_message!(MaximizeEvent);
|
||||
impl_event_properties!(MaximizeEvent);
|
||||
impl_from_object_ref!(MaximizeEvent);
|
||||
|
||||
event_test_cases!(RestoreEvent);
|
||||
impl_to_dbus_message!(RestoreEvent);
|
||||
impl_from_dbus_message!(RestoreEvent);
|
||||
impl_event_properties!(RestoreEvent);
|
||||
impl_from_object_ref!(RestoreEvent);
|
||||
|
||||
event_test_cases!(CloseEvent);
|
||||
impl_to_dbus_message!(CloseEvent);
|
||||
impl_from_dbus_message!(CloseEvent);
|
||||
impl_event_properties!(CloseEvent);
|
||||
impl_from_object_ref!(CloseEvent);
|
||||
|
||||
event_test_cases!(CreateEvent);
|
||||
impl_to_dbus_message!(CreateEvent);
|
||||
impl_from_dbus_message!(CreateEvent);
|
||||
impl_event_properties!(CreateEvent);
|
||||
impl_from_object_ref!(CreateEvent);
|
||||
|
||||
event_test_cases!(ReparentEvent);
|
||||
impl_to_dbus_message!(ReparentEvent);
|
||||
impl_from_dbus_message!(ReparentEvent);
|
||||
impl_event_properties!(ReparentEvent);
|
||||
impl_from_object_ref!(ReparentEvent);
|
||||
|
||||
event_test_cases!(DesktopCreateEvent);
|
||||
impl_to_dbus_message!(DesktopCreateEvent);
|
||||
impl_from_dbus_message!(DesktopCreateEvent);
|
||||
impl_event_properties!(DesktopCreateEvent);
|
||||
impl_from_object_ref!(DesktopCreateEvent);
|
||||
|
||||
event_test_cases!(DesktopDestroyEvent);
|
||||
impl_to_dbus_message!(DesktopDestroyEvent);
|
||||
impl_from_dbus_message!(DesktopDestroyEvent);
|
||||
impl_event_properties!(DesktopDestroyEvent);
|
||||
impl_from_object_ref!(DesktopDestroyEvent);
|
||||
|
||||
event_test_cases!(DestroyEvent);
|
||||
impl_to_dbus_message!(DestroyEvent);
|
||||
impl_from_dbus_message!(DestroyEvent);
|
||||
impl_event_properties!(DestroyEvent);
|
||||
impl_from_object_ref!(DestroyEvent);
|
||||
|
||||
event_test_cases!(ActivateEvent);
|
||||
impl_to_dbus_message!(ActivateEvent);
|
||||
impl_from_dbus_message!(ActivateEvent);
|
||||
impl_event_properties!(ActivateEvent);
|
||||
impl_from_object_ref!(ActivateEvent);
|
||||
|
||||
event_test_cases!(DeactivateEvent);
|
||||
impl_to_dbus_message!(DeactivateEvent);
|
||||
impl_from_dbus_message!(DeactivateEvent);
|
||||
impl_event_properties!(DeactivateEvent);
|
||||
impl_from_object_ref!(DeactivateEvent);
|
||||
|
||||
event_test_cases!(RaiseEvent);
|
||||
impl_to_dbus_message!(RaiseEvent);
|
||||
impl_from_dbus_message!(RaiseEvent);
|
||||
impl_event_properties!(RaiseEvent);
|
||||
impl_from_object_ref!(RaiseEvent);
|
||||
|
||||
event_test_cases!(LowerEvent);
|
||||
impl_to_dbus_message!(LowerEvent);
|
||||
impl_from_dbus_message!(LowerEvent);
|
||||
impl_event_properties!(LowerEvent);
|
||||
impl_from_object_ref!(LowerEvent);
|
||||
|
||||
event_test_cases!(MoveEvent);
|
||||
impl_to_dbus_message!(MoveEvent);
|
||||
impl_from_dbus_message!(MoveEvent);
|
||||
impl_event_properties!(MoveEvent);
|
||||
impl_from_object_ref!(MoveEvent);
|
||||
|
||||
event_test_cases!(ResizeEvent);
|
||||
impl_to_dbus_message!(ResizeEvent);
|
||||
impl_from_dbus_message!(ResizeEvent);
|
||||
impl_event_properties!(ResizeEvent);
|
||||
impl_from_object_ref!(ResizeEvent);
|
||||
|
||||
event_test_cases!(ShadeEvent);
|
||||
impl_to_dbus_message!(ShadeEvent);
|
||||
impl_from_dbus_message!(ShadeEvent);
|
||||
impl_event_properties!(ShadeEvent);
|
||||
impl_from_object_ref!(ShadeEvent);
|
||||
|
||||
event_test_cases!(UUshadeEvent);
|
||||
impl_to_dbus_message!(UUshadeEvent);
|
||||
impl_from_dbus_message!(UUshadeEvent);
|
||||
impl_event_properties!(UUshadeEvent);
|
||||
impl_from_object_ref!(UUshadeEvent);
|
||||
|
||||
event_test_cases!(RestyleEvent);
|
||||
impl_to_dbus_message!(RestyleEvent);
|
||||
impl_from_dbus_message!(RestyleEvent);
|
||||
impl_event_properties!(RestyleEvent);
|
||||
impl_from_object_ref!(RestyleEvent);
|
||||
|
||||
impl_msg_conversion_ext_for_target_type!(PropertyChangeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(MinimizeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(MaximizeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(RestoreEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(CloseEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(CreateEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ReparentEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(DesktopCreateEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(DesktopDestroyEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(DestroyEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ActivateEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(DeactivateEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(RaiseEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(LowerEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(MoveEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ResizeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(ShadeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(UUshadeEvent);
|
||||
impl_msg_conversion_ext_for_target_type!(RestyleEvent);
|
||||
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(MinimizeEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(MaximizeEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(RestoreEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(CloseEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(CreateEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ReparentEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(DesktopCreateEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(DesktopDestroyEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(DestroyEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ActivateEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(DeactivateEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(RaiseEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(LowerEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(MoveEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ResizeEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(ShadeEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(UUshadeEvent);
|
||||
impl_msg_conversion_for_types_built_from_object_ref!(RestyleEvent);
|
||||
308
patches/atspi-common/src/interface.rs
vendored
Normal file
308
patches/atspi-common/src/interface.rs
vendored
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
//! Conversion functions and types representing a set of [`Interface`]s.
|
||||
//!
|
||||
//! Each `AccessibleProxy` will implement some set of these interfaces,
|
||||
//! represented by a [`InterfaceSet`].
|
||||
|
||||
use enumflags2::{bitflags, BitFlag, BitFlags};
|
||||
use serde::{
|
||||
de::{self, Deserializer, Visitor},
|
||||
ser::{self, Serializer},
|
||||
Deserialize, Serialize,
|
||||
};
|
||||
use std::fmt;
|
||||
use zbus::wire::{Signature, Type};
|
||||
|
||||
/// AT-SPI interfaces an accessible object can implement.
|
||||
#[bitflags]
|
||||
#[repr(u32)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Interface {
|
||||
/// Interface to indicate implementation of `AccessibleProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Accessible")]
|
||||
Accessible,
|
||||
/// Interface to indicate implementation of `ActionProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Action")]
|
||||
Action,
|
||||
/// Interface to indicate implementation of `ApplicationProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Application")]
|
||||
Application,
|
||||
/// Interface to indicate implementation of `CacheProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Cache")]
|
||||
Cache,
|
||||
/// Interface to indicate implementation of `CollectionProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Collection")]
|
||||
Collection,
|
||||
/// Interface to indicate implementation of `ComponentProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Component")]
|
||||
Component,
|
||||
/// Interface to indicate implementation of `DocumentProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Document")]
|
||||
Document,
|
||||
/// Interface to indicate implementation of `DeviceEventControllerProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.DeviceEventController")]
|
||||
DeviceEventController,
|
||||
/// Interface to indicate implementation of `DeviceEventListenerProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.DeviceEventListener")]
|
||||
DeviceEventListener,
|
||||
/// Interface to indicate implementation of `EditableTextProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.EditableText")]
|
||||
EditableText,
|
||||
/// Interface to indicate implementation of `HyperlinkProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Hyperlink")]
|
||||
Hyperlink,
|
||||
/// Interface to indicate implementation of `HypertextProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Hypertext")]
|
||||
Hypertext,
|
||||
/// Interface to indicate implementation of `ImageProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Image")]
|
||||
Image,
|
||||
/// Interface to indicate implementation of `RegistryProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Registry")]
|
||||
Registry,
|
||||
/// Interface to indicate implementation of `SelectionProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Selection")]
|
||||
Selection,
|
||||
/// Interface to indicate implementation of `SocketProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Socket")]
|
||||
Socket,
|
||||
/// Interface to indicate implementation of `TableProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Table")]
|
||||
Table,
|
||||
/// Interface to indicate implementation of `TableCellProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.TableCell")]
|
||||
TableCell,
|
||||
/// Interface to indicate implementation of `TextProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Text")]
|
||||
Text,
|
||||
/// Interface to indicate implementation of `ValueProxy`.
|
||||
#[serde(rename = "org.a11y.atspi.Value")]
|
||||
Value,
|
||||
}
|
||||
|
||||
/// A collection type which encodes the AT-SPI interfaces an accessible object has implemented.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct InterfaceSet(BitFlags<Interface>);
|
||||
|
||||
impl InterfaceSet {
|
||||
pub fn new<B: Into<BitFlags<Interface>>>(value: B) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn empty() -> InterfaceSet {
|
||||
InterfaceSet(Interface::empty())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn bits(&self) -> u32 {
|
||||
self.0.bits()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn all() -> InterfaceSet {
|
||||
InterfaceSet(Interface::all())
|
||||
}
|
||||
|
||||
pub fn contains<B: Into<BitFlags<Interface>>>(self, other: B) -> bool {
|
||||
self.0.contains(other)
|
||||
}
|
||||
|
||||
pub fn insert<B: Into<BitFlags<Interface>>>(&mut self, other: B) {
|
||||
self.0.insert(other);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn iter(&self) -> enumflags2::Iter<Interface> {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for InterfaceSet {
|
||||
type IntoIter = enumflags2::Iter<Interface>;
|
||||
type Item = Interface;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for &InterfaceSet {
|
||||
type IntoIter = enumflags2::Iter<Interface>;
|
||||
type Item = Interface;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for InterfaceSet {
|
||||
fn default() -> Self {
|
||||
Self::empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> de::Deserialize<'de> for InterfaceSet {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct InterfaceSetVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for InterfaceSetVisitor {
|
||||
type Value = InterfaceSet;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a sequence comprised of valid AT-SPI interface names")
|
||||
}
|
||||
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
match <Vec<Interface> as Deserialize>::deserialize(deserializer) {
|
||||
Ok(interfaces) => Ok(InterfaceSet(BitFlags::from_iter(interfaces))),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_newtype_struct("InterfaceSet", InterfaceSetVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl ser::Serialize for InterfaceSet {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer
|
||||
.serialize_newtype_struct("InterfaceSet", &self.0.iter().collect::<Vec<Interface>>())
|
||||
}
|
||||
}
|
||||
|
||||
impl Type for InterfaceSet {
|
||||
const SIGNATURE: &'static Signature = <Vec<String> as Type>::SIGNATURE;
|
||||
}
|
||||
|
||||
impl FromIterator<Interface> for InterfaceSet {
|
||||
fn from_iter<T: IntoIterator<Item = Interface>>(iter: T) -> Self {
|
||||
Self(BitFlags::from_iter(iter))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromIterator<&'a Interface> for InterfaceSet {
|
||||
fn from_iter<I: IntoIterator<Item = &'a Interface>>(iter: I) -> Self {
|
||||
InterfaceSet(iter.into_iter().copied().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Interface> for InterfaceSet {
|
||||
fn from(value: Interface) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::BitAnd for InterfaceSet {
|
||||
type Output = InterfaceSet;
|
||||
|
||||
fn bitand(self, other: Self) -> Self::Output {
|
||||
InterfaceSet(self.0 & other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::BitXor for InterfaceSet {
|
||||
type Output = InterfaceSet;
|
||||
|
||||
fn bitxor(self, other: Self) -> Self::Output {
|
||||
InterfaceSet(self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::BitOr for InterfaceSet {
|
||||
type Output = InterfaceSet;
|
||||
|
||||
fn bitor(self, other: Self) -> Self::Output {
|
||||
InterfaceSet(self.0 | other.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Interface, InterfaceSet};
|
||||
use zbus::wire::serialized::Data;
|
||||
use zbus::wire::{serialized::Context, to_bytes, LE};
|
||||
|
||||
#[test]
|
||||
fn serialize_empty_interface_set() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &InterfaceSet::empty()).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_empty_interface_set() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &InterfaceSet::empty()).unwrap();
|
||||
let (decoded, _) = encoded.deserialize::<InterfaceSet>().unwrap();
|
||||
assert_eq!(decoded, InterfaceSet::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_interface_set_accessible() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &InterfaceSet::new(Interface::Accessible)).unwrap();
|
||||
assert_eq!(
|
||||
encoded.bytes(),
|
||||
&[
|
||||
30, 0, 0, 0, 25, 0, 0, 0, 111, 114, 103, 46, 97, 49, 49, 121, 46, 97, 116, 115,
|
||||
112, 105, 46, 65, 99, 99, 101, 115, 115, 105, 98, 108, 101, 0
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_interface_set_accessible() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(
|
||||
&[
|
||||
30, 0, 0, 0, 25, 0, 0, 0, 111, 114, 103, 46, 97, 49, 49, 121, 46, 97, 116, 115,
|
||||
112, 105, 46, 65, 99, 99, 101, 115, 115, 105, 98, 108, 101, 0,
|
||||
],
|
||||
ctxt,
|
||||
);
|
||||
|
||||
let (ifaceset, _) = data.deserialize::<InterfaceSet>().unwrap();
|
||||
assert_eq!(ifaceset, InterfaceSet::new(Interface::Accessible));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_handle_multiple_interfaces() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let object =
|
||||
InterfaceSet::new(Interface::Accessible | Interface::Action | Interface::Component);
|
||||
let encoded = to_bytes(ctxt, &object).unwrap();
|
||||
let (decoded, _) = encoded.deserialize::<InterfaceSet>().unwrap();
|
||||
assert!(object == decoded);
|
||||
}
|
||||
|
||||
// The order of appearance of the interfaces is equal to the order in the enum.
|
||||
#[test]
|
||||
fn iterator_on_interface_set() {
|
||||
let set =
|
||||
InterfaceSet::new(Interface::Accessible | Interface::Action | Interface::Component);
|
||||
let mut iter = set.into_iter();
|
||||
assert_eq!(iter.next(), Some(Interface::Accessible));
|
||||
assert_eq!(iter.next(), Some(Interface::Action));
|
||||
assert_eq!(iter.next(), Some(Interface::Component));
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iterator_on_interface_set_ref() {
|
||||
let set = InterfaceSet::new(Interface::Text | Interface::Collection | Interface::Component);
|
||||
let mut iter = (&set).into_iter();
|
||||
assert_eq!(iter.next(), Some(Interface::Collection));
|
||||
assert_eq!(iter.next(), Some(Interface::Component));
|
||||
assert_eq!(iter.next(), Some(Interface::Text));
|
||||
}
|
||||
}
|
||||
278
patches/atspi-common/src/lib.rs
vendored
Normal file
278
patches/atspi-common/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
#![deny(clippy::all, clippy::pedantic, clippy::cargo, unsafe_code, rustdoc::all)]
|
||||
#![allow(clippy::module_name_repetitions)]
|
||||
#![allow(clippy::multiple_crate_versions)]
|
||||
|
||||
//! # atspi-common
|
||||
//!
|
||||
//! Defines all common types, events, and data structures for `atspi-proxies` and `atspi-connection`.
|
||||
//! Since `atspi-proxies` and `atspi-connection` are downstream crates, the documentation can not link to it directly.
|
||||
//! Any type ending in `*Proxy` is in `atspi-proxies`.
|
||||
//!
|
||||
|
||||
#[macro_use]
|
||||
extern crate static_assertions;
|
||||
#[macro_use]
|
||||
pub(crate) mod macros;
|
||||
|
||||
pub mod action;
|
||||
#[cfg(feature = "wrappers")]
|
||||
pub use crate::events::event_wrappers::{
|
||||
CacheEvents, DocumentEvents, Event, EventListenerEvents, FocusEvents, KeyboardEvents,
|
||||
MouseEvents, ObjectEvents, TerminalEvents, WindowEvents,
|
||||
};
|
||||
pub use action::Action;
|
||||
pub mod object_match;
|
||||
pub use object_match::{MatchType, ObjectMatchRule, SortOrder, TreeTraversalType};
|
||||
pub mod object_ref;
|
||||
pub use object_ref::{ObjectRef, ObjectRefOwned};
|
||||
pub mod operation;
|
||||
pub use operation::Operation;
|
||||
pub mod interface;
|
||||
pub use interface::{Interface, InterfaceSet};
|
||||
pub mod state;
|
||||
pub use state::{State, StateSet};
|
||||
pub mod cache;
|
||||
pub use cache::{CacheItem, LegacyCacheItem};
|
||||
pub mod error;
|
||||
pub use error::AtspiError;
|
||||
pub mod events;
|
||||
pub use events::{EventProperties, EventTypeProperties};
|
||||
mod role;
|
||||
pub use role::Role;
|
||||
mod relation_type;
|
||||
pub use relation_type::RelationType;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zbus::wire::Type;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, AtspiError>;
|
||||
|
||||
/// Describes a selection of text, including selections across object boundaries.
|
||||
///
|
||||
/// For example, selecting from the beginning of a paragraph to half way through a link would cause
|
||||
/// the start and end object references to be different.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
pub struct TextSelection {
|
||||
/// starting object reference
|
||||
start_obj: ObjectRefOwned,
|
||||
/// text offset within `start_obj`
|
||||
start_idx: i32,
|
||||
/// ending object reference
|
||||
end_obj: ObjectRefOwned,
|
||||
/// text offset within `end_obj`
|
||||
end_idx: i32,
|
||||
/// is the `start_obj` active;
|
||||
///
|
||||
/// This is the same as querying for the [`StateSet`], then checking if [`State::Active`] is contained.
|
||||
/// See `atspi_proxies::accessible::AccessibleProxy` for more information on checking state.
|
||||
start_is_active: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[repr(u32)]
|
||||
/// The coordinate type encodes the frame of reference.
|
||||
pub enum CoordType {
|
||||
/// In relation to the entire screen.
|
||||
Screen,
|
||||
/// In relation to only the window.
|
||||
Window,
|
||||
/// In relation to the parent of the element being checked.
|
||||
Parent,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[repr(u32)]
|
||||
/// Enumeration used by `TextProxy` to indicate how to treat characters intersecting bounding boxes.
|
||||
pub enum ClipType {
|
||||
/// No characters/glyphs are omitted.
|
||||
Neither,
|
||||
/// Characters/glyphs clipped by the minimum coordinate are omitted.
|
||||
Min,
|
||||
/// Characters/glyphs which intersect the maximum coordinate are omitted.
|
||||
Max,
|
||||
/// Only glyphs falling entirely within the region bounded by min and max are retained.
|
||||
Both,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[repr(u32)]
|
||||
/// Level of granularity to get text of, in relation to a cursor position.
|
||||
pub enum Granularity {
|
||||
/// Gives the character at the index of the cursor. With a line-style cursor (which is standard) this will get the character that appears after the cursor.
|
||||
Char,
|
||||
/// Gives the entire word in front of, or which contains, the cursor. TODO: confirm that it always chooses the word in front of the cursor.
|
||||
Word,
|
||||
/// Gives entire sentence in front of, or which contains, the cursor. TODO: confirm that it always chooses the sentence after the cursor.
|
||||
Sentence,
|
||||
/// Gives the line, as seen visually of which the cursor is situated within.
|
||||
Line,
|
||||
/// Gives the entire block of text, regardless of where the cursor lies within it.
|
||||
Paragraph,
|
||||
}
|
||||
|
||||
/// Indicates relative stacking order of a `atspi_proxies::component::ComponentProxy` with respect to the
|
||||
/// onscreen visual representation of the UI.
|
||||
///
|
||||
/// The layer index, in combination with the component's extents,
|
||||
/// can be used to compute the visibility of all or part of a component.
|
||||
/// This is important in programmatic determination of region-of-interest for magnification,
|
||||
/// and in flat screen review models of the screen, as well as for other uses.
|
||||
/// Objects residing in two of the `Layer` categories support further z-ordering information,
|
||||
/// with respect to their peers in the same layer:
|
||||
/// namely, [`Layer::Window`] and [`Layer::Mdi`].
|
||||
/// Relative stacking order for other objects within the same layer is not available;
|
||||
/// the recommended heuristic is first child paints first. In other words,
|
||||
/// assume that the first siblings in the child list are subject to being
|
||||
/// overpainted by later siblings if their bounds intersect.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
pub enum Layer {
|
||||
/// Indicates an error condition or uninitialized value.
|
||||
Invalid,
|
||||
/// Reserved for the desktop background; this is the bottom-most layer,
|
||||
/// over which everything else is painted.
|
||||
Background,
|
||||
/// The 'background' layer for most content renderers and
|
||||
/// UI `atspi_proxies::component::ComponentProxy` containers.
|
||||
Canvas,
|
||||
/// The layer in which the majority of ordinary 'foreground' widgets reside.
|
||||
Widget,
|
||||
/// A special layer between [`Layer::Canvas`] and [`Layer::Widget`], in which the
|
||||
/// 'pseudo windows' (e.g. the Multiple-Document Interface frames) reside.
|
||||
///
|
||||
/// See `atspi_proxies::component::ComponentProxy::get_mdizorder`.
|
||||
Mdi,
|
||||
/// A layer for popup window content, above [`Layer::Widget`].
|
||||
Popup,
|
||||
/// The topmost layer.
|
||||
Overlay,
|
||||
/// The layer in which a toplevel window background usually resides.
|
||||
Window,
|
||||
}
|
||||
|
||||
/// Enumeration used by interface the [`crate::interface::Interface::Accessible`] to specify where an object should be placed on the screen when using `scroll_to`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
pub enum ScrollType {
|
||||
/// Scroll the object to the top left corner of the window.
|
||||
TopLeft,
|
||||
/// Scroll the object to the bottom right corner of the window.
|
||||
BottomRight,
|
||||
/// Scroll the object to the top edge of the window.
|
||||
TopEdge,
|
||||
/// Scroll the object to the bottom edge of the window.
|
||||
BottomEdge,
|
||||
/// Scroll the object to the left edge of the window.
|
||||
LeftEdge,
|
||||
/// Scroll the object to the right edge of the window.
|
||||
RightEdge,
|
||||
/// Scroll the object to application-dependent position on the window.
|
||||
Anywhere,
|
||||
}
|
||||
|
||||
/// Enumeration used to indicate a type of live region and how assertive it
|
||||
/// should be in terms of speaking notifications.
|
||||
///
|
||||
/// Currently, this is only used
|
||||
/// for `Announcement` events, but it may be used for additional purposes
|
||||
/// in the future.
|
||||
/// The argument in the `Announcement` event is named `politeness`.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
|
||||
#[repr(i32)]
|
||||
pub enum Politeness {
|
||||
/// No live region.
|
||||
#[default]
|
||||
None = 0,
|
||||
/// This live region should be considered polite.
|
||||
Polite = 1,
|
||||
/// This live region should be considered assertive.
|
||||
Assertive = 2,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for Politeness {
|
||||
type Error = AtspiError;
|
||||
|
||||
fn try_from(value: i32) -> std::result::Result<Self, Self::Error> {
|
||||
match value {
|
||||
0 => Ok(Politeness::None),
|
||||
1 => Ok(Politeness::Polite),
|
||||
2 => Ok(Politeness::Assertive),
|
||||
_ => Err(AtspiError::Conversion("Unknown Politeness variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::str::FromStr;
|
||||
use zbus_lockstep::{
|
||||
method_args_signature, method_return_signature, signal_body_type_signature,
|
||||
};
|
||||
use zbus::wire::Signature;
|
||||
|
||||
#[test]
|
||||
fn convert_i32_to_live() {
|
||||
assert_eq!(Politeness::None, Politeness::try_from(0).unwrap());
|
||||
assert_eq!(Politeness::Polite, Politeness::try_from(1).unwrap());
|
||||
assert_eq!(Politeness::Assertive, Politeness::try_from(2).unwrap());
|
||||
assert!(Politeness::try_from(3).is_err());
|
||||
assert!(Politeness::try_from(-1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_live_signature() {
|
||||
let signature = signal_body_type_signature!("Announcement");
|
||||
let politeness_signature_str = &signature.to_string_no_parens();
|
||||
let politeness_signature = Signature::from_str(&politeness_signature_str.as_str()[1..2])
|
||||
.expect("Valid signature pattern");
|
||||
assert_eq!(*<Politeness as Type>::SIGNATURE, politeness_signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_scroll_type_signature() {
|
||||
let signature = method_args_signature!(member: "ScrollTo", interface: "org.a11y.atspi.Component", argument: "type");
|
||||
assert_eq!(*<ScrollType as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_layer_signature() {
|
||||
let signature = method_return_signature!("GetLayer");
|
||||
assert_eq!(*<Layer as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_granularity_signature() {
|
||||
let signature = method_args_signature!(member: "GetStringAtOffset", interface: "org.a11y.atspi.Text", argument: "granularity");
|
||||
assert_eq!(*<Granularity as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_clip_type_signature() {
|
||||
let signature = method_args_signature!(member: "GetTextAtOffset", interface: "org.a11y.atspi.Text", argument: "type");
|
||||
assert_eq!(*<ClipType as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_coord_type_signature() {
|
||||
let signature = method_args_signature!(member: "GetImagePosition", interface: "org.a11y.atspi.Image", argument: "coordType");
|
||||
assert_eq!(*<CoordType as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_match_type_signature() {
|
||||
let rule_signature = method_args_signature!(member: "GetMatchesTo", interface: "org.a11y.atspi.Collection", argument: "rule");
|
||||
let match_type_signature_str = rule_signature.to_string();
|
||||
let match_type_signature = Signature::from_str(&match_type_signature_str.as_str()[3..4])
|
||||
.expect("Valid signature pattern");
|
||||
assert_eq!(*<MatchType as Type>::SIGNATURE, match_type_signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_text_selection_signature() {
|
||||
let selection_signature = method_args_signature!(member: "GetTextSelections", interface: "org.a11y.atspi.Document", argument: "selections");
|
||||
let selection_signature_str = selection_signature.to_string();
|
||||
let selection_signature = Signature::from_str(&selection_signature_str.as_str()[1..])
|
||||
.expect("Valid signature pattern");
|
||||
// this signature is written: `a(...)`, where `(...)` is the signature we want to compare against
|
||||
assert_eq!(*<TextSelection as Type>::SIGNATURE, selection_signature);
|
||||
}
|
||||
}
|
||||
1174
patches/atspi-common/src/macros.rs
vendored
Normal file
1174
patches/atspi-common/src/macros.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
304
patches/atspi-common/src/object_match.rs
vendored
Normal file
304
patches/atspi-common/src/object_match.rs
vendored
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
use std::{borrow::Borrow, collections::HashMap, marker::PhantomData};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zbus::wire::{Signature, Type};
|
||||
|
||||
use crate::{Interface, InterfaceSet, Role, State, StateSet};
|
||||
|
||||
/// Defines how an object-tree is to be traversed.
|
||||
/// Used in `CollectionProxy`.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[repr(u32)]
|
||||
pub enum TreeTraversalType {
|
||||
/// When traversing the tree, restrict to children of the current object.
|
||||
RestrictChildren,
|
||||
|
||||
/// When traversing the tree, restrict to siblings of the current object.
|
||||
RestrictSibling,
|
||||
|
||||
/// Traverse the tree in order of appearance.
|
||||
#[default]
|
||||
Inorder,
|
||||
}
|
||||
|
||||
/// Definition of match rules for accessible objects.
|
||||
/// Rule(s) against which we can match an object or a collection thereof.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// # use zbus::MatchRule;
|
||||
/// let builder = MatchRule::builder();
|
||||
/// ```
|
||||
///
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct ObjectMatchRule {
|
||||
pub states: StateSet,
|
||||
pub states_mt: MatchType,
|
||||
pub attr: HashMap<String, String>,
|
||||
pub attr_mt: MatchType,
|
||||
pub roles: Vec<Role>,
|
||||
pub roles_mt: MatchType,
|
||||
pub ifaces: InterfaceSet,
|
||||
pub ifaces_mt: MatchType,
|
||||
pub invert: bool,
|
||||
// Private phantom, gets compiled away.
|
||||
// Here to ensure the builder is the only route to obtain a `MatchRule`
|
||||
#[serde(skip)]
|
||||
_marker: std::marker::PhantomData<()>,
|
||||
}
|
||||
|
||||
/// !!! WARNING !!! :
|
||||
///
|
||||
/// State and Role are defined as u32 in Accessible.xml but as i32 in Collection.xml
|
||||
///
|
||||
/// The signature on `StateSet` is defined inconsistently in the XMLs:
|
||||
///
|
||||
/// - `Accessible.xml`: `GetState type="au"`
|
||||
/// - `Collection.xml`: `GetMatches` argument `name="rule" type="(aiia{ss}iaiiasib)"`
|
||||
///
|
||||
/// The latter starts with ai, which is a signature for an array of signed ints i32.
|
||||
///
|
||||
/// <https://gitlab.gnome.org/federico/at-spi2-core/-/commit/4885efedeef71e0df8210622771a0b1bb10e194d>
|
||||
impl Type for ObjectMatchRule {
|
||||
const SIGNATURE: &'static Signature = &Signature::static_structure(&[
|
||||
<Vec<i32>>::SIGNATURE,
|
||||
&Signature::I32,
|
||||
<HashMap<&str, &str>>::SIGNATURE,
|
||||
&Signature::I32,
|
||||
<Vec<i32>>::SIGNATURE,
|
||||
&Signature::I32,
|
||||
<Vec<&str>>::SIGNATURE,
|
||||
&Signature::I32,
|
||||
&Signature::Bool,
|
||||
]);
|
||||
}
|
||||
|
||||
impl ObjectMatchRule {
|
||||
/// Create a new `MatchRuleBuilder`
|
||||
#[must_use]
|
||||
pub fn builder() -> ObjectMatchRuleBuilder {
|
||||
ObjectMatchRuleBuilder::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// The 'builder' type for `MatchRule`.
|
||||
/// Use its methods to set match criteria.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ObjectMatchRuleBuilder {
|
||||
states: StateSet,
|
||||
states_mt: MatchType,
|
||||
attr: HashMap<String, String>,
|
||||
attr_mt: MatchType,
|
||||
roles: Vec<Role>,
|
||||
roles_mt: MatchType,
|
||||
ifaces: InterfaceSet,
|
||||
ifaces_mt: MatchType,
|
||||
invert: bool,
|
||||
}
|
||||
|
||||
impl ObjectMatchRuleBuilder {
|
||||
/// Insert a `StateSet` to the builder
|
||||
#[must_use]
|
||||
pub fn states<I>(mut self, states: I, mt: MatchType) -> Self
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::Item: Borrow<State>,
|
||||
{
|
||||
self.states = states.into_iter().map(|state| *state.borrow()).collect();
|
||||
self.states_mt = mt;
|
||||
self
|
||||
}
|
||||
|
||||
/// Insert a map of attributes
|
||||
#[must_use]
|
||||
pub fn attributes(mut self, attributes: HashMap<String, String>, mt: MatchType) -> Self {
|
||||
self.attr = attributes;
|
||||
self.attr_mt = mt;
|
||||
self
|
||||
}
|
||||
|
||||
/// Insert a slice of `Role`s
|
||||
#[must_use]
|
||||
pub fn roles(mut self, roles: &[Role], mt: MatchType) -> Self {
|
||||
self.roles = roles.into();
|
||||
self.roles_mt = mt;
|
||||
self
|
||||
}
|
||||
|
||||
/// Insert an `InterfaceSet` from a collection of `Interface`s
|
||||
#[must_use]
|
||||
pub fn interfaces<I>(mut self, interfaces: I, mt: MatchType) -> Self
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::Item: Borrow<Interface>,
|
||||
{
|
||||
self.ifaces = interfaces.into_iter().map(|iface| *iface.borrow()).collect();
|
||||
self.ifaces_mt = mt;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the inversion of the `MatchRule`, defaults to `false`, no inversion.
|
||||
#[must_use]
|
||||
pub fn invert(mut self, invert: bool) -> Self {
|
||||
self.invert = invert;
|
||||
self
|
||||
}
|
||||
|
||||
/// Builds the [`ObjectMatchRule`]
|
||||
///
|
||||
/// [`ObjectMatchRule``]: crate::object_match::ObjectMatchRule
|
||||
#[must_use]
|
||||
pub fn build(self) -> ObjectMatchRule {
|
||||
ObjectMatchRule {
|
||||
states: self.states,
|
||||
states_mt: self.states_mt,
|
||||
attr: self.attr,
|
||||
attr_mt: self.attr_mt,
|
||||
roles: self.roles,
|
||||
roles_mt: self.roles_mt,
|
||||
ifaces: self.ifaces,
|
||||
ifaces_mt: self.ifaces_mt,
|
||||
invert: self.invert,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enumeration used by [`ObjectMatchRule`] to specify how to interpret [`ObjectRef`] objects.
|
||||
///
|
||||
/// [`ObjectRef`]: crate::object_ref::ObjectRef
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Default)]
|
||||
#[repr(i32)]
|
||||
pub enum MatchType {
|
||||
#[default]
|
||||
/// Invalidates match criterion. Meanting: the search of this property will not be performed.
|
||||
Invalid,
|
||||
|
||||
/// All of the criteria must be met.
|
||||
All,
|
||||
|
||||
/// Any of the criteria must criteria must be met.
|
||||
Any,
|
||||
|
||||
/// None of the criteria must be met.
|
||||
NA,
|
||||
|
||||
/// Same as [`Self::All`] if the criterion item is non-empty - All of the criteria must be met.
|
||||
/// For empty criteria this rule requires the returned value to also have empty set.
|
||||
Empty,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[repr(u32)]
|
||||
/// Enumeration used by interface `CollectionProxy` to specify the way [`ObjectRef`]
|
||||
/// objects should be sorted.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Only `Canonical` and `ReverseCanonical` are currently implemented in the known implementation of `Collection`.
|
||||
///
|
||||
/// see: [issue 140. "Are all the AtspiCollectionSortOrder types really a thing?"](https://gitlab.gnome.org/GNOME/at-spi2-core/-/issues/140)
|
||||
///
|
||||
/// [`ObjectRef`]: crate::object_ref::ObjectRef
|
||||
pub enum SortOrder {
|
||||
/// Invalid sort order
|
||||
///
|
||||
/// Unimplemented
|
||||
Invalid,
|
||||
|
||||
/// Canonical sort order
|
||||
Canonical,
|
||||
|
||||
/// Flow sort order
|
||||
///
|
||||
/// Unimplemented
|
||||
Flow,
|
||||
|
||||
/// Tab sort order
|
||||
///
|
||||
/// Unimplemented
|
||||
Tab,
|
||||
|
||||
/// Reverse canonical sort order
|
||||
ReverseCanonical,
|
||||
|
||||
/// Reverse flow sort order
|
||||
///
|
||||
/// Unimplemented
|
||||
ReverseFlow,
|
||||
|
||||
/// Reverse tab sort order
|
||||
///
|
||||
/// Unimplemented
|
||||
ReverseTab,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{SortOrder, State};
|
||||
use std::str::FromStr;
|
||||
use zbus_lockstep::method_args_signature;
|
||||
|
||||
#[test]
|
||||
fn validate_match_rule_signature() {
|
||||
let signature = method_args_signature!(member: "GetMatchesTo", interface: "org.a11y.atspi.Collection", argument: "rule");
|
||||
assert_eq!(*<ObjectMatchRule as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_match_type_signature() {
|
||||
let rule_signature = method_args_signature!(member: "GetMatchesTo", interface: "org.a11y.atspi.Collection", argument: "rule");
|
||||
// The match type signature is the fourth element in the signature
|
||||
let match_type_signature_str = rule_signature.to_string();
|
||||
let match_type_signature = Signature::from_str(&match_type_signature_str.as_str()[3..4])
|
||||
.expect("Valid signature pattern");
|
||||
assert_eq!(*<MatchType as Type>::SIGNATURE, match_type_signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_tree_traversal_type_signature() {
|
||||
let signature = method_args_signature!(member: "GetMatchesTo", interface: "org.a11y.atspi.Collection", argument: "tree");
|
||||
assert_eq!(*<TreeTraversalType as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_sort_order_signature() {
|
||||
let signature = method_args_signature!(member: "GetMatches", interface: "org.a11y.atspi.Collection", argument: "sortby");
|
||||
assert_eq!(*<SortOrder as Type>::SIGNATURE, signature);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_empty_object_match_rule() {
|
||||
let rule = ObjectMatchRule::builder().build();
|
||||
|
||||
assert_eq!(rule.states, StateSet::default());
|
||||
assert_eq!(rule.attr, HashMap::new());
|
||||
assert_eq!(rule.roles, Vec::new());
|
||||
assert_eq!(rule.ifaces, InterfaceSet::default());
|
||||
assert!(!rule.invert);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_object_match_rule() {
|
||||
let rule = ObjectMatchRule::builder()
|
||||
.states(StateSet::new(State::Active), MatchType::All)
|
||||
.attributes(
|
||||
[("name".to_string(), "value".to_string())].iter().cloned().collect(),
|
||||
MatchType::Any,
|
||||
)
|
||||
.roles(&[Role::Alert], MatchType::All)
|
||||
.interfaces([Interface::Action], MatchType::Any)
|
||||
.invert(true)
|
||||
.build();
|
||||
|
||||
assert_eq!(rule.states, StateSet::new(State::Active));
|
||||
assert_eq!(
|
||||
rule.attr,
|
||||
[("name".to_string(), "value".to_string())].iter().cloned().collect()
|
||||
);
|
||||
assert_eq!(rule.roles, vec![Role::Alert]);
|
||||
assert_eq!(rule.ifaces, InterfaceSet::new(Interface::Action));
|
||||
assert!(rule.invert);
|
||||
}
|
||||
}
|
||||
871
patches/atspi-common/src/object_ref.rs
vendored
Normal file
871
patches/atspi-common/src/object_ref.rs
vendored
Normal file
|
|
@ -0,0 +1,871 @@
|
|||
use crate::AtspiError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use zbus_lockstep_macros::validate;
|
||||
use zbus::names::{BusName, UniqueName};
|
||||
use zbus::wire::{ObjectPath, Structure, Type};
|
||||
|
||||
const NULL_PATH_STR: &str = "/org/a11y/atspi/null";
|
||||
const NULL_OBJECT_PATH: &ObjectPath<'static> =
|
||||
&ObjectPath::from_static_str_unchecked(NULL_PATH_STR);
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_OBJECT_BUS_NAME: &str = ":0.0";
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_OBJECT_PATH_STR: &str = "/org/a11y/atspi/test/default";
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_DEFAULT_OBJECT_REF: ObjectRef<'static> =
|
||||
ObjectRef::from_static_str_unchecked(TEST_OBJECT_BUS_NAME, TEST_OBJECT_PATH_STR);
|
||||
|
||||
/// A unique identifier for an object in the accessibility tree.
|
||||
///
|
||||
/// A ubiquitous type used to refer to an object in the accessibility tree.
|
||||
///
|
||||
/// In AT-SPI2, objects in the applications' UI object tree are uniquely identified
|
||||
/// using an application's bus name and object path. "(so)"
|
||||
///
|
||||
/// Emitted by `RemoveAccessible` and `Available`
|
||||
#[validate(signal: "Available")]
|
||||
#[derive(Clone, Debug, Eq, Type)]
|
||||
#[zvariant(signature = "(so)")]
|
||||
pub enum ObjectRef<'o> {
|
||||
Null,
|
||||
Owned { name: UniqueName<'static>, path: ObjectPath<'static> },
|
||||
Borrowed { name: UniqueName<'o>, path: ObjectPath<'o> },
|
||||
}
|
||||
|
||||
impl<'o> ObjectRef<'o> {
|
||||
/// Create a new `ObjectRef::Borrowed` from a `UniqueName` and `ObjectPath`.
|
||||
#[must_use]
|
||||
pub fn new(name: UniqueName<'o>, path: ObjectPath<'o>) -> Self {
|
||||
Self::new_borrowed(name, path)
|
||||
}
|
||||
|
||||
/// Create a new, owned `ObjectRef`.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
///
|
||||
/// let object_ref = ObjectRef::new_owned(name, path);
|
||||
/// # assert_eq!(object_ref.name_as_str(), Some(":1.23"));
|
||||
/// # assert_eq!(object_ref.path_as_str(), "/org/a11y/example/path/007");
|
||||
/// ```
|
||||
pub fn new_owned<N, P>(name: N, path: P) -> ObjectRefOwned
|
||||
where
|
||||
N: Into<UniqueName<'static>>,
|
||||
P: Into<ObjectPath<'static>>,
|
||||
{
|
||||
let name: UniqueName<'static> = name.into();
|
||||
let path: ObjectPath<'static> = path.into();
|
||||
|
||||
ObjectRefOwned(ObjectRef::Owned { name, path })
|
||||
}
|
||||
|
||||
/// Create a new, borrowed `ObjectRef`.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
///
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
/// # assert_eq!(object_ref.name_as_str(), Some(":1.23"));
|
||||
/// # assert_eq!(object_ref.path_as_str(), "/org/a11y/example/path/007");
|
||||
/// ```
|
||||
pub fn new_borrowed<N, P>(name: N, path: P) -> ObjectRef<'o>
|
||||
where
|
||||
N: Into<UniqueName<'o>>,
|
||||
P: Into<ObjectPath<'o>>,
|
||||
{
|
||||
let name: UniqueName<'o> = name.into();
|
||||
let path: ObjectPath<'o> = path.into();
|
||||
|
||||
ObjectRef::Borrowed { name, path }
|
||||
}
|
||||
|
||||
/// Create a new `ObjectRef`, from `BusName` and `ObjectPath`.
|
||||
///
|
||||
/// # Errors
|
||||
/// Will fail if the `sender` is not a `UniqueName`.
|
||||
pub fn try_from_bus_name_and_path(
|
||||
sender: BusName<'o>,
|
||||
path: ObjectPath<'o>,
|
||||
) -> Result<Self, AtspiError> {
|
||||
// Check whether `BusName` matches `UniqueName`
|
||||
if let BusName::Unique(unique_sender) = sender {
|
||||
Ok(ObjectRef::new(unique_sender, path))
|
||||
} else {
|
||||
Err(AtspiError::ParseError("Expected UniqueName"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new `ObjectRef`, unchecked.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the strings are valid.
|
||||
#[must_use]
|
||||
pub const fn from_static_str_unchecked(name: &'static str, path: &'static str) -> Self {
|
||||
let name = UniqueName::from_static_str_unchecked(name);
|
||||
let path = ObjectPath::from_static_str_unchecked(path);
|
||||
|
||||
ObjectRef::Owned { name, path }
|
||||
}
|
||||
|
||||
/// Returns `true` if the object reference is `Null`, otherwise returns `false`.
|
||||
///
|
||||
/// Toolkits may use the `Null` object reference to indicate that an object is not available or does not exist.
|
||||
/// For example, when calling `Accessible::get_parent` on an object that has no parent,
|
||||
/// it may return a `Null` object reference.
|
||||
#[must_use]
|
||||
pub fn is_null(&self) -> bool {
|
||||
matches!(self, Self::Null)
|
||||
}
|
||||
|
||||
/// Returns the name of the object reference.
|
||||
/// If the object reference is `Null`, it returns `None`.
|
||||
/// If the object reference is `Owned` or `Borrowed`, it returns the name.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
///
|
||||
/// // Check the name of the object reference
|
||||
/// assert!(object_ref.name().is_some());
|
||||
/// assert_eq!(object_ref.name().unwrap().as_str(), ":1.23");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn name(&self) -> Option<&UniqueName<'o>> {
|
||||
match self {
|
||||
Self::Owned { name: own_name, .. } => Some(own_name),
|
||||
Self::Borrowed { name: borrow_name, .. } => Some(borrow_name),
|
||||
Self::Null => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path of the object reference.\
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
///
|
||||
/// // Check the path of the object reference
|
||||
/// assert_eq!(object_ref.path().as_str(), "/org/a11y/example/path/007");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn path(&self) -> &ObjectPath<'o> {
|
||||
match self {
|
||||
Self::Owned { path: own_path, .. } => own_path,
|
||||
Self::Borrowed { path: borrow_path, .. } => borrow_path,
|
||||
Self::Null => NULL_OBJECT_PATH,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts the `ObjectRef` into an owned instance, consuming `self`.\
|
||||
/// If the object reference is `Null`, it returns `ObjectRef::Null`.\
|
||||
/// If the object reference is `Owned`, it returns the same `ObjectRef::Owned`.\
|
||||
/// If the object reference is `Borrowed`, it converts the name and path to owned versions and returns `ObjectRef::Owned`.
|
||||
///
|
||||
/// # Extending lifetime 'magic' (from 'o -> 'static')
|
||||
///
|
||||
/// `ObjectRef<'_>` leans on the implementation of `UniqueName` and `ObjectPath` to
|
||||
/// convert the inner types to `'static`.
|
||||
/// These types have an `Inner` enum that can contain an `Owned`, `Borrowed`, or `Static` `Str` type.
|
||||
/// The `Str`type is either a `&'static str` (static), `&str` (borrowed), or an `Arc<str>` (owned).
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
///
|
||||
/// // Check whether the object reference can be converted to an owned version
|
||||
/// assert!(!object_ref.is_null());
|
||||
/// let object_ref = object_ref.into_owned();
|
||||
/// assert!(matches!(object_ref, ObjectRef::Owned { .. }));
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn into_owned(self) -> ObjectRef<'static> {
|
||||
match self {
|
||||
Self::Null => ObjectRef::Null,
|
||||
Self::Owned { name, path } => ObjectRef::Owned { name, path },
|
||||
Self::Borrowed { name, path } => {
|
||||
ObjectRef::Owned { name: name.to_owned(), path: path.to_owned() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the name of the object reference as a string slice.
|
||||
#[must_use]
|
||||
pub fn name_as_str(&self) -> Option<&str> {
|
||||
match self {
|
||||
ObjectRef::Null => None,
|
||||
ObjectRef::Owned { name, .. } | ObjectRef::Borrowed { name, .. } => Some(name.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path of the object reference as a string slice.
|
||||
#[must_use]
|
||||
pub fn path_as_str(&self) -> &str {
|
||||
match self {
|
||||
ObjectRef::Null => NULL_PATH_STR,
|
||||
ObjectRef::Owned { path, .. } | ObjectRef::Borrowed { path, .. } => path.as_str(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Event tests lean on the `Default` implementation of `ObjectRef`.
|
||||
// This is a workaround for the fact that `ObjectRef::Null` in
|
||||
// `#[cfg(test)]` context is inconvenient.
|
||||
// Events are guaranteed to have a non-null `ObjectRef` on their `item` field, because we receive signals over
|
||||
// regular (non-p2p) DBus. Which means the `Message` `Header` has valid `Sender` and `Path` fields which
|
||||
// are used to construct the `ObjectRef` from a `Message`.
|
||||
#[cfg(test)]
|
||||
impl Default for ObjectRef<'_> {
|
||||
/// Returns a non-Null object reference. (test implementation)
|
||||
fn default() -> Self {
|
||||
TEST_DEFAULT_OBJECT_REF
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Default for ObjectRef<'_> {
|
||||
/// Returns a `Null` object reference.
|
||||
fn default() -> Self {
|
||||
ObjectRef::Null
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper around the static variant of `ObjectRef`.
|
||||
/// This is guaranteed to have a `'static` lifetime.
|
||||
#[validate(signal: "Available")]
|
||||
#[derive(Clone, Debug, Default, Eq, Type)]
|
||||
pub struct ObjectRefOwned(pub(crate) ObjectRef<'static>);
|
||||
|
||||
impl From<ObjectRef<'_>> for ObjectRefOwned {
|
||||
/// Convert an `ObjectRef<'_>` into an `ObjectRefOwned`.
|
||||
///
|
||||
/// # Extending lifetime 'magic' (from 'o -> 'static')
|
||||
///
|
||||
/// `ObjectRef<'_>` leans on the implementation of `UniqueName` and `ObjectPath` to
|
||||
/// convert the inner types to `'static`.
|
||||
/// These types have an `Inner` enum that can contain an `Owned`, `Borrowed`, or `Static` `Str` type.
|
||||
/// The `Str`type is either a `&'static str` (static), `&str` (borrowed), or an `Arc<str>` (owned).
|
||||
fn from(object_ref: ObjectRef<'_>) -> Self {
|
||||
ObjectRefOwned(object_ref.into_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRefOwned {
|
||||
/// Create a new `ObjectRefOwned` from an `ObjectRef<'static>`.
|
||||
#[must_use]
|
||||
pub const fn new(object_ref: ObjectRef<'static>) -> Self {
|
||||
Self(object_ref)
|
||||
}
|
||||
|
||||
/// Create a new `ObjectRefOwned` from `&'static str` unchecked.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the strings are valid.
|
||||
#[must_use]
|
||||
pub const fn from_static_str_unchecked(name: &'static str, path: &'static str) -> Self {
|
||||
let name = UniqueName::from_static_str_unchecked(name);
|
||||
let path = ObjectPath::from_static_str_unchecked(path);
|
||||
|
||||
ObjectRefOwned(ObjectRef::Owned { name, path })
|
||||
}
|
||||
|
||||
/// Returns `true` if the object reference is `Null`, otherwise returns `false`.
|
||||
#[must_use]
|
||||
pub fn is_null(&self) -> bool {
|
||||
matches!(self.0, ObjectRef::Null)
|
||||
}
|
||||
|
||||
/// Returns the inner `ObjectRef`, consuming `self`.
|
||||
#[must_use]
|
||||
pub fn into_inner(self) -> ObjectRef<'static> {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Returns the name of the object reference.
|
||||
/// If the object reference is `Null`, it returns `None`.
|
||||
/// If the object reference is `Owned` or `Borrowed`, it returns the name.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
///
|
||||
/// // Check the name of the object reference
|
||||
/// assert!(object_ref.name().is_some());
|
||||
/// assert_eq!(object_ref.name_as_str().unwrap(), ":1.23");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn name(&self) -> Option<&UniqueName<'static>> {
|
||||
match &self.0 {
|
||||
ObjectRef::Owned { name, .. } | ObjectRef::Borrowed { name, .. } => Some(name),
|
||||
ObjectRef::Null => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path of the object reference.\
|
||||
/// If the object reference is `Null`, it returns the null-path.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use zbus::names::UniqueName;
|
||||
/// use zbus::wire::ObjectPath;
|
||||
/// use atspi_common::ObjectRef;
|
||||
///
|
||||
/// let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
/// let path = ObjectPath::from_static_str_unchecked("/org/a11y/example/path/007");
|
||||
/// let object_ref = ObjectRef::new_borrowed(name, path);
|
||||
///
|
||||
/// assert_eq!(object_ref.path_as_str(), "/org/a11y/example/path/007");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn path(&self) -> &ObjectPath<'static> {
|
||||
match &self.0 {
|
||||
ObjectRef::Owned { path, .. } | ObjectRef::Borrowed { path, .. } => path,
|
||||
ObjectRef::Null => NULL_OBJECT_PATH,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the name of the object reference as a string slice.
|
||||
#[must_use]
|
||||
pub fn name_as_str(&self) -> Option<&str> {
|
||||
match &self.0 {
|
||||
ObjectRef::Null => None,
|
||||
ObjectRef::Owned { name, .. } | ObjectRef::Borrowed { name, .. } => Some(name.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path of the object reference as a string slice.
|
||||
#[must_use]
|
||||
pub fn path_as_str(&self) -> &str {
|
||||
match &self.0 {
|
||||
ObjectRef::Null => NULL_PATH_STR,
|
||||
ObjectRef::Owned { path, .. } | ObjectRef::Borrowed { path, .. } => path.as_str(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ObjectRef<'_> {
|
||||
/// `ObjectRef`'s wire format is `(&str, ObjectPath)`.
|
||||
/// The `Null` variant, the "Null object", is serialized as `("", ObjectPath("/org/a11y/atspi/null"))`.
|
||||
/// Both `Owned` and `Borrowed` variants are serialized as `(&str, ObjectPath)` with the object's\
|
||||
/// unique name and path.
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match &self {
|
||||
ObjectRef::Null => ("", NULL_OBJECT_PATH).serialize(serializer),
|
||||
ObjectRef::Owned { name, path } | ObjectRef::Borrowed { name, path } => {
|
||||
(name.as_str(), path).serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for ObjectRefOwned {
|
||||
/// `ObjectRefOwned` is serialized as the inner `ObjectRef`.
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de: 'o, 'o> Deserialize<'de> for ObjectRef<'o> {
|
||||
/// `ObjectRef`'s wire format is `(&str, ObjectPath)`.
|
||||
/// An empty `&str` with a "/org/a11y/atspi/null" path is considered a `Null` object,
|
||||
/// this is deserialized as `ObjectRef::Null`.\
|
||||
/// Any other valid `(&str, ObjectPath)` will deserialize into `ObjectRef::Borrowed`.
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
struct ObjectRefVisitor;
|
||||
|
||||
impl<'de> serde::de::Visitor<'de> for ObjectRefVisitor {
|
||||
type Value = ObjectRef<'de>;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
formatter.write_str("a tuple of (&str, ObjectPath)")
|
||||
}
|
||||
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let name: &str = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(0, &self))?;
|
||||
let path: ObjectPath<'de> = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(1, &self))?;
|
||||
|
||||
if path == *NULL_OBJECT_PATH {
|
||||
Ok(ObjectRef::Null)
|
||||
} else {
|
||||
assert!(
|
||||
!name.is_empty(),
|
||||
"A non-null ObjectRef requires a name and a path but got: (\"\", {path})"
|
||||
);
|
||||
Ok(ObjectRef::Borrowed {
|
||||
name: UniqueName::try_from(name).map_err(serde::de::Error::custom)?,
|
||||
path,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_tuple(2, ObjectRefVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ObjectRefOwned {
|
||||
/// `ObjectRefOwned` is deserialized as "Owned" variant `ObjectRef<'static>`.
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let object_ref: ObjectRef<'_> = Deserialize::deserialize(deserializer)?;
|
||||
Ok(object_ref.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ObjectRef<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
// Match order is relevant here. Null == Null, but Null != any other object.
|
||||
(ObjectRef::Null, ObjectRef::Null) => true,
|
||||
(ObjectRef::Null, _) | (_, ObjectRef::Null) => false,
|
||||
_ => self.name() == other.name() && self.path() == other.path(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `Hash` requires that hashes are equal if values are equal.
|
||||
// If a == b, then a.hash() == b.hash() must hold true.
|
||||
//
|
||||
// Because PartialEq treats Owned and Borrowed variants with identical (name, path) as equal,
|
||||
// we must implement Hash manually to ignore the variant discriminant and preserve hash/equality
|
||||
// consistency.
|
||||
impl Hash for ObjectRef<'_> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
match self {
|
||||
ObjectRef::Null => {
|
||||
// Hashing a Null object reference.
|
||||
"Null".hash(state);
|
||||
}
|
||||
ObjectRef::Owned { name, path } | ObjectRef::Borrowed { name, path } => {
|
||||
name.as_str().hash(state);
|
||||
path.as_str().hash(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for ObjectRefOwned {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ObjectRefOwned {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<ObjectRef<'_>> for ObjectRefOwned {
|
||||
fn eq(&self, other: &ObjectRef<'_>) -> bool {
|
||||
self.0 == *other
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<ObjectRefOwned> for ObjectRef<'_> {
|
||||
fn eq(&self, other: &ObjectRefOwned) -> bool {
|
||||
*self == other.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl<'m: 'o, 'o> TryFrom<&'m zbus::message::Header<'_>> for ObjectRef<'o> {
|
||||
type Error = crate::AtspiError;
|
||||
|
||||
// Construct an ObjectRef<'o> by reborrowing from the Header’s data.
|
||||
// 'm: 'o, 'm outlives 'o, so the references returned by this function
|
||||
// are guaranteed to be valid for the lifetime of the header.
|
||||
|
||||
/// Construct an `ObjectRef` from a `zbus::message::Header`.
|
||||
///
|
||||
/// # Header fields
|
||||
///
|
||||
/// `Path` is a mandatory field on method calls and signals,
|
||||
/// `Sender` is an optional field, see:
|
||||
/// [DBus specification - header fields](<https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-header-fields>)).,
|
||||
///
|
||||
/// ```quote
|
||||
/// On a message bus, this header field is controlled by the message bus,
|
||||
/// so it is as reliable and trustworthy as the message bus itself.
|
||||
/// Otherwise, (eg. P2P) this header field is controlled by the message sender,
|
||||
/// unless there is out-of-band information that indicates otherwise.
|
||||
/// ```
|
||||
///
|
||||
/// While unlikely, it is possible that `Sender` or `Path` are not set on the header.
|
||||
/// This could happen if the server implementation does not set these fields for any reason.
|
||||
///
|
||||
/// # Errors
|
||||
/// Will return an `AtspiError::ParseError` if the header does not contain a valid path or sender.
|
||||
fn try_from(header: &'m zbus::message::Header) -> Result<Self, Self::Error> {
|
||||
let path = header.path().ok_or(crate::AtspiError::MissingPath)?;
|
||||
let name = header.sender().ok_or(crate::AtspiError::MissingName)?;
|
||||
|
||||
Ok(ObjectRef::Borrowed { name: name.clone(), path: path.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "zbus")]
|
||||
impl<'m> TryFrom<&'m zbus::message::Header<'_>> for ObjectRefOwned {
|
||||
type Error = crate::AtspiError;
|
||||
|
||||
/// Construct an `ObjectRefOwned` from a `zbus::message::Header`.
|
||||
fn try_from(header: &'m zbus::message::Header) -> Result<Self, Self::Error> {
|
||||
let path = header.path().ok_or(crate::AtspiError::MissingPath)?;
|
||||
let name = header.sender().ok_or(crate::AtspiError::MissingName)?;
|
||||
|
||||
let object_ref =
|
||||
ObjectRef::Owned { name: name.clone().into_owned(), path: path.clone().into_owned() };
|
||||
Ok(ObjectRefOwned(object_ref))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'v> TryFrom<zbus::wire::Variant<'v>> for ObjectRef<'v> {
|
||||
type Error = zbus::wire::Error;
|
||||
|
||||
fn try_from(value: zbus::wire::Variant<'v>) -> Result<Self, Self::Error> {
|
||||
// Relies on the generic `Value` to tuple conversion `(UniqueName, ObjectPath)`.
|
||||
let (name, path): (UniqueName, ObjectPath) = value.try_into()?;
|
||||
Ok(ObjectRef::new_borrowed(name, path))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'v> TryFrom<zbus::wire::Variant<'v>> for ObjectRefOwned {
|
||||
type Error = zbus::wire::Error;
|
||||
|
||||
fn try_from(value: zbus::wire::Variant<'v>) -> Result<Self, Self::Error> {
|
||||
// Relies on the generic `Value` to tuple conversion `(UniqueName, ObjectPath)`.
|
||||
let (name, path): (UniqueName, ObjectPath) = value.try_into()?;
|
||||
Ok(ObjectRef::new_borrowed(name, path).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<zbus::wire::OwnedVariant> for ObjectRef<'static> {
|
||||
type Error = zbus::wire::Error;
|
||||
fn try_from(value: zbus::wire::OwnedVariant) -> Result<Self, Self::Error> {
|
||||
let (name, path): (UniqueName<'static>, ObjectPath<'static>) = value.try_into()?;
|
||||
Ok(ObjectRef::Owned { name, path })
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<zbus::wire::OwnedVariant> for ObjectRefOwned {
|
||||
type Error = zbus::wire::Error;
|
||||
fn try_from(value: zbus::wire::OwnedVariant) -> Result<Self, Self::Error> {
|
||||
let (name, path): (UniqueName<'static>, ObjectPath<'static>) = value.try_into()?;
|
||||
let obj = ObjectRef::Owned { name, path };
|
||||
Ok(ObjectRefOwned(obj))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'reference: 'structure, 'object: 'structure, 'structure> From<&'reference ObjectRef<'object>>
|
||||
for zbus::wire::Structure<'structure>
|
||||
{
|
||||
fn from(obj: &'reference ObjectRef<'object>) -> Self {
|
||||
match obj {
|
||||
ObjectRef::Null => ("", NULL_OBJECT_PATH).into(),
|
||||
ObjectRef::Borrowed { name, path } => Structure::from((name.clone(), path)),
|
||||
ObjectRef::Owned { name, path } => Structure::from((name.as_str(), path.as_ref())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'o> From<ObjectRef<'o>> for zbus::wire::Structure<'o> {
|
||||
fn from(obj: ObjectRef<'o>) -> Self {
|
||||
match obj {
|
||||
ObjectRef::Null => Structure::from(("", NULL_OBJECT_PATH)),
|
||||
ObjectRef::Borrowed { name, path } | ObjectRef::Owned { name, path } => {
|
||||
Structure::from((name, path))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectRefOwned> for zbus::wire::Structure<'_> {
|
||||
fn from(obj: ObjectRefOwned) -> Self {
|
||||
let object_ref = obj.into_inner();
|
||||
object_ref.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
use super::ObjectRef;
|
||||
use crate::object_ref::{NULL_OBJECT_PATH, NULL_PATH_STR};
|
||||
use zbus::{names::UniqueName, wire::ObjectPath};
|
||||
use zbus::wire::{serialized::Context, to_bytes, OwnedVariant as OwnedValue, Variant as Value, LE};
|
||||
|
||||
const TEST_OBJECT_PATH: &str = "/org/a11y/atspi/path/007";
|
||||
|
||||
#[test]
|
||||
fn owned_object_ref_creation() {
|
||||
let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
let path = ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH);
|
||||
|
||||
let object_ref = ObjectRef::new_owned(name, path);
|
||||
|
||||
assert_eq!(object_ref.name_as_str(), Some(":1.23"));
|
||||
assert_eq!(object_ref.path_as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn borrowed_object_ref_creation() {
|
||||
let object_ref = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
assert_eq!(object_ref.name_as_str(), Some(":1.23"));
|
||||
assert_eq!(object_ref.path_as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn null_object_ref() {
|
||||
let null_object_ref: ObjectRef = ObjectRef::Null;
|
||||
assert!(null_object_ref.is_null());
|
||||
assert!(null_object_ref.name().is_none());
|
||||
assert_eq!(null_object_ref.path(), NULL_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_ref_into_owned() {
|
||||
let borrowed_object_ref = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
let owned_object_ref = borrowed_object_ref.into_owned();
|
||||
assert!(matches!(owned_object_ref, ObjectRef::Owned { .. }));
|
||||
assert_eq!(owned_object_ref.name_as_str(), Some(":1.23"));
|
||||
assert_eq!(owned_object_ref.path_as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_ref_into_name_and_path() {
|
||||
let object_ref = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
let name = object_ref.name().unwrap();
|
||||
let path = object_ref.path();
|
||||
assert_eq!(name.as_str(), ":1.23");
|
||||
assert_eq!(path.as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialization_null_object_ref() {
|
||||
let null_object_ref: ObjectRef = ObjectRef::Null;
|
||||
assert!(null_object_ref.is_null());
|
||||
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &null_object_ref).unwrap();
|
||||
|
||||
let (obj, _) = encoded.deserialize::<ObjectRef>().unwrap();
|
||||
|
||||
assert!(obj.is_null());
|
||||
assert!(obj.name().is_none());
|
||||
assert_eq!(obj.path(), NULL_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialization_owned_object_ref() {
|
||||
let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
let path = ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH);
|
||||
|
||||
let object_ref = ObjectRef::new_owned(name, path);
|
||||
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &object_ref).unwrap();
|
||||
|
||||
let (obj, _) = encoded.deserialize::<ObjectRef>().unwrap();
|
||||
|
||||
// Deserialization alwayys results in a borrowed object reference.
|
||||
// On the wire the distinction between owned and borrowed is not preserved.
|
||||
// As borrowed is the cheaper option, we always deserialize to that.
|
||||
assert!(matches!(obj, ObjectRef::Borrowed { .. }));
|
||||
assert_eq!(obj.name().unwrap().as_str(), ":1.23");
|
||||
assert_eq!(obj.path_as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialization_borrowed_object_ref() {
|
||||
let object_ref = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &object_ref).unwrap();
|
||||
|
||||
let (obj, _) = encoded.deserialize::<ObjectRef>().unwrap();
|
||||
assert!(matches!(obj, ObjectRef::Borrowed { .. }));
|
||||
|
||||
assert_eq!(obj.name().unwrap().as_str(), ":1.23");
|
||||
assert_eq!(obj.path_as_str(), TEST_OBJECT_PATH);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_ref_equality() {
|
||||
let object_ref1 = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
let object_ref2 = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.23").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
assert_eq!(object_ref1, object_ref2);
|
||||
|
||||
let object_ref3 = ObjectRef::new_borrowed(
|
||||
UniqueName::from_static_str(":1.24").unwrap(),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
assert_ne!(object_ref1, object_ref3);
|
||||
|
||||
let object_ref4 = ObjectRef::new_owned(
|
||||
UniqueName::from_static_str_unchecked(":1.23"),
|
||||
ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH),
|
||||
);
|
||||
assert_eq!(object_ref1, object_ref4);
|
||||
|
||||
let null_object_ref: ObjectRef = ObjectRef::Null;
|
||||
assert_ne!(object_ref1, null_object_ref);
|
||||
assert_ne!(null_object_ref, object_ref1);
|
||||
|
||||
let null_object_ref2: ObjectRef = ObjectRef::Null;
|
||||
assert_eq!(null_object_ref, null_object_ref2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_from_value_for_objectref() {
|
||||
let name = UniqueName::from_static_str_unchecked(":0.0");
|
||||
let path = ObjectPath::from_static_str_unchecked("/org/a11y/atspi/testpath");
|
||||
|
||||
let objref = ObjectRef::new_borrowed(name, path);
|
||||
let value: Value = objref.into();
|
||||
|
||||
let objref_2: ObjectRef = value.try_into().unwrap();
|
||||
|
||||
assert_eq!(objref_2.name().unwrap().as_str(), ":0.0");
|
||||
assert_eq!(objref_2.path_as_str(), "/org/a11y/atspi/testpath");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_from_owned_value_for_objectref() {
|
||||
let name = UniqueName::from_static_str_unchecked(":0.0");
|
||||
let path = ObjectPath::from_static_str_unchecked("/org/a11y/atspi/testpath");
|
||||
|
||||
let objref = ObjectRef::new_borrowed(name, path);
|
||||
|
||||
let value: Value = objref.into();
|
||||
let value: OwnedValue = value.try_into().unwrap();
|
||||
let objref_2: ObjectRef = value.try_into().unwrap();
|
||||
|
||||
assert_eq!(objref_2.name_as_str(), Some(":0.0"));
|
||||
assert_eq!(objref_2.path_as_str(), "/org/a11y/atspi/testpath");
|
||||
}
|
||||
|
||||
// Must fail test:
|
||||
|
||||
#[test]
|
||||
fn must_fail_test_try_from_invalid_value_for_object_ref() {
|
||||
let value = zbus::wire::Variant::from((42, true));
|
||||
let obj: Result<ObjectRef, _> = value.try_into();
|
||||
assert!(obj.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_and_object_coherence() {
|
||||
let name = UniqueName::from_static_str_unchecked(":1.23");
|
||||
let path = ObjectPath::from_static_str_unchecked(TEST_OBJECT_PATH);
|
||||
|
||||
let object_ref1 = ObjectRef::new_borrowed(&name, &path);
|
||||
let object_ref2 = ObjectRef::new_borrowed(name, path);
|
||||
|
||||
let mut hasher1 = DefaultHasher::new();
|
||||
let mut hasher2 = DefaultHasher::new();
|
||||
assert_eq!(object_ref1, object_ref2);
|
||||
object_ref1.hash(&mut hasher1);
|
||||
object_ref2.hash(&mut hasher2);
|
||||
assert_eq!(hasher1.finish(), hasher2.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "assertion failed: matches!(obj, ObjectRef::Borrowed { .. })")]
|
||||
fn valid_name_null_path_object_ref() {
|
||||
let object_ref = ObjectRef::from_static_str_unchecked("1.23", NULL_PATH_STR);
|
||||
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &object_ref).unwrap();
|
||||
|
||||
let (obj, _) = encoded.deserialize::<ObjectRef>().unwrap();
|
||||
assert!(matches!(obj, ObjectRef::Borrowed { .. }));
|
||||
}
|
||||
|
||||
// Check that the Deserialize implementation correctly panics
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = r#"A non-null ObjectRef requires a name and a path but got: ("", /org/a11y/atspi/path/007)"#
|
||||
)]
|
||||
fn empty_name_valid_path_object_ref() {
|
||||
let object_ref = ObjectRef::from_static_str_unchecked("", TEST_OBJECT_PATH);
|
||||
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &object_ref).unwrap();
|
||||
|
||||
let (_obj, _) = encoded.deserialize::<ObjectRef>().unwrap();
|
||||
}
|
||||
}
|
||||
39
patches/atspi-common/src/operation.rs
vendored
Normal file
39
patches/atspi-common/src/operation.rs
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use crate::AtspiError;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
/// An operation can either be [`Self::Insert`] or [`Self::Delete`].
|
||||
/// These correspond to methods available on [`Vec`].
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize, Eq, Hash, Default)]
|
||||
pub enum Operation {
|
||||
#[default]
|
||||
#[serde(rename = "add")]
|
||||
#[serde(alias = "add/system")]
|
||||
#[serde(alias = "insert")]
|
||||
#[serde(alias = "insert/system")]
|
||||
Insert,
|
||||
#[serde(rename = "delete")]
|
||||
#[serde(alias = "delete/system")]
|
||||
#[serde(alias = "remove")]
|
||||
#[serde(alias = "remove/system")]
|
||||
Delete,
|
||||
}
|
||||
|
||||
impl FromStr for Operation {
|
||||
type Err = AtspiError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"add" | "add/system" | "insert" | "insert/system" => Ok(Operation::Insert),
|
||||
"delete" | "delete/system" | "remove" | "remove/system" => Ok(Operation::Delete),
|
||||
_ => Err(AtspiError::KindMatch(format!("{s} is not a type of Operation"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Operation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Operation::Insert => write!(f, "insert"),
|
||||
Operation::Delete => write!(f, "delete"),
|
||||
}
|
||||
}
|
||||
}
|
||||
121
patches/atspi-common/src/relation_type.rs
vendored
Normal file
121
patches/atspi-common/src/relation_type.rs
vendored
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use zbus::wire::Type;
|
||||
|
||||
/// Describes a relationship between one object and another.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Hash)]
|
||||
pub enum RelationType {
|
||||
/// Not a meaningful relationship; clients should not normally encounter this value.
|
||||
Null = 0,
|
||||
|
||||
/// Object is a label for one or more other objects.
|
||||
LabelFor,
|
||||
|
||||
/// Object is labelled by one or more other objects.
|
||||
LabelledBy,
|
||||
|
||||
/// Object is an interactive object which modifies the state,
|
||||
/// onscreen location, or other attributes of one or more target objects.
|
||||
ControllerFor,
|
||||
|
||||
/// Object state, position, etc. is modified/controlled by user interaction
|
||||
/// with one or more other objects.
|
||||
/// For instance a viewport or scroll pane may be `ControlledBy` scrollbars.
|
||||
ControlledBy,
|
||||
|
||||
/// Object has a grouping relationship (e.g. 'same group as') to one or more other objects.
|
||||
MemberOf,
|
||||
|
||||
/// Object is a tooltip associated with another object.
|
||||
TooltipFor,
|
||||
|
||||
/// Object is a child of the target.
|
||||
NodeChildOf,
|
||||
|
||||
/// Object is a parent of the target.
|
||||
NodeParentOf,
|
||||
|
||||
/// Used to indicate that a relationship exists, but its type is not
|
||||
/// specified in the enumeration.
|
||||
Extended,
|
||||
|
||||
/// Object renders content which flows logically to another object.
|
||||
/// For instance, text in a paragraph may flow to another object
|
||||
/// which is not the 'next sibling' in the accessibility hierarchy.
|
||||
FlowsTo,
|
||||
|
||||
/// Reciprocal of `FlowsTo`.
|
||||
FlowsFrom,
|
||||
|
||||
/// Object is visually and semantically considered a subwindow of another object,
|
||||
/// even though it is not the object's child.
|
||||
/// Useful when dealing with embedded applications and other cases where the
|
||||
/// widget hierarchy does not map cleanly to the onscreen presentation.
|
||||
SubwindowOf,
|
||||
|
||||
/// Similar to `SubwindowOf`, but specifically used for cross-process embedding.
|
||||
Embeds,
|
||||
|
||||
/// Reciprocal of `Embeds`. Used to denote content rendered by embedded renderers
|
||||
/// that live in a separate process space from the embedding context.
|
||||
EmbeddedBy,
|
||||
|
||||
///Denotes that the object is a transient window or frame associated with another
|
||||
/// onscreen object. Similar to `TooltipFor`, but more general.
|
||||
/// Useful for windows which are technically toplevels but which, for one or more reasons,
|
||||
/// do not explicitly cause their associated window to lose 'window focus'.
|
||||
/// Creation of an [`crate::Role::Window`] object with the `PopupFor` relation usually requires
|
||||
/// some presentation action on the part of assistive technology clients,
|
||||
/// even though the previous toplevel [`crate::Role::Frame`] object may still be the active window.
|
||||
PopupFor,
|
||||
|
||||
/// This is the reciprocal relation to `PopupFor`.
|
||||
ParentWindowOf,
|
||||
|
||||
/// Reciprocal of `DescribedBy`. Indicates that this object provides descriptive information
|
||||
/// about the target object(s). See also `DetailsFor` and `ErrorFor`.
|
||||
DescriptionFor,
|
||||
|
||||
/// Reciprocal of `DescriptionFor`.
|
||||
/// Indicates that one or more target objects provide descriptive information
|
||||
/// about this object. This relation type is most appropriate for information
|
||||
/// that is not essential as its presentation may be user-configurable and/or
|
||||
/// limited to an on-demand mechanism such as an assistive technology command.
|
||||
/// For brief, essential information such as can be found in a widget's on-screen
|
||||
/// label, use `LabelledBy`. For an on-screen error message, use `ErrorMessage`.
|
||||
/// For lengthy extended descriptive information contained in an on-screen object,
|
||||
/// consider using `Details` as assistive technologies may provide a means
|
||||
/// for the user to navigate to objects containing detailed descriptions so that
|
||||
/// their content can be more closely reviewed.
|
||||
DescribedBy,
|
||||
|
||||
/// Reciprocal of `DetailsFor`.
|
||||
/// Indicates that this object has a detailed or extended description,
|
||||
/// the contents of which can be found in the target object(s).
|
||||
/// This relation type is most appropriate for information that is sufficiently lengthy
|
||||
/// as to make navigation to the container of that information desirable.
|
||||
/// For less verbose information suitable for announcement only, see `DescribedBy`.
|
||||
/// If the detailed information describes an error condition, `ErrorFor` should be used instead.
|
||||
/// Included in upstream [AT-SPI2-CORE](https://gitlab.gnome.org/GNOME/at-spi2-core) since 2.26.
|
||||
Details,
|
||||
|
||||
/// Reciprocal of `Details`.
|
||||
/// Indicates that this object provides a detailed or extended description about the target
|
||||
/// object(s). See also `DescriptionFor` and `ErrorFor`.
|
||||
/// Included in upstream [AT-SPI2-CORE](https://gitlab.gnome.org/GNOME/at-spi2-core) since 2.26.
|
||||
DetailsFor,
|
||||
|
||||
/// Reciprocal of `ErrorFor`.
|
||||
/// Indicates that this object has one or more errors, the nature of which is
|
||||
/// described in the contents of the target object(s). Objects that have this
|
||||
/// relation type should also contain [`crate::state::State::InvalidEntry`] when their
|
||||
/// `GetState` method is called.
|
||||
///
|
||||
/// Included in upstream [AT-SPI2-CORE](https://gitlab.gnome.org/GNOME/at-spi2-core) since 2.26.
|
||||
ErrorMessage,
|
||||
|
||||
/// Reciprocal of `ErrorMessage`.
|
||||
/// Indicates that this object contains an error message describing an invalid condition
|
||||
/// in the target object(s).
|
||||
/// Included in upstream [AT-SPI2-CORE](https://gitlab.gnome.org/GNOME/at-spi2-core) since 2.26.
|
||||
ErrorFor,
|
||||
}
|
||||
651
patches/atspi-common/src/role.rs
vendored
Normal file
651
patches/atspi-common/src/role.rs
vendored
Normal file
|
|
@ -0,0 +1,651 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use zbus::wire::Type;
|
||||
|
||||
use crate::AtspiError;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Hash)]
|
||||
/// An accessible object role.
|
||||
///
|
||||
/// To think of it in terms of HTML, any semantic element likely has a corollary in this enum.
|
||||
/// For example: `<button>`, `<input>`, `<form>` or `<h4>`.
|
||||
/// Non-semantic elements like `<span>`, `<div>` and `<b>` will not be represented here, and this information is not passed through via the atspi library.
|
||||
/// TODO: add examples for GTK/Qt libraries in addition to HTML examples.
|
||||
#[repr(u32)]
|
||||
pub enum Role {
|
||||
/// A role indicating an error condition, such as uninitialized Role data, or an error deserializing.
|
||||
Invalid,
|
||||
/// Object is a label indicating the keyboard accelerators for the parent.
|
||||
AcceleratorLabel,
|
||||
/// Object is used to alert the user about something.
|
||||
Alert,
|
||||
/// Object contains a dynamic or moving image of some kind.
|
||||
Animation,
|
||||
/// Object is a 2d directional indicator.
|
||||
Arrow,
|
||||
/// Object contains one or more dates, usually arranged into a 2d list.
|
||||
Calendar,
|
||||
/// Object that can be drawn into and is used to trap events.
|
||||
Canvas,
|
||||
/// A choice that can be checked or unchecked and provides a separate indicator for the current state.
|
||||
CheckBox,
|
||||
/// A menu item that behaves like a check box. See [`Self::CheckBox`].
|
||||
CheckMenuItem,
|
||||
/// A specialized dialog that lets the user choose a color.
|
||||
ColorChooser,
|
||||
/// The header for a column of data.
|
||||
ColumnHeader,
|
||||
/// A list of choices the user can select from.
|
||||
ComboBox,
|
||||
/// An object which allows entry of a date.
|
||||
DateEditor,
|
||||
/// An inconifed internal frame within a [`Role::DesktopFrame`].
|
||||
DesktopIcon,
|
||||
/// A pane that supports internal frames and iconified versions of those internal frames.
|
||||
DesktopFrame,
|
||||
/// An object that allows a value to be changed via rotating a visual element, or which displays a value via such a rotating element.
|
||||
Dial,
|
||||
/// A top level window with title bar and a border.
|
||||
Dialog,
|
||||
/// A pane that allows the user to navigate through and select the contents of a directory.
|
||||
DirectoryPane,
|
||||
/// An object used for drawing custom user interface elements.
|
||||
DrawingArea,
|
||||
/// A specialized dialog that displays the files in the directory and lets the user select a file, browse a different directory, or specify a filename.
|
||||
FileChooser,
|
||||
/// A object that fills up space in a user interface.
|
||||
Filler,
|
||||
/// Don't use, reserved for future use.
|
||||
FocusTraversable,
|
||||
/// Allows selection of a display font.
|
||||
FontChooser,
|
||||
/// A top level window with a title bar, border, menubar, etc.
|
||||
Frame,
|
||||
/// A pane that is guaranteed to be painted on top of all panes beneath it.
|
||||
GlassPane,
|
||||
/// A document container for HTML, whose children represent the document content.
|
||||
HTMLContainer,
|
||||
/// A small fixed size picture, typically used to decorate components.
|
||||
Icon,
|
||||
/// An image, typically static.
|
||||
Image,
|
||||
/// A frame-like object that is clipped by a desktop pane.
|
||||
InternalFrame,
|
||||
/// An object used to present an icon or short string in an interface.
|
||||
Label,
|
||||
/// A specialized pane that allows its children to be drawn in layers, providing a form of stacking order.
|
||||
LayeredPane,
|
||||
/// An object that presents a list of objects to the user and * allows the user to select one or more of them.
|
||||
List,
|
||||
/// An object that represents an element of a list.
|
||||
ListItem,
|
||||
/// An object usually found inside a menu bar that contains a list of actions the user can choose from.
|
||||
Menu,
|
||||
/// An object usually drawn at the top of the primary dialog box of an application that contains a list of menus the user can choose from.
|
||||
MenuBar,
|
||||
/// An object usually contained in a menu that presents an action the user can choose.
|
||||
MenuItem,
|
||||
/// A specialized pane whose primary use is inside a dialog.
|
||||
OptionPane,
|
||||
/// An object that is a child of a page tab list.
|
||||
PageTab,
|
||||
/// An object that presents a series of panels (or page tabs), one at a time,through some mechanism provided by the object.
|
||||
PageTabList,
|
||||
/// A generic container that is often used to group objects.
|
||||
Panel,
|
||||
/// A text object uses for passwords, or other places where the text content is not shown visibly to the user.
|
||||
PasswordText,
|
||||
/// A temporary window that is usually used to offer the user a list of choices, and then hides when the user selects one of those choices.
|
||||
PopupMenu,
|
||||
/// An object used to indicate how much of a task has been completed.
|
||||
ProgressBar,
|
||||
/// An object the user can manipulate to tell the application to do something.
|
||||
Button,
|
||||
/// A specialized check box that will cause other radio buttons in the same group to become unchecked when this one is checked.
|
||||
RadioButton,
|
||||
/// Object is both a menu item and a "radio button". See [`Self::RadioButton`].
|
||||
RadioMenuItem,
|
||||
/// A specialized pane that has a glass pane and a layered pane as its children.
|
||||
RootPane,
|
||||
/// The header for a row of data.
|
||||
RowHeader,
|
||||
/// An object usually used to allow a user to incrementally view a large amount of data by moving the bounds of a viewport along a one-dimensional axis.
|
||||
ScrollBar,
|
||||
/// A scroll pane: the pane in which the scrollable content is contained within.
|
||||
/// An object that allows a user to incrementally view a large amount of information.
|
||||
/// [`Self::ScrollPane`] objects are usually accompanied by [`Self::ScrollBar`] controllers,
|
||||
/// on which the [`crate::RelationType::ControllerFor`] and [`crate::RelationType::ControlledBy`] reciprocal relations are set.
|
||||
ScrollPane,
|
||||
/// An object usually contained in a menu to provide a visible and logical separation of the contents in a menu.
|
||||
Separator,
|
||||
/// An object that allows the user to select from a bounded range.
|
||||
/// Unlike [`Self::ScrollBar`], [`Self::Slider`] objects need not control 'viewport'-like objects.
|
||||
Slider,
|
||||
/// An object which allows one of a set of choices to be selected, and which displays the current choice.
|
||||
SpinButton,
|
||||
/// A specialized panel that presents two other panels at the same time.
|
||||
SplitPane,
|
||||
/// Object displays non-quantitative status information (c.f. [`Self::ProgressBar`])
|
||||
StatusBar,
|
||||
/// An object used to represent information in terms of rows and columns.
|
||||
Table,
|
||||
/// A 'cell' or discrete child within a Table.
|
||||
/// Note: Table cells need not have [`Self::TableCell`], other [`crate::Role`] values are valid as well.
|
||||
TableCell,
|
||||
/// An object which labels a particular column in an [`Self::Table`].
|
||||
TableColumnHeader,
|
||||
/// An object which labels a particular row in a [`Self::Table`].
|
||||
/// `TableProxy` rows and columns may also be labelled via the
|
||||
/// [`crate::RelationType::LabelFor`]/[`crate::RelationType::LabelledBy`] relationships.
|
||||
/// See: `AccessibleProxy::get_relation_type`.
|
||||
TableRowHeader,
|
||||
/// Object allows menu to be removed from menubar and shown in its own window.
|
||||
TearoffMenuItem,
|
||||
/// An object that emulates a terminal.
|
||||
Terminal,
|
||||
/// An interactive widget that supports multiple lines of text and optionally accepts user input,
|
||||
/// but whose purpose is not to solicit user input.
|
||||
/// Thus [`Self::Text`] is appropriate for the text view in a plain text editor but inappropriate for an input field in a dialog box or web form.
|
||||
/// For widgets whose purpose is to solicit input from the user, see [`Self::Entry`] and [`Self::PasswordText`].
|
||||
/// For generic objects which display a brief amount of textual information, see [`Self::Static`].
|
||||
Text,
|
||||
/// A specialized push button that can be checked or unchecked, but does not provide a separate indicator for the current state.
|
||||
ToggleButton,
|
||||
/// A bar or palette usually composed of push buttons or toggle buttons.
|
||||
ToolBar,
|
||||
/// An object that provides information about another object.
|
||||
ToolTip,
|
||||
/// An object used to repsent hierarchical information to the user.
|
||||
Tree,
|
||||
/// An object that presents both tabular and hierarchical info to the user.
|
||||
TreeTable,
|
||||
/// When the role cannot be accurately reported, this role will be set.
|
||||
Unknown,
|
||||
/// An object usually used in a scroll pane, or to otherwise clip a larger object or content renderer to a specific onscreen viewport.
|
||||
Viewport,
|
||||
/// A top level window with no title or border.
|
||||
Window,
|
||||
/// means that the role for this item is known, but not included in the core enumeration.
|
||||
Extended,
|
||||
/// An object that serves as a document header.
|
||||
Header,
|
||||
/// An object that serves as a document footer.
|
||||
Footer,
|
||||
/// An object which is contains a single paragraph of text content. See also [`Self::Text`].
|
||||
Paragraph,
|
||||
/// An object which describes margins and tab stops, etc. for text objects which it controls (should have [`crate::RelationType::ControllerFor`] relation to such).
|
||||
Ruler,
|
||||
/// An object corresponding to the toplevel accessible of an application, which may contain [`Self::Frame`] objects or other accessible objects.
|
||||
/// Children of objects with the [`Self::DesktopFrame`] role are generally [`Self::Application`] objects.
|
||||
Application,
|
||||
/// The object is a dialog or list containing items for insertion into an entry widget, for instance a list of words for completion of a text entry.
|
||||
Autocomplete,
|
||||
/// The object is an editable text object in a toolbar.
|
||||
Editbar,
|
||||
/// The object is an embedded component container.
|
||||
/// This role is a "grouping" hint that the contained objects share a context which is different from the container in which this accessible is embedded.
|
||||
/// In particular, it is used for some kinds of document embedding, and for embedding of out-of-process component, "panel applets", etc.
|
||||
Embedded,
|
||||
/// The object is a component whose textual content may be entered or modified by the user, provided [`crate::State::Editable`] is present.
|
||||
/// A readonly [`Self::Entry`] object (i.e. where [`crate::State::Editable`] is not present) implies a read-only 'text field' in a form, as opposed to a title, label, or caption.
|
||||
Entry,
|
||||
/// The object is a graphical depiction of quantitative data.
|
||||
/// It may contain multiple subelements whose attributes and/or description may be queried to obtain both the quantitative data and information about how the data is being presented.
|
||||
/// The [`crate::RelationType::LabelledBy`] relation is particularly important in interpreting objects of this type, as is the accessible description property.
|
||||
/// See [`Self::Caption`].
|
||||
CHART,
|
||||
/// The object contains descriptive information, usually textual, about another user interface element such as a table, chart, or image.
|
||||
Caption,
|
||||
/// The object is a visual frame or container which
|
||||
/// contains a view of document content. [`Self::DocumentFrame`]s may occur within
|
||||
/// another `DocumentProxy` instance, in which case the second document may be
|
||||
/// said to be embedded in the containing instance.
|
||||
/// HTML frames are often [`Self::DocumentFrame`]: Either this object, or a singleton descendant,
|
||||
/// should implement the [`crate::Interface::Document`] interface.
|
||||
DocumentFrame,
|
||||
/// Heading: this is a heading with a level (usually 1-6). This is represented by `<h1>` through `<h6>` in HTML.
|
||||
/// The object serves as a heading for content which follows it in a document.
|
||||
/// The 'heading level' of the heading, if available, may be obtained by querying the object's attributes.
|
||||
Heading,
|
||||
/// The object is a containing instance which encapsulates a page of information.
|
||||
/// [`Self::Page`] is used in documents and content which support a paginated navigation model.
|
||||
Page,
|
||||
/// The object is a containing instance of document content which constitutes a particular 'logical' section of the document.
|
||||
/// The type of content within a section, and the nature of the section division itself, may be obtained by querying the object's attributes.
|
||||
/// Sections may be nested.
|
||||
Section,
|
||||
/// The object is redundant with another object in the hierarchy, and is exposed for purely technical reasons.
|
||||
/// Objects of this role should be ignored by clients, if they are encountered at all.
|
||||
RedundantObject,
|
||||
/// The object is a containing instance of document content which has within it components with which the user can interact in order to input information;
|
||||
/// i.e. the object is a container for pushbuttons, comboboxes, text input fields, and other 'GUI' components.
|
||||
/// [`Self::Form`] should not, in general, be used for toplevel GUI containers or dialogs, but should be reserved for 'GUI' containers which occur within document content, for instance within Web documents, presentations, or text documents.
|
||||
/// Unlike other GUI containers and dialogs which occur inside application instances, [`Self::Form`] containers' components are associated with the current document, rather than the current foreground application or viewer instance.
|
||||
Form,
|
||||
/// The object is a hypertext anchor, i.e. a "link" in a hypertext document.
|
||||
/// Such objects are distinct from 'inline' content which may also use the [`crate::Interface::Hypertext`]/[`crate::Interface::Hyperlink`] interfaces to indicate the range/location within a text object where an inline or embedded object lies.
|
||||
Link,
|
||||
/// The object is a window or similar viewport which is used to allow composition or input of a 'complex character', in other words it is an "input method window".
|
||||
InputMethodWindow,
|
||||
/// A row in a table.
|
||||
TableRow,
|
||||
/// An object that represents an element of a tree.
|
||||
TreeItem,
|
||||
/// A document frame which contains a spreadsheet.
|
||||
DocumentSpreadsheet,
|
||||
/// A document frame which contains a presentation or slide content.
|
||||
DocumentPresentation,
|
||||
/// A document frame which contains textual content, such as found in a word processing application.
|
||||
DocumentText,
|
||||
/// A document frame which contains HTML or other markup suitable for display in a web browser.
|
||||
DocumentWeb,
|
||||
/// A document frame which contains email content to be displayed or composed either in plain text or HTML.
|
||||
DocumentEmail,
|
||||
/// An object found within a document and designed to present a comment, note, or other annotation.
|
||||
/// In some cases, this object might not be visible until activated.
|
||||
Comment,
|
||||
/// A non-collapsible list of choices the user can select from.
|
||||
ListBox,
|
||||
/// A group of related widgets. This group typically has a label.
|
||||
Grouping,
|
||||
/// An image map object. Usually a graphic with multiple hotspots, where each hotspot can be activated resulting in the loading of another document or section of a document.
|
||||
ImageMap,
|
||||
/// A transitory object designed to present a message to the user, typically at the desktop level rather than inside a particular application.
|
||||
Notification,
|
||||
/// An object designed to present a message to the user within an existing window.
|
||||
InfoBar,
|
||||
/// A bar that serves as a level indicator to, for instance, show the strength of a password or the state of a battery.
|
||||
LevelBar,
|
||||
/// A bar that serves as the title of a window or a dialog.
|
||||
TitleBar,
|
||||
/// An object which contains a text section that is quoted from another source.
|
||||
BlockQuote,
|
||||
/// An object which represents an audio element.
|
||||
Audio,
|
||||
/// An object which represents a video element.
|
||||
Video,
|
||||
/// A definition of a term or concept.
|
||||
Definition,
|
||||
/// A section of a page that consists of a composition that forms an independent part of a document, page, or site.
|
||||
/// Examples: A blog entry, a news story, a forum post.
|
||||
Article,
|
||||
/// A region of a web page intended as a navigational landmark. This is designed to allow Assistive Technologies to provide quick navigation among key regions within a document.
|
||||
Landmark,
|
||||
/// A text widget or container holding log content, such as chat history and error logs. In this role there is a relationship between the arrival of new items in the log and the reading order.
|
||||
/// The log contains a meaningful sequence and new information is added only to the end of the log, not at arbitrary points.
|
||||
Log,
|
||||
/// A container where non-essential information changes frequently.
|
||||
/// Common usages of marquee include stock tickers and ad banners.
|
||||
/// The primary difference between a marquee and a log is that logs usually have a meaningful order or sequence of important content changes.
|
||||
Marquee,
|
||||
/// A text widget or container that holds a mathematical expression.
|
||||
Math,
|
||||
/// A rating system, generally out of five stars, but it does not need to be that way. There is no tag nor role for this in HTML, however.
|
||||
/// A widget whose purpose is to display a rating, such as the number of stars associated with a song in a media player.
|
||||
/// Objects of this role should also implement [`crate::Interface::Value`].
|
||||
Rating,
|
||||
/// An object containing a numerical counter which indicates an amount of elapsed time from a start point, or the time remaining until an end point.
|
||||
Timer,
|
||||
/// A generic non-container object whose purpose is to display a brief amount of information to the user and whose role is known by the implementor but lacks semantic value for the user.
|
||||
/// Examples in which [`Self::Static`] is appropriate include the message displayed in a message box and an image used as an alternative means to display text.
|
||||
/// [`Self::Static`] should not be applied to widgets which are traditionally interactive, objects which display a significant amount of content, or any object which has an accessible relation pointing to another object.
|
||||
/// The displayed information, as a general rule, should be exposed through the accessible name of the object.
|
||||
/// For labels which describe another widget, see [`Self::Label`].
|
||||
/// For text views, see [`Self::Text`].
|
||||
/// For generic containers, see [`Self::Panel`]. For objects whose role is not known by the implementor, see [`Self::Unknown`].
|
||||
Static,
|
||||
/// An object that represents a mathematical fraction.
|
||||
MathFraction,
|
||||
/// An object that represents a mathematical expression displayed with a radical.
|
||||
MathRoot,
|
||||
/// An object that contains text that is displayed as a subscript.
|
||||
Subscript,
|
||||
/// An object that contains text that is displayed as a superscript.
|
||||
Superscript,
|
||||
/// An object that represents a list of term-value groups.
|
||||
/// A term-value group represents an individual description and consist of one or more names ([`Self::DescriptionTerm`]) followed by one or more values ([`Self::DescriptionValue`]).
|
||||
/// For each list, there should not be more than one group with the same term name.
|
||||
DescriptionList,
|
||||
/// An object that represents a term or phrase with a corresponding definition.
|
||||
DescriptionTerm,
|
||||
/// An object that represents the description, definition, or value of a term.
|
||||
DescriptionValue,
|
||||
/// An object that contains the text of a footnote.
|
||||
Footnote,
|
||||
/// Content previously deleted or proposed to be deleted, e.g. in revision history or a content view providing suggestions from reviewers.
|
||||
ContentDeletion,
|
||||
/// Content previously inserted or proposed to be inserted, e.g. in revision history or a content view providing suggestions from reviewers.
|
||||
ContentInsertion,
|
||||
/// A run of content that is marked or highlighted, such as for reference purposes, or to call it out as having a special purpose.
|
||||
/// If the marked content has an associated section in the document elaborating on the reason for the mark, then [`crate::RelationType::Details`] should be used on the mark to point to that associated section.
|
||||
/// In addition, the reciprocal relation [`crate::RelationType::DetailsFor`] should be used on the associated content section to point back to the mark.
|
||||
Mark,
|
||||
/// A container for content that is called out as a proposed change from the current version of the document, such as by a reviewer of the content.
|
||||
/// An object with this role should include children with [`Self::ContentDeletion`] and/or [`Self::ContentInsertion`], in any order, to indicate what the actual change is.
|
||||
Suggestion,
|
||||
/// A specialized push button to open a menu.
|
||||
PushButtonMenu,
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for Role {
|
||||
type Error = AtspiError;
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
#[allow(clippy::enum_glob_use)]
|
||||
use Role::*;
|
||||
let res = match value {
|
||||
0 => Invalid,
|
||||
1 => AcceleratorLabel,
|
||||
2 => Alert,
|
||||
3 => Animation,
|
||||
4 => Arrow,
|
||||
5 => Calendar,
|
||||
6 => Canvas,
|
||||
7 => CheckBox,
|
||||
8 => CheckMenuItem,
|
||||
9 => ColorChooser,
|
||||
10 => ColumnHeader,
|
||||
11 => ComboBox,
|
||||
12 => DateEditor,
|
||||
13 => DesktopIcon,
|
||||
14 => DesktopFrame,
|
||||
15 => Dial,
|
||||
16 => Dialog,
|
||||
17 => DirectoryPane,
|
||||
18 => DrawingArea,
|
||||
19 => FileChooser,
|
||||
20 => Filler,
|
||||
21 => FocusTraversable,
|
||||
22 => FontChooser,
|
||||
23 => Frame,
|
||||
24 => GlassPane,
|
||||
25 => HTMLContainer,
|
||||
26 => Icon,
|
||||
27 => Image,
|
||||
28 => InternalFrame,
|
||||
29 => Label,
|
||||
30 => LayeredPane,
|
||||
31 => List,
|
||||
32 => ListItem,
|
||||
33 => Menu,
|
||||
34 => MenuBar,
|
||||
35 => MenuItem,
|
||||
36 => OptionPane,
|
||||
37 => PageTab,
|
||||
38 => PageTabList,
|
||||
39 => Panel,
|
||||
40 => PasswordText,
|
||||
41 => PopupMenu,
|
||||
42 => ProgressBar,
|
||||
43 => Button,
|
||||
44 => RadioButton,
|
||||
45 => RadioMenuItem,
|
||||
46 => RootPane,
|
||||
47 => RowHeader,
|
||||
48 => ScrollBar,
|
||||
49 => ScrollPane,
|
||||
50 => Separator,
|
||||
51 => Slider,
|
||||
52 => SpinButton,
|
||||
53 => SplitPane,
|
||||
54 => StatusBar,
|
||||
55 => Table,
|
||||
56 => TableCell,
|
||||
57 => TableColumnHeader,
|
||||
58 => TableRowHeader,
|
||||
59 => TearoffMenuItem,
|
||||
60 => Terminal,
|
||||
61 => Text,
|
||||
62 => ToggleButton,
|
||||
63 => ToolBar,
|
||||
64 => ToolTip,
|
||||
65 => Tree,
|
||||
66 => TreeTable,
|
||||
67 => Unknown,
|
||||
68 => Viewport,
|
||||
69 => Window,
|
||||
70 => Extended,
|
||||
71 => Header,
|
||||
72 => Footer,
|
||||
73 => Paragraph,
|
||||
74 => Ruler,
|
||||
75 => Application,
|
||||
76 => Autocomplete,
|
||||
77 => Editbar,
|
||||
78 => Embedded,
|
||||
79 => Entry,
|
||||
80 => CHART,
|
||||
81 => Caption,
|
||||
82 => DocumentFrame,
|
||||
83 => Heading,
|
||||
84 => Page,
|
||||
85 => Section,
|
||||
86 => RedundantObject,
|
||||
87 => Form,
|
||||
88 => Link,
|
||||
89 => InputMethodWindow,
|
||||
90 => TableRow,
|
||||
91 => TreeItem,
|
||||
92 => DocumentSpreadsheet,
|
||||
93 => DocumentPresentation,
|
||||
94 => DocumentText,
|
||||
95 => DocumentWeb,
|
||||
96 => DocumentEmail,
|
||||
97 => Comment,
|
||||
98 => ListBox,
|
||||
99 => Grouping,
|
||||
100 => ImageMap,
|
||||
101 => Notification,
|
||||
102 => InfoBar,
|
||||
103 => LevelBar,
|
||||
104 => TitleBar,
|
||||
105 => BlockQuote,
|
||||
106 => Audio,
|
||||
107 => Video,
|
||||
108 => Definition,
|
||||
109 => Article,
|
||||
110 => Landmark,
|
||||
111 => Log,
|
||||
112 => Marquee,
|
||||
113 => Math,
|
||||
114 => Rating,
|
||||
115 => Timer,
|
||||
116 => Static,
|
||||
117 => MathFraction,
|
||||
118 => MathRoot,
|
||||
119 => Subscript,
|
||||
120 => Superscript,
|
||||
121 => DescriptionList,
|
||||
122 => DescriptionTerm,
|
||||
123 => DescriptionValue,
|
||||
124 => Footnote,
|
||||
125 => ContentDeletion,
|
||||
126 => ContentInsertion,
|
||||
127 => Mark,
|
||||
128 => Suggestion,
|
||||
129 => PushButtonMenu,
|
||||
_ => return Err(AtspiError::UnknownRole(value)),
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
const ROLE_NAMES: &[&str] = &[
|
||||
"invalid",
|
||||
"accelerator label",
|
||||
"alert",
|
||||
"animation",
|
||||
"arrow",
|
||||
"calendar",
|
||||
"canvas",
|
||||
"check box",
|
||||
"check menu item",
|
||||
"color chooser",
|
||||
"column header",
|
||||
"combo box",
|
||||
"date editor",
|
||||
"desktop icon",
|
||||
"desktop frame",
|
||||
"dial",
|
||||
"dialog",
|
||||
"directory pane",
|
||||
"drawing area",
|
||||
"file chooser",
|
||||
"filler",
|
||||
"focus traversable",
|
||||
"font chooser",
|
||||
"frame",
|
||||
"glass pane",
|
||||
"html container",
|
||||
"icon",
|
||||
"image",
|
||||
"internal frame",
|
||||
"label",
|
||||
"layered pane",
|
||||
"list",
|
||||
"list item",
|
||||
"menu",
|
||||
"menu bar",
|
||||
"menu item",
|
||||
"option pane",
|
||||
"page tab",
|
||||
"page tab list",
|
||||
"panel",
|
||||
"password text",
|
||||
"popup menu",
|
||||
"progress bar",
|
||||
"button",
|
||||
"radio button",
|
||||
"radio menu item",
|
||||
"root pane",
|
||||
"row header",
|
||||
"scroll bar",
|
||||
"scroll pane",
|
||||
"separator",
|
||||
"slider",
|
||||
"spin button",
|
||||
"split pane",
|
||||
"status bar",
|
||||
"table",
|
||||
"table cell",
|
||||
"table column header",
|
||||
"table row header",
|
||||
"tearoff menu item",
|
||||
"terminal",
|
||||
"text",
|
||||
"toggle button",
|
||||
"tool bar",
|
||||
"tool tip",
|
||||
"tree",
|
||||
"tree table",
|
||||
"unknown",
|
||||
"viewport",
|
||||
"window",
|
||||
"extended",
|
||||
"header",
|
||||
"footer",
|
||||
"paragraph",
|
||||
"ruler",
|
||||
"application",
|
||||
"autocomplete",
|
||||
"editbar",
|
||||
"embedded",
|
||||
"entry",
|
||||
"chart",
|
||||
"caption",
|
||||
"document frame",
|
||||
"heading",
|
||||
"page",
|
||||
"section",
|
||||
"redundant object",
|
||||
"form",
|
||||
"link",
|
||||
"input method window",
|
||||
"table row",
|
||||
"tree item",
|
||||
"document spreadsheet",
|
||||
"document presentation",
|
||||
"document text",
|
||||
"document web",
|
||||
"document email",
|
||||
"comment",
|
||||
"list box",
|
||||
"grouping",
|
||||
"image map",
|
||||
"notification",
|
||||
"info bar",
|
||||
"level bar",
|
||||
"title bar",
|
||||
"block quote",
|
||||
"audio",
|
||||
"video",
|
||||
"definition",
|
||||
"article",
|
||||
"landmark",
|
||||
"log",
|
||||
"marquee",
|
||||
"math",
|
||||
"rating",
|
||||
"timer",
|
||||
"static",
|
||||
"math fraction",
|
||||
"math root",
|
||||
"subscript",
|
||||
"superscript",
|
||||
"description list",
|
||||
"description term",
|
||||
"description value",
|
||||
"footnote",
|
||||
"content deletion",
|
||||
"content insertion",
|
||||
"mark",
|
||||
"suggestion",
|
||||
"push button menu",
|
||||
];
|
||||
|
||||
impl Role {
|
||||
/// Get a readable, English name from the role.
|
||||
#[must_use]
|
||||
pub fn name(&self) -> &'static str {
|
||||
ROLE_NAMES[*self as usize]
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Role {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(self.name())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::Role;
|
||||
use zbus::wire::serialized::Context;
|
||||
use zbus::wire::{to_bytes, LE};
|
||||
|
||||
const HIGHEST_ROLE_VALUE: u32 = 129;
|
||||
|
||||
#[test]
|
||||
fn test_serialization_matches_from_impl() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
|
||||
for role_num in 1..=HIGHEST_ROLE_VALUE {
|
||||
let from_role = Role::try_from(role_num)
|
||||
.unwrap_or_else(|_| panic!("Unable to convert {role_num} into Role"));
|
||||
let encoded = to_bytes(ctxt, &from_role)
|
||||
.unwrap_or_else(|_| panic!("Unable to encode {from_role}"));
|
||||
println!("ENCODED: {encoded:?}");
|
||||
|
||||
let (zbus_role, _) = encoded
|
||||
.deserialize()
|
||||
.unwrap_or_else(|_| panic!("Unable to decode {encoded:?}"));
|
||||
|
||||
assert_eq!(from_role, zbus_role, "The serde `Data::deserialize` and `From<u32>` impls produced different results. The number used was {role_num}, it produced a Role of {from_role}, but the from_slice(...) implementation produced {zbus_role}");
|
||||
assert_eq!(
|
||||
from_role as u32, role_num,
|
||||
"The role number {role_num} does not match the representation of the role {}",
|
||||
from_role as u32
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
719
patches/atspi-common/src/state.rs
vendored
Normal file
719
patches/atspi-common/src/state.rs
vendored
Normal file
|
|
@ -0,0 +1,719 @@
|
|||
use enumflags2::{bitflags, BitFlag, BitFlags, FromBitsError};
|
||||
use serde::{
|
||||
de::{self, Deserializer, Visitor},
|
||||
ser::{SerializeSeq, Serializer},
|
||||
Deserialize, Serialize,
|
||||
};
|
||||
use std::{convert::Infallible, fmt, str::FromStr};
|
||||
use zbus::wire::{Signature, Type};
|
||||
|
||||
/// Used by various interfaces indicating every possible state
|
||||
/// of an accessibility object.
|
||||
#[bitflags]
|
||||
#[non_exhaustive]
|
||||
#[repr(u64)]
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum State {
|
||||
/// Indicates an invalid state - probably an error condition.
|
||||
#[default]
|
||||
Invalid,
|
||||
/// Indicates a window is currently the active window, or
|
||||
/// an object is the active subelement within a container or table.
|
||||
///
|
||||
/// `Active` should not be used for objects which have
|
||||
/// [`State::Focusable`] or [`State::Selectable`]: Those objects should use
|
||||
/// [`State::Focused`] and [`State::Selected`] respectively.
|
||||
///
|
||||
/// `Active` is a means to indicate that an object which is not
|
||||
/// focusable and not selectable is the currently-active item within its
|
||||
/// parent container.
|
||||
Active,
|
||||
/// Indicates that the object is armed.
|
||||
Armed,
|
||||
/// Indicates the current object is busy, i.e. onscreen
|
||||
/// representation is in the process of changing, or the object is
|
||||
/// temporarily unavailable for interaction due to activity already in progress.
|
||||
Busy,
|
||||
/// Indicates this object is currently checked.
|
||||
Checked,
|
||||
/// Indicates this object is collapsed.
|
||||
Collapsed,
|
||||
/// Indicates that this object no longer has a valid
|
||||
/// backing widget (for instance, if its peer object has been destroyed).
|
||||
Defunct,
|
||||
/// Indicates the user can change the contents of this object.
|
||||
Editable,
|
||||
/// Indicates that this object is enabled, i.e. that it
|
||||
/// currently reflects some application state. Objects that are "greyed out"
|
||||
/// may lack this state, and may lack the [`State::Sensitive`] if direct
|
||||
/// user interaction cannot cause them to acquire `Enabled`.
|
||||
///
|
||||
/// See [`State::Sensitive`].
|
||||
Enabled,
|
||||
/// Indicates this object allows progressive
|
||||
/// disclosure of its children.
|
||||
Expandable,
|
||||
/// Indicates this object is expanded.
|
||||
Expanded,
|
||||
/// Indicates this object can accept keyboard focus,
|
||||
/// which means all events resulting from typing on the keyboard will
|
||||
/// normally be passed to it when it has focus.
|
||||
Focusable,
|
||||
/// Indicates this object currently has the keyboard focus.
|
||||
Focused,
|
||||
/// Indicates that the object has an associated tooltip.
|
||||
HasTooltip,
|
||||
/// Indicates the orientation of this object is horizontal.
|
||||
Horizontal,
|
||||
/// Indicates this object is minimized and is
|
||||
/// represented only by an icon.
|
||||
Iconified,
|
||||
/// Indicates something must be done with this object
|
||||
/// before the user can interact with an object in a different window.
|
||||
Modal,
|
||||
/// Indicates this (text) object can contain multiple
|
||||
/// lines of text.
|
||||
MultiLine,
|
||||
/// Indicates this object allows more than one of
|
||||
/// its children to be selected at the same time, or in the case of text
|
||||
/// objects, that the object supports non-contiguous text selections.
|
||||
Multiselectable,
|
||||
/// Indicates this object paints every pixel within its
|
||||
/// rectangular region. It also indicates an alpha value of unity, if it
|
||||
/// supports alpha blending.
|
||||
Opaque,
|
||||
/// Indicates this object is currently pressed.
|
||||
Pressed,
|
||||
/// Indicates the size of this object's size is not fixed.
|
||||
Resizable,
|
||||
/// Indicates this object is the child of an object
|
||||
/// that allows its children to be selected and that this child is one of
|
||||
/// those children that can be selected.
|
||||
Selectable,
|
||||
/// Indicates this object is the child of an object that
|
||||
/// allows its children to be selected and that this child is one of those
|
||||
/// children that has been selected.
|
||||
Selected,
|
||||
/// Indicates this object is sensitive, e.g. to user
|
||||
/// interaction. `Sensitive` usually accompanies.
|
||||
/// [`State::Enabled`] for user-actionable controls, but may be found in the
|
||||
/// absence of [`State::Enabled`] if the current visible state of the control
|
||||
/// is "disconnected" from the application state. In such cases, direct user
|
||||
/// interaction can often result in the object gaining `Sensitive`,
|
||||
/// for instance if a user makes an explicit selection using an object whose
|
||||
/// current state is ambiguous or undefined.
|
||||
///
|
||||
/// See [`State::Enabled`], [`State::Indeterminate`].
|
||||
Sensitive,
|
||||
/// Indicates this object, the object's parent, the
|
||||
/// object's parent's parent, and so on, are all 'shown' to the end-user,
|
||||
/// i.e. subject to "exposure" if blocking or obscuring objects do not
|
||||
/// interpose between this object and the top of the window stack.
|
||||
Showing,
|
||||
/// Indicates this (text) object can contain only a
|
||||
/// single line of text.
|
||||
SingleLine,
|
||||
/// Indicates that the information returned for this object
|
||||
/// may no longer be synchronized with the application state. This can occur
|
||||
/// if the object has [`State::Transient`], and can also occur towards the
|
||||
/// end of the object peer's lifecycle.
|
||||
Stale,
|
||||
/// Indicates this object is transient.
|
||||
Transient,
|
||||
/// Indicates the orientation of this object is vertical;
|
||||
/// for example this state may appear on such objects as scrollbars, text
|
||||
/// objects (with vertical text flow), separators, etc.
|
||||
Vertical,
|
||||
/// Indicates this object is visible, e.g. has been
|
||||
/// explicitly marked for exposure to the user. `Visible` is no
|
||||
/// guarantee that the object is actually unobscured on the screen, only that
|
||||
/// it is 'potentially' visible, barring obstruction, being scrolled or clipped
|
||||
/// out of the field of view, or having an ancestor container that has not yet
|
||||
/// made visible. A widget is potentially onscreen if it has both
|
||||
/// `Visible` and [`State::Showing`]. The absence of
|
||||
/// `Visible` and [`State::Showing`] is
|
||||
/// semantically equivalent to saying that an object is 'hidden'.
|
||||
Visible,
|
||||
/// Indicates that "active-descendant-changed"
|
||||
/// event is sent when children become 'active' (i.e. are selected or
|
||||
/// navigated to onscreen). Used to prevent need to enumerate all children
|
||||
/// in very large containers, like tables. The presence of
|
||||
/// `ManagesDescendants` is an indication to the client that the
|
||||
/// children should not, and need not, be enumerated by the client.
|
||||
/// Objects implementing this state are expected to provide relevant state
|
||||
/// notifications to listening clients, for instance notifications of
|
||||
/// visibility changes and activation of their contained child objects, without
|
||||
/// the client having previously requested references to those children.
|
||||
ManagesDescendants,
|
||||
/// Indicates that a check box or other boolean
|
||||
/// indicator is in a state other than checked or not checked.
|
||||
///
|
||||
/// This usually means that the boolean value reflected or controlled by the
|
||||
/// object does not apply consistently to the entire current context.
|
||||
/// For example, a checkbox for the "Bold" attribute of text may have
|
||||
/// `Indeterminate` if the currently selected text contains a mixture
|
||||
/// of weight attributes. In many cases interacting with a
|
||||
/// `Indeterminate` object will cause the context's corresponding
|
||||
/// boolean attribute to be homogenized, whereupon the object will lose
|
||||
/// `Indeterminate` and a corresponding state-changed event will be
|
||||
/// fired.
|
||||
Indeterminate,
|
||||
/// Indicates that user interaction with this object is
|
||||
/// 'required' from the user, for instance before completing the
|
||||
/// processing of a form.
|
||||
Required,
|
||||
/// Indicates that an object's onscreen content
|
||||
/// is truncated, e.g. a text value in a spreadsheet cell.
|
||||
Truncated,
|
||||
/// Indicates this object's visual representation is
|
||||
/// dynamic, not static. This state may be applied to an object during an
|
||||
/// animated 'effect' and be removed from the object once its visual
|
||||
/// representation becomes static. Some applications, notably content viewers,
|
||||
/// may not be able to detect all kinds of animated content. Therefore the
|
||||
/// absence of this state should not be taken as
|
||||
/// definitive evidence that the object's visual representation is
|
||||
/// static; this state is advisory.
|
||||
Animated,
|
||||
/// This object has indicated an error condition
|
||||
/// due to failure of input validation. For instance, a form control may
|
||||
/// acquire this state in response to invalid or malformed user input.
|
||||
InvalidEntry,
|
||||
/// This state indicates that the object
|
||||
/// in question implements some form of typeahead or
|
||||
/// pre-selection behavior whereby entering the first character of one or more
|
||||
/// sub-elements causes those elements to scroll into view or become
|
||||
/// selected. Subsequent character input may narrow the selection further as
|
||||
/// long as one or more sub-elements match the string. This state is normally
|
||||
/// only useful and encountered on objects that implement [`crate::interface::Interface::Selection`].
|
||||
/// In some cases the typeahead behavior may result in full or partial
|
||||
/// completion of the data in the input field, in which case
|
||||
/// these input events may trigger text-changed events from the source.
|
||||
SupportsAutocompletion,
|
||||
/// Indicates that the object in
|
||||
/// question supports text selection. It should only be exposed on objects
|
||||
/// which implement the [`crate::interface::Interface::Text`] interface, in order to distinguish this state
|
||||
/// from [`State::Selectable`], which infers that the object in question is a
|
||||
/// selectable child of an object which implements [`crate::interface::Interface::Selection`]. While
|
||||
/// similar, text selection and subelement selection are distinct operations.
|
||||
SelectableText,
|
||||
/// Indicates that the object in question is
|
||||
/// the 'default' interaction object in a dialog, i.e. the one that gets
|
||||
/// activated if the user presses "Enter" when the dialog is initially
|
||||
/// posted.
|
||||
IsDefault,
|
||||
/// Indicates that the object (typically a
|
||||
/// hyperlink) has already been activated or invoked, with the result that
|
||||
/// some backing data has been downloaded or rendered.
|
||||
Visited,
|
||||
/// Indicates this object has the potential to
|
||||
/// be checked, such as a checkbox or toggle-able table cell.
|
||||
Checkable,
|
||||
/// Indicates that the object has a popup
|
||||
/// context menu or sub-level menu which may or may not be
|
||||
/// showing. This means that activation renders conditional content.
|
||||
/// Note that ordinary tooltips are not considered popups in this
|
||||
/// context.
|
||||
HasPopup,
|
||||
/// Indicates that an object which is [`State::Enabled`] and
|
||||
/// [`State::Sensitive`] has a value which can be read, but not modified, by the
|
||||
/// user.
|
||||
ReadOnly,
|
||||
}
|
||||
|
||||
impl State {
|
||||
// "Matches on enums with undeclared discriminants (such that the compiler can choose sequential values)
|
||||
// are optimized down to a jump table"
|
||||
// https://users.rust-lang.org/t/match-statement-efficiency/4488/2
|
||||
|
||||
/// Returns the state as a static string.
|
||||
#[must_use]
|
||||
pub fn to_static_str(&self) -> &'static str {
|
||||
match self {
|
||||
State::Invalid => "invalid",
|
||||
State::Active => "active",
|
||||
State::Armed => "armed",
|
||||
State::Busy => "busy",
|
||||
State::Checked => "checked",
|
||||
State::Collapsed => "collapsed",
|
||||
State::Defunct => "defunct",
|
||||
State::Editable => "editable",
|
||||
State::Enabled => "enabled",
|
||||
State::Expandable => "expandable",
|
||||
State::Expanded => "expanded",
|
||||
State::Focusable => "focusable",
|
||||
State::Focused => "focused",
|
||||
State::HasTooltip => "has-tooltip",
|
||||
State::Horizontal => "horizontal",
|
||||
State::Iconified => "iconified",
|
||||
State::Modal => "modal",
|
||||
State::MultiLine => "multi-line",
|
||||
State::Multiselectable => "multiselectable",
|
||||
State::Opaque => "opaque",
|
||||
State::Pressed => "pressed",
|
||||
State::Resizable => "resizable",
|
||||
State::Selectable => "selectable",
|
||||
State::Selected => "selected",
|
||||
State::Sensitive => "sensitive",
|
||||
State::Showing => "showing",
|
||||
State::SingleLine => "single-line",
|
||||
State::Stale => "stale",
|
||||
State::Transient => "transient",
|
||||
State::Vertical => "vertical",
|
||||
State::Visible => "visible",
|
||||
State::ManagesDescendants => "manages-descendants",
|
||||
State::Indeterminate => "indeterminate",
|
||||
State::Required => "required",
|
||||
State::Truncated => "truncated",
|
||||
State::Animated => "animated",
|
||||
State::InvalidEntry => "invalid-entry",
|
||||
State::SupportsAutocompletion => "supports-autocompletion",
|
||||
State::SelectableText => "selectable-text",
|
||||
State::IsDefault => "is-default",
|
||||
State::Visited => "visited",
|
||||
State::Checkable => "checkable",
|
||||
State::HasPopup => "has-popup",
|
||||
State::ReadOnly => "read-only",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for State {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(self.to_static_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for State {
|
||||
fn from(string: String) -> State {
|
||||
(&*string).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for State {
|
||||
type Err = Infallible;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for State {
|
||||
fn from(string: &str) -> State {
|
||||
match string {
|
||||
"active" => State::Active,
|
||||
"armed" => State::Armed,
|
||||
"busy" => State::Busy,
|
||||
"checked" => State::Checked,
|
||||
"collapsed" => State::Collapsed,
|
||||
"defunct" => State::Defunct,
|
||||
"editable" => State::Editable,
|
||||
"enabled" => State::Enabled,
|
||||
"expandable" => State::Expandable,
|
||||
"expanded" => State::Expanded,
|
||||
"focusable" => State::Focusable,
|
||||
"focused" => State::Focused,
|
||||
"has-tooltip" => State::HasTooltip,
|
||||
"horizontal" => State::Horizontal,
|
||||
"iconified" => State::Iconified,
|
||||
"modal" => State::Modal,
|
||||
"multi-line" => State::MultiLine,
|
||||
"multiselectable" => State::Multiselectable,
|
||||
"opaque" => State::Opaque,
|
||||
"pressed" => State::Pressed,
|
||||
"resizable" => State::Resizable,
|
||||
"selectable" => State::Selectable,
|
||||
"selected" => State::Selected,
|
||||
"sensitive" => State::Sensitive,
|
||||
"showing" => State::Showing,
|
||||
"single-line" => State::SingleLine,
|
||||
"stale" => State::Stale,
|
||||
"transient" => State::Transient,
|
||||
"vertical" => State::Vertical,
|
||||
"visible" => State::Visible,
|
||||
"manages-descendants" => State::ManagesDescendants,
|
||||
"indeterminate" => State::Indeterminate,
|
||||
"required" => State::Required,
|
||||
"truncated" => State::Truncated,
|
||||
"animated" => State::Animated,
|
||||
"invalid-entry" => State::InvalidEntry,
|
||||
"supports-autocompletion" => State::SupportsAutocompletion,
|
||||
"selectable-text" => State::SelectableText,
|
||||
"is-default" => State::IsDefault,
|
||||
"visited" => State::Visited,
|
||||
"checkable" => State::Checkable,
|
||||
"has-popup" => State::HasPopup,
|
||||
"read-only" => State::ReadOnly,
|
||||
_ => State::Invalid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
|
||||
/// The bitflag representation of all states an object may have.
|
||||
pub struct StateSet(BitFlags<State>);
|
||||
|
||||
impl StateSet {
|
||||
/// Create a new `StateSet`.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```rust
|
||||
/// # use atspi_common::{State, StateSet};
|
||||
/// let states = State::Focusable | State::Sensitive | State::Active;
|
||||
/// let set = StateSet::new(states);
|
||||
///
|
||||
/// assert!(set.contains(State::Active));
|
||||
/// assert!(!set.contains(State::Busy));
|
||||
/// ```
|
||||
pub fn new<B: Into<BitFlags<State>>>(value: B) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
|
||||
/// Returns the `StateSet` that corresponds to the provided `u64`s bit pattern.
|
||||
/// # Errors
|
||||
/// When the argument encodes an undefined [`State`].
|
||||
pub fn from_bits(bits: u64) -> Result<StateSet, FromBitsError<State>> {
|
||||
Ok(StateSet(BitFlags::from_bits(bits)?))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Create an empty `StateSet`
|
||||
pub fn empty() -> StateSet {
|
||||
StateSet(State::empty())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Returns the state as represented by a u64.
|
||||
pub fn bits(&self) -> u64 {
|
||||
self.0.bits()
|
||||
}
|
||||
|
||||
/// Whether the `StateSet` contains a [`State`].
|
||||
pub fn contains<B: Into<BitFlags<State>>>(self, other: B) -> bool {
|
||||
self.0.contains(other)
|
||||
}
|
||||
|
||||
/// Removes a [`State`] (optionally) previously contained in the `StateSet`.
|
||||
pub fn remove<B: Into<BitFlags<State>>>(&mut self, other: B) {
|
||||
self.0.remove(other);
|
||||
}
|
||||
|
||||
/// Inserts a [`State`] in the `StateSet`.
|
||||
pub fn insert<B: Into<BitFlags<State>>>(&mut self, other: B) {
|
||||
self.0.insert(other);
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields each set [`State`].
|
||||
#[must_use]
|
||||
pub fn iter(self) -> enumflags2::Iter<State> {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Checks if all states are unset.
|
||||
pub fn is_empty(self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
/// Returns true if at least one flag is shared.
|
||||
pub fn intersects<B: Into<BitFlags<State>>>(self, other: B) -> bool {
|
||||
self.0.intersects(other)
|
||||
}
|
||||
|
||||
/// Toggles the matching bits.
|
||||
pub fn toggle<B: Into<BitFlags<State>>>(&mut self, other: B) {
|
||||
self.0.toggle(other);
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for StateSet {
|
||||
type IntoIter = enumflags2::Iter<State>;
|
||||
type Item = State;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for &StateSet {
|
||||
type IntoIter = enumflags2::Iter<State>;
|
||||
type Item = State;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<State> for StateSet {
|
||||
fn from_iter<I: IntoIterator<Item = State>>(iter: I) -> Self {
|
||||
StateSet(iter.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromIterator<&'a State> for StateSet {
|
||||
fn from_iter<I: IntoIterator<Item = &'a State>>(iter: I) -> Self {
|
||||
StateSet(iter.into_iter().copied().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for StateSet {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct StateSetVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for StateSetVisitor {
|
||||
type Value = StateSet;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter
|
||||
.write_str("a sequence comprised of two u32 that represents a valid StateSet")
|
||||
}
|
||||
|
||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
match <Vec<u32> as Deserialize>::deserialize(deserializer) {
|
||||
Ok(states) if states.len() == 2 => {
|
||||
let mut bits = u64::from(states[0]);
|
||||
bits |= (u64::from(states[1])) << 32;
|
||||
StateSet::from_bits(bits).map_err(|_| de::Error::custom("invalid state"))
|
||||
}
|
||||
Ok(states) => Err(de::Error::invalid_length(states.len(), &"array of size 2")),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_newtype_struct("StateSet", StateSetVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for StateSet {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut seq = serializer.serialize_seq(Some(2))?;
|
||||
let bits = self.bits();
|
||||
|
||||
// This cast is safe and truncation is intentional.
|
||||
//The shift is sound provided that `State` is `#[repr(u64)]`
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
seq.serialize_element(&(bits as u32))?;
|
||||
seq.serialize_element(&((bits >> 32) as u32))?;
|
||||
seq.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl Type for StateSet {
|
||||
const SIGNATURE: &'static Signature = <Vec<u32> as Type>::SIGNATURE;
|
||||
}
|
||||
|
||||
impl From<State> for StateSet {
|
||||
fn from(value: State) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::BitXor for StateSet {
|
||||
type Output = StateSet;
|
||||
|
||||
fn bitxor(self, other: Self) -> Self::Output {
|
||||
StateSet(self.0 ^ other.0)
|
||||
}
|
||||
}
|
||||
impl std::ops::BitXorAssign for StateSet {
|
||||
fn bitxor_assign(&mut self, other: Self) {
|
||||
self.0 = self.0 ^ other.0;
|
||||
}
|
||||
}
|
||||
impl std::ops::BitOr for StateSet {
|
||||
type Output = StateSet;
|
||||
|
||||
fn bitor(self, other: Self) -> Self::Output {
|
||||
StateSet(self.0 | other.0)
|
||||
}
|
||||
}
|
||||
impl std::ops::BitOrAssign for StateSet {
|
||||
fn bitor_assign(&mut self, other: Self) {
|
||||
self.0 = self.0 | other.0;
|
||||
}
|
||||
}
|
||||
impl std::ops::BitAnd for StateSet {
|
||||
type Output = StateSet;
|
||||
|
||||
fn bitand(self, other: Self) -> Self::Output {
|
||||
StateSet(self.0 & other.0)
|
||||
}
|
||||
}
|
||||
impl std::ops::BitAndAssign for StateSet {
|
||||
fn bitand_assign(&mut self, other: Self) {
|
||||
self.0 = self.0 & other.0;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{State, StateSet};
|
||||
use zbus::wire::serialized::{Context, Data};
|
||||
use zbus::wire::{to_bytes, LE};
|
||||
|
||||
#[test]
|
||||
fn serialize_empty_state_set() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &StateSet::empty()).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_empty_state_set() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ctxt);
|
||||
let (decoded, _) = data.deserialize::<StateSet>().unwrap();
|
||||
assert_eq!(decoded, StateSet::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_state_set_invalid() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &StateSet::new(State::Invalid)).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_state_set_invalid() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], ctxt);
|
||||
let (decoded, _) = data.deserialize::<StateSet>().unwrap();
|
||||
assert_eq!(decoded, StateSet::new(State::Invalid));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_state_set_manages_descendants() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &StateSet::new(State::ManagesDescendants)).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[8, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_state_set_manages_descendants() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0], ctxt);
|
||||
let (decoded, _) = data.deserialize::<StateSet>().unwrap();
|
||||
assert_eq!(decoded, StateSet::new(State::ManagesDescendants));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_state_set_indeterminate() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &StateSet::new(State::Indeterminate)).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_state_set_indeterminate() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], ctxt);
|
||||
let (decoded, _) = data.deserialize::<StateSet>().unwrap();
|
||||
assert_eq!(decoded, StateSet::new(State::Indeterminate));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_state_set_focusable_focused() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let encoded = to_bytes(ctxt, &StateSet::new(State::Focusable | State::Focused)).unwrap();
|
||||
assert_eq!(encoded.bytes(), &[8, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_state_set_focusable_focused() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0], ctxt);
|
||||
let (decoded, _) = data.deserialize::<StateSet>().unwrap();
|
||||
assert_eq!(decoded, StateSet::new(State::Focusable | State::Focused));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_deserialize_state_set_invalid_length() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ctxt);
|
||||
let decode_result = data.deserialize::<StateSet>();
|
||||
assert!(decode_result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_deserialize_state_set_invalid_flag() {
|
||||
let ctxt = Context::new(LE, 0);
|
||||
let data = Data::new::<&[u8]>(&[8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32], ctxt);
|
||||
let decode_result = data.deserialize::<StateSet>();
|
||||
assert!(decode_result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_state_direct_string() {
|
||||
for state in
|
||||
StateSet::from_bits(0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111).unwrap()
|
||||
{
|
||||
let state_str: String = state.to_string();
|
||||
let state_two: State = state_str.clone().into();
|
||||
assert_eq!(
|
||||
state, state_two,
|
||||
"The {state:?} was serialized as {state_str}, which deserializes to {state_two:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn convert_state_direct_string_is_equal_to_serde_output() {
|
||||
for state in
|
||||
StateSet::from_bits(0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111).unwrap()
|
||||
{
|
||||
let serde_state_str: String = serde_plain::to_string(&state).unwrap();
|
||||
let state_str: String = state.to_string();
|
||||
assert_eq!(serde_state_str, state_str);
|
||||
let state_two: State = serde_plain::from_str(&state_str).unwrap();
|
||||
assert_eq!(state, state_two, "The {state:?} was serialized as {state_str}, which deserializes to {state_two:?} (serde)");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_stateset_from_owned_states() {
|
||||
let states = vec![State::Active, State::Focused, State::Focusable];
|
||||
let set = StateSet::from_iter(states);
|
||||
assert!(set.contains(State::Active));
|
||||
assert!(set.contains(State::Focused));
|
||||
assert!(set.contains(State::Focusable));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_stateset_from_borrowed_states() {
|
||||
// &[T].iter() yields &T
|
||||
let states = &[State::Active, State::Focused, State::Focusable];
|
||||
let set = states.iter().collect::<StateSet>();
|
||||
assert!(set.contains(State::Active));
|
||||
assert!(set.contains(State::Focused));
|
||||
assert!(set.contains(State::Focusable));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_iterator_owned_stateset() {
|
||||
let set = StateSet::new(State::Active | State::Focused | State::Focusable);
|
||||
let states: Vec<State> = set.into_iter().collect();
|
||||
assert_eq!(states.len(), 3);
|
||||
assert!(states.contains(&State::Active));
|
||||
assert!(states.contains(&State::Focused));
|
||||
assert!(states.contains(&State::Focusable));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_iterator_borrowed_stateset() {
|
||||
let set = StateSet::new(State::Active | State::Focused | State::Focusable);
|
||||
let states: Vec<State> = (&set).into_iter().collect();
|
||||
assert_eq!(states.len(), 3);
|
||||
assert!(states.contains(&State::Active));
|
||||
assert!(states.contains(&State::Focused));
|
||||
assert!(states.contains(&State::Focusable));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue