[gtk/a11y/atspi: 30/30] a11y: Convenience API for referencing ATSPI root node




commit 3b92caba7d62b00a75adc559b1ff59fc8d371a49
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Sat Oct 10 13:23:21 2020 +0100

    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.

 gtk/a11y/gtkatspicontext.c     | 12 +++---------
 gtk/a11y/gtkatspiroot.c        | 25 ++++++++++++++++---------
 gtk/a11y/gtkatspirootprivate.h |  6 ++----
 3 files changed, 21 insertions(+), 22 deletions(-)
---
diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c
index c1448b6e22..1567a665d2 100644
--- a/gtk/a11y/gtkatspicontext.c
+++ b/gtk/a11y/gtkatspicontext.c
@@ -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
         {
diff --git a/gtk/a11y/gtkatspiroot.c b/gtk/a11y/gtkatspiroot.c
index 2330852a58..a3b3a4f9fb 100644
--- a/gtk/a11y/gtkatspiroot.c
+++ b/gtk/a11y/gtkatspiroot.c
@@ -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 (self->desktop_path == NULL)
+    return gtk_at_spi_null_ref ();
 
-  if (name != NULL)
-    *name = self->desktop_name;
-  if (path != NULL)
-    *path = self->desktop_path;
+  return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
 }
diff --git a/gtk/a11y/gtkatspirootprivate.h b/gtk/a11y/gtkatspirootprivate.h
index 268c8a161f..0ce5e6b693 100644
--- a/gtk/a11y/gtkatspirootprivate.h
+++ b/gtk/a11y/gtkatspirootprivate.h
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]