[gtk/ebassi/for-master: 2/6] a11y: Compute the base path in the root object
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/ebassi/for-master: 2/6] a11y: Compute the base path in the root object
- Date: Mon, 16 Nov 2020 16:45:34 +0000 (UTC)
commit eec92b40ea22f48839f680cfa9729e30737b6f01
Author: Emmanuele Bassi <ebassi gnome org>
Date: Mon Nov 16 14:17:28 2020 +0000
a11y: Compute the base path in the root object
The root path is shared by all AtSpiContext instances, so we should
compute it once, instead of every time we instantiate a new context.
This allows us to defer the path creation at realization time and ensure
that we have a registered application.
gtk/a11y/gtkatspicontext.c | 61 +++++++++++++++---------------------------
gtk/a11y/gtkatspiroot.c | 32 ++++++++++++++++++++++
gtk/a11y/gtkatspirootprivate.h | 3 +++
3 files changed, 57 insertions(+), 39 deletions(-)
---
diff --git a/gtk/a11y/gtkatspicontext.c b/gtk/a11y/gtkatspicontext.c
index 4dad9863dd..735b661945 100644
--- a/gtk/a11y/gtkatspicontext.c
+++ b/gtk/a11y/gtkatspicontext.c
@@ -1458,45 +1458,6 @@ gtk_at_spi_context_constructed (GObject *gobject)
/* Make sure that we were properly constructed */
g_assert (self->bus_address);
- /* We use the application's object path to build the path of each
- * accessible object exposed on the accessibility bus; the path is
- * also used to access the object cache
- */
- GApplication *application = g_application_get_default ();
- char *base_path = NULL;
-
- if (application != NULL)
- {
- const char *app_path = g_application_get_dbus_object_path (application);
- base_path = g_strconcat (app_path, "/a11y", NULL);
- }
- else
- {
- char *uuid = g_uuid_string_random ();
- base_path = g_strconcat ("/org/gtk/application/", uuid, "/a11y", NULL);
- g_free (uuid);
- }
-
- /* We use a unique id to ensure that we don't have conflicting
- * objects on the bus
- */
- char *uuid = g_uuid_string_random ();
-
- self->context_path = g_strconcat (base_path, "/", uuid, NULL);
-
- /* UUIDs use '-' as the separator, but that's not a valid character
- * for a DBus object path
- */
- size_t path_len = strlen (self->context_path);
- for (size_t i = 0; i < path_len; i++)
- {
- if (self->context_path[i] == '-')
- self->context_path[i] = '_';
- }
-
- g_free (base_path);
- g_free (uuid);
-
G_OBJECT_CLASS (gtk_at_spi_context_parent_class)->constructed (gobject);
}
@@ -1526,6 +1487,22 @@ gtk_at_spi_context_realize (GtkATContext *context)
g_object_ref (self->root);
}
+ /* UUIDs use '-' as the separator, but that's not a valid character
+ * for a DBus object path
+ */
+ char *uuid = g_uuid_string_random ();
+ size_t len = strlen (uuid);
+ for (size_t i = 0; i < len; i++)
+ {
+ if (uuid[i] == '-')
+ uuid[i] = '_';
+ }
+
+ self->context_path =
+ g_strconcat (gtk_at_spi_root_get_base_path (self->root), "/", uuid, NULL);
+
+ g_free (uuid);
+
self->connection = gtk_at_spi_root_get_connection (self->root);
if (self->connection == NULL)
return;
@@ -1812,7 +1789,13 @@ gtk_at_spi_context_get_context_path (GtkAtSpiContext *self)
GVariant *
gtk_at_spi_context_to_ref (GtkAtSpiContext *self)
{
+ g_return_val_if_fail (GTK_IS_AT_SPI_CONTEXT (self), NULL);
+
+ if (self->context_path == NULL)
+ return gtk_at_spi_null_ref ();
+
const char *name = g_dbus_connection_get_unique_name (self->connection);
+
return g_variant_new ("(so)", name, self->context_path);
}
/* }}} */
diff --git a/gtk/a11y/gtkatspiroot.c b/gtk/a11y/gtkatspiroot.c
index e9a174990e..583371bcec 100644
--- a/gtk/a11y/gtkatspiroot.c
+++ b/gtk/a11y/gtkatspiroot.c
@@ -51,6 +51,8 @@ struct _GtkAtSpiRoot
char *bus_address;
GDBusConnection *connection;
+ char *base_path;
+
const char *root_path;
const char *toolkit_name;
@@ -87,6 +89,7 @@ gtk_at_spi_root_finalize (GObject *gobject)
g_clear_handle_id (&self->register_id, g_source_remove);
g_free (self->bus_address);
+ g_free (self->base_path);
g_free (self->desktop_name);
g_free (self->desktop_path);
@@ -613,6 +616,27 @@ gtk_at_spi_root_constructed (GObject *gobject)
goto out;
}
+ /* We use the application's object path to build the path of each
+ * accessible object exposed on the accessibility bus; the path is
+ * also used to access the object cache
+ */
+ GApplication *application = g_application_get_default ();
+
+ if (application != NULL && g_application_get_is_registered (application))
+ {
+ const char *app_path = g_application_get_dbus_object_path (application);
+
+ self->base_path = g_strconcat (app_path, "/a11y", NULL);
+ }
+ else
+ {
+ self->base_path = g_strconcat ("/org/gtk/application/",
+ g_get_prgname (),
+ "/a11y",
+ NULL);
+ }
+
+
out:
G_OBJECT_CLASS (gtk_at_spi_root_parent_class)->constructed (gobject);
}
@@ -687,3 +711,11 @@ gtk_at_spi_root_to_ref (GtkAtSpiRoot *self)
return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
}
+
+const char *
+gtk_at_spi_root_get_base_path (GtkAtSpiRoot *self)
+{
+ g_return_val_if_fail (GTK_IS_AT_SPI_ROOT (self), NULL);
+
+ return self->base_path;
+}
diff --git a/gtk/a11y/gtkatspirootprivate.h b/gtk/a11y/gtkatspirootprivate.h
index 7a99e7c254..15a6b48548 100644
--- a/gtk/a11y/gtkatspirootprivate.h
+++ b/gtk/a11y/gtkatspirootprivate.h
@@ -42,6 +42,9 @@ gtk_at_spi_root_get_connection (GtkAtSpiRoot *self);
GtkAtSpiCache *
gtk_at_spi_root_get_cache (GtkAtSpiRoot *self);
+const char *
+gtk_at_spi_root_get_base_path (GtkAtSpiRoot *self);
+
GVariant *
gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]