atspi_common/
cache.rs

1//! Common types for `org.a11y.atspi.Cache` events.
2//!
3
4use crate::{object_ref::ObjectRefOwned, InterfaceSet, ObjectRef, Role, StateSet};
5use serde::{Deserialize, Serialize};
6use zbus_lockstep_macros::validate;
7use zvariant::Type;
8
9/// The item type provided by `Cache:Add` signals
10#[allow(clippy::module_name_repetitions)]
11#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
12#[validate(signal: "AddAccessible")]
13pub struct CacheItem {
14	/// The accessible object (within the application)   (so)
15	pub object: ObjectRefOwned,
16	/// The application (root object(?)    (so)
17	pub app: ObjectRefOwned,
18	/// The parent object.  (so)
19	pub parent: ObjectRefOwned,
20	/// The accessbile index in parent.  i
21	pub index: i32,
22	/// Child count of the accessible  i
23	pub children: i32,
24	/// The exposed interface(s) set.  as
25	pub ifaces: InterfaceSet,
26	/// The short localized name.  s
27	pub short_name: String,
28	/// `ObjectRef` role. u
29	pub role: Role,
30	/// More detailed localized name.
31	pub name: String,
32	/// The states applicable to the accessible.  au
33	pub states: StateSet,
34}
35
36impl Default for CacheItem {
37	fn default() -> Self {
38		Self {
39			object: ObjectRefOwned::from_static_str_unchecked(
40				":0.0",
41				"/org/a11y/atspi/accessible/object",
42			),
43			app: ObjectRefOwned::from_static_str_unchecked(
44				":0.0",
45				"/org/a11y/atspi/accessible/application",
46			),
47			parent: ObjectRefOwned::from_static_str_unchecked(
48				":0.0",
49				"/org/a11y/atspi/accessible/parent",
50			),
51			index: 0,
52			children: 0,
53			ifaces: InterfaceSet::empty(),
54			short_name: String::default(),
55			role: Role::Invalid,
56			name: String::default(),
57			states: StateSet::empty(),
58		}
59	}
60}
61
62/// The item type provided by `Cache:Add` signals
63#[allow(clippy::module_name_repetitions)]
64#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
65pub struct LegacyCacheItem {
66	/// The accessible object (within the application)   (so)
67	pub object: ObjectRefOwned,
68	/// The application (root object(?)    (so)
69	pub app: ObjectRefOwned,
70	/// The parent object.  (so)
71	pub parent: ObjectRefOwned,
72	/// List of references to the accessible's children.  a(so)
73	pub children: Vec<ObjectRefOwned>,
74	/// The exposed interface(s) set.  as
75	pub ifaces: InterfaceSet,
76	/// The short localized name.  s
77	pub short_name: String,
78	/// `ObjectRef` role. u
79	pub role: Role,
80	/// More detailed localized name.
81	pub name: String,
82	/// The states applicable to the accessible.  au
83	pub states: StateSet,
84}
85
86impl Default for LegacyCacheItem {
87	fn default() -> Self {
88		Self {
89			object: ObjectRef::from_static_str_unchecked(
90				":0.0",
91				"/org/a11y/atspi/accessible/object",
92			)
93			.into(),
94			app: ObjectRef::from_static_str_unchecked(
95				":0.0",
96				"/org/a11y/atspi/accessible/application",
97			)
98			.into(),
99			parent: ObjectRef::from_static_str_unchecked(
100				":0.0",
101				"/org/a11y/atspi/accessible/parent",
102			)
103			.into(),
104			children: Vec::new(),
105			ifaces: InterfaceSet::empty(),
106			short_name: String::default(),
107			role: Role::Invalid,
108			name: String::default(),
109			states: StateSet::empty(),
110		}
111	}
112}
113
114#[cfg(test)]
115#[test]
116fn zvariant_type_signature_of_legacy_cache_item() {
117	use std::str::FromStr;
118	assert_eq!(
119		*<LegacyCacheItem as Type>::SIGNATURE,
120		zbus::zvariant::Signature::from_str("((so)(so)(so)a(so)assusau)").unwrap()
121	);
122}