VNOX-Client/patches/accesskit_unix/src/atspi/object_id.rs
loki5512344 8e5ab56611
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.
2026-10-24 14:23:48 +02:00

79 lines
2.2 KiB
Rust
Vendored

// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.
use crate::atspi::OwnedObjectAddress;
use accesskit_atspi_common::{NodeId, PlatformNode};
use serde::{Serialize, Serializer};
use zbus::{
names::UniqueName,
wire::{ObjectPath, OwnedObjectPath, Signature, Structure, Type},
};
const ACCESSIBLE_PATH_PREFIX: &str = "/org/a11y/atspi/accessible/";
const ROOT_PATH: &str = "/org/a11y/atspi/accessible/root";
const CACHE_PATH: &str = "/org/a11y/atspi/cache";
pub(crate) fn cache_path() -> OwnedObjectPath {
ObjectPath::from_str_unchecked(CACHE_PATH).into()
}
#[derive(Debug, PartialEq)]
pub(crate) enum ObjectId {
Root,
Node { adapter: usize, node: NodeId },
}
impl ObjectId {
pub(crate) fn to_address(&self, bus_name: &UniqueName) -> OwnedObjectAddress {
OwnedObjectAddress::new(bus_name, self.path())
}
pub(crate) fn path(&self) -> OwnedObjectPath {
match self {
Self::Root => ObjectPath::from_str_unchecked(ROOT_PATH),
Self::Node { adapter, node } => ObjectPath::from_string_unchecked(format!(
"{}{}/{}",
ACCESSIBLE_PATH_PREFIX,
adapter,
u128::from(*node)
)),
}
.into()
}
}
impl Serialize for ObjectId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::Root => serializer.serialize_str("root"),
Self::Node { node, .. } => serializer.serialize_str(&u128::from(*node).to_string()),
}
}
}
impl Type for ObjectId {
const SIGNATURE: &'static Signature = <&str>::SIGNATURE;
}
impl From<ObjectId> for Structure<'_> {
fn from(id: ObjectId) -> Self {
Self::from((match id {
ObjectId::Root => "root".into(),
ObjectId::Node { node, .. } => u128::from(node).to_string(),
},))
}
}
impl From<&PlatformNode> for ObjectId {
fn from(node: &PlatformNode) -> Self {
Self::Node {
adapter: node.adapter_id(),
node: node.id(),
}
}
}