Skip to content

Commit

Permalink
fix: Return a null object for AT-SPI application's parent (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny authored Sep 23, 2024
1 parent 119aa1d commit 8a84abf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
17 changes: 6 additions & 11 deletions platforms/unix/src/atspi/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,15 @@ impl Bus {
.at(path.clone(), ApplicationInterface(node.clone()))
.await?
{
let desktop = self
.socket_proxy
self.socket_proxy
.embed(&(self.unique_name().as_str(), ObjectId::Root.path().into()))
.await?;

self.conn
.object_server()
.at(
path,
RootAccessibleInterface::new(
self.unique_name().to_owned(),
desktop.into(),
node,
),
RootAccessibleInterface::new(self.unique_name().to_owned(), node),
)
.await?;
}
Expand Down Expand Up @@ -230,7 +225,7 @@ impl Bus {
kind: "",
detail1: 0,
detail2: 0,
any_data: child.to_address(self.unique_name().clone()).into(),
any_data: child.to_address(self.unique_name().inner()).into(),
properties,
},
)
Expand Down Expand Up @@ -294,7 +289,7 @@ impl Bus {
kind: "add",
detail1: index as i32,
detail2: 0,
any_data: child.to_address(self.unique_name().clone()).into(),
any_data: child.to_address(self.unique_name().inner()).into(),
properties,
},
)
Expand All @@ -313,7 +308,7 @@ impl Bus {
kind: "remove",
detail1: -1,
detail2: 0,
any_data: child.to_address(self.unique_name().clone()).into(),
any_data: child.to_address(self.unique_name().inner()).into(),
properties,
},
)
Expand Down Expand Up @@ -345,7 +340,7 @@ impl Bus {
},
NodeIdOrRoot::Root => ObjectId::Root,
};
parent.to_address(self.unique_name().clone()).into()
parent.to_address(self.unique_name().inner()).into()
}
Property::Role(value) => Value::U32(value as u32),
Property::Value(value) => Value::F64(value),
Expand Down
25 changes: 8 additions & 17 deletions platforms/unix/src/atspi/interfaces/accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl NodeAccessibleInterface {
},
NodeIdOrRoot::Root => ObjectId::Root,
}
.to_address(self.bus_name.clone())
.to_address(self.bus_name.inner())
})
}

Expand Down Expand Up @@ -90,7 +90,7 @@ impl NodeAccessibleInterface {
adapter: self.node.adapter_id(),
node: child,
}
.to_address(self.bus_name.clone())
.to_address(self.bus_name.inner())
})
.map_err(self.map_error())
}
Expand All @@ -116,7 +116,7 @@ impl NodeAccessibleInterface {
}

fn get_application(&self) -> (OwnedObjectAddress,) {
(ObjectId::Root.to_address(self.bus_name.clone()),)
(ObjectId::Root.to_address(self.bus_name.inner()),)
}

fn get_interfaces(&self) -> fdo::Result<InterfaceSet> {
Expand All @@ -126,21 +126,12 @@ impl NodeAccessibleInterface {

pub(crate) struct RootAccessibleInterface {
bus_name: OwnedUniqueName,
desktop_address: OwnedObjectAddress,
root: PlatformRoot,
}

impl RootAccessibleInterface {
pub fn new(
bus_name: OwnedUniqueName,
desktop_address: OwnedObjectAddress,
root: PlatformRoot,
) -> Self {
Self {
bus_name,
desktop_address,
root,
}
pub fn new(bus_name: OwnedUniqueName, root: PlatformRoot) -> Self {
Self { bus_name, root }
}
}

Expand All @@ -158,7 +149,7 @@ impl RootAccessibleInterface {

#[dbus_interface(property)]
fn parent(&self) -> OwnedObjectAddress {
self.desktop_address.clone()
OwnedObjectAddress::null()
}

#[dbus_interface(property)]
Expand Down Expand Up @@ -191,7 +182,7 @@ impl RootAccessibleInterface {
fn get_children(&self) -> fdo::Result<Vec<OwnedObjectAddress>> {
self.root
.map_child_ids(|(adapter, node)| {
ObjectId::Node { adapter, node }.to_address(self.bus_name.clone())
ObjectId::Node { adapter, node }.to_address(self.bus_name.inner())
})
.map_err(map_root_error)
}
Expand All @@ -209,7 +200,7 @@ impl RootAccessibleInterface {
}

fn get_application(&self) -> (OwnedObjectAddress,) {
(ObjectId::Root.to_address(self.bus_name.clone()),)
(ObjectId::Root.to_address(self.bus_name.inner()),)
}

fn get_interfaces(&self) -> InterfaceSet {
Expand Down
7 changes: 3 additions & 4 deletions platforms/unix/src/atspi/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ mod text;
mod value;

use crate::atspi::{ObjectId, OwnedObjectAddress};
use zbus::{fdo, names::OwnedUniqueName};
use zbus::{fdo, names::UniqueName};

fn map_root_error(error: accesskit_atspi_common::Error) -> fdo::Error {
crate::util::map_error(ObjectId::Root, error)
}

fn optional_object_address(
bus_name: &OwnedUniqueName,
bus_name: &UniqueName,
object_id: Option<ObjectId>,
) -> (OwnedObjectAddress,) {
let bus_name = bus_name.clone();
match object_id {
Some(id) => (id.to_address(bus_name),),
None => (OwnedObjectAddress::null(bus_name),),
None => (OwnedObjectAddress::null(),),
}
}

Expand Down
17 changes: 10 additions & 7 deletions platforms/unix/src/atspi/object_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@
use atspi::Accessible;
use serde::{Deserialize, Serialize};
use zbus::{
names::{OwnedUniqueName, UniqueName},
names::UniqueName,
zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value},
};

const NULL_PATH: &str = "/org/a11y/atspi/null";

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, OwnedValue, Type, Value)]
pub(crate) struct OwnedObjectAddress {
bus_name: OwnedUniqueName,
bus_name: String,
path: OwnedObjectPath,
}

impl OwnedObjectAddress {
pub(crate) fn new(bus_name: OwnedUniqueName, path: OwnedObjectPath) -> Self {
Self { bus_name, path }
pub(crate) fn new(bus_name: &UniqueName, path: OwnedObjectPath) -> Self {
Self {
bus_name: bus_name.to_string(),
path,
}
}

pub(crate) fn null(bus_name: OwnedUniqueName) -> Self {
pub(crate) fn null() -> Self {
Self {
bus_name,
bus_name: String::new(),
path: ObjectPath::from_str_unchecked(NULL_PATH).into(),
}
}
Expand All @@ -34,7 +37,7 @@ impl OwnedObjectAddress {
impl From<Accessible> for OwnedObjectAddress {
fn from(object: Accessible) -> Self {
Self {
bus_name: OwnedUniqueName::from(UniqueName::from_string_unchecked(object.name)),
bus_name: object.name,
path: object.path,
}
}
Expand Down
4 changes: 2 additions & 2 deletions platforms/unix/src/atspi/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use accesskit::NodeId;
use accesskit_atspi_common::PlatformNode;
use serde::{Serialize, Serializer};
use zbus::{
names::OwnedUniqueName,
names::UniqueName,
zvariant::{ObjectPath, OwnedObjectPath, Signature, Structure, StructureBuilder, Type},
};

Expand All @@ -22,7 +22,7 @@ pub(crate) enum ObjectId {
}

impl ObjectId {
pub(crate) fn to_address(&self, bus_name: OwnedUniqueName) -> OwnedObjectAddress {
pub(crate) fn to_address(&self, bus_name: &UniqueName) -> OwnedObjectAddress {
OwnedObjectAddress::new(bus_name, self.path())
}

Expand Down

0 comments on commit 8a84abf

Please sign in to comment.