a11y: Convenience API for referencing ATSPI root node

We turn the root node into a reference fairly often, so it's worth it to
have a utility function that does this for us.
This commit is contained in:
Emmanuele Bassi 2020-10-10 13:23:21 +01:00
parent 35163bd7cc
commit 9ce790032d
3 changed files with 21 additions and 22 deletions

View File

@ -279,11 +279,8 @@ handle_accessible_method (GDBusConnection *connection,
}
else if (g_strcmp0 (method_name, "GetApplication") == 0)
{
const char *name, *path;
gtk_at_spi_root_get_application (self->root, &name, &path);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("((so))", name, path));
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("((so))", gtk_at_spi_root_to_ref (self->root)));
}
else if (g_strcmp0 (method_name, "GetChildAtIndex") == 0)
{
@ -409,10 +406,7 @@ handle_accessible_get_property (GDBusConnection *connection,
if (parent == NULL)
{
const char *name, *path;
gtk_at_spi_root_get_application (self->root, &name, &path);
res = g_variant_new ("(so)", name, path);
res = gtk_at_spi_root_to_ref (self->root);
}
else
{

View File

@ -24,6 +24,7 @@
#include "gtkatspicontextprivate.h"
#include "gtkatspiprivate.h"
#include "gtkatspiutilsprivate.h"
#include "gtkdebug.h"
#include "gtkwindow.h"
@ -568,15 +569,21 @@ gtk_at_spi_root_get_cache (GtkAtSpiRoot *self)
return self->cache;
}
void
gtk_at_spi_root_get_application (GtkAtSpiRoot *self,
const char **name,
const char **path)
/*< private >
* gtk_at_spi_root_to_ref:
* @self: a #GtkAtSpiRoot
*
* Returns an ATSPI object reference for the #GtkAtSpiRoot node.
*
* Returns: (transfer floating): a #GVariant with the root reference
*/
GVariant *
gtk_at_spi_root_to_ref (GtkAtSpiRoot *self)
{
g_return_if_fail (GTK_IS_AT_SPI_ROOT (self));
g_return_val_if_fail (GTK_IS_AT_SPI_ROOT (self), NULL);
if (name != NULL)
*name = self->desktop_name;
if (path != NULL)
*path = self->desktop_path;
if (self->desktop_path == NULL)
return gtk_at_spi_null_ref ();
return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
}

View File

@ -39,9 +39,7 @@ gtk_at_spi_root_get_connection (GtkAtSpiRoot *self);
GtkAtSpiCache *
gtk_at_spi_root_get_cache (GtkAtSpiRoot *self);
void
gtk_at_spi_root_get_application (GtkAtSpiRoot *self,
const char **name,
const char **path);
GVariant *
gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
G_END_DECLS