diff --git a/pressure-vessel/flatpak-run-dbus.c b/pressure-vessel/flatpak-run-dbus.c index 5fd802dd66409aa3dc91fee9d3357eadead4cddf..4eed6dbed1de605eac9ab3480053b536d7fbb30e 100644 --- a/pressure-vessel/flatpak-run-dbus.c +++ b/pressure-vessel/flatpak-run-dbus.c @@ -419,6 +419,7 @@ flatpak_run_add_a11y_dbus_args (FlatpakBwrap *app_bwrap, g_autoptr(GDBusMessage) reply = NULL; g_autoptr(GDBusMessage) msg = NULL; g_autofree char *proxy_socket = NULL; + const char *value; if ((flags & FLATPAK_RUN_FLAG_NO_A11Y_BUS_PROXY) != 0) return FALSE; @@ -427,26 +428,45 @@ flatpak_run_add_a11y_dbus_args (FlatpakBwrap *app_bwrap, if (session_bus == NULL) return FALSE; - msg = g_dbus_message_new_method_call ("org.a11y.Bus", "/org/a11y/bus", "org.a11y.Bus", "GetAddress"); - g_dbus_message_set_body (msg, g_variant_new ("()")); - reply = - g_dbus_connection_send_message_with_reply_sync (session_bus, msg, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - 30000, - NULL, - NULL, - NULL); - if (reply) + value = g_getenv ("AT_SPI_BUS_ADDRESS"); + + if (value != NULL && value[0] != '\0') { - if (g_dbus_message_to_gerror (reply, &local_error)) - { - if (!g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) - g_message ("Can't find a11y bus: %s", local_error->message); - } - else + a11y_address = g_strdup (value); + g_debug ("Retrieved AT-SPI bus address \"%s\" from environment", + a11y_address); + } + + /* To have an accurate emulation of AT-SPI's behaviour, ideally we would + * also query the AT_SPI_BUS atom on the root window if a11y_address is + * still NULL here, but that would require a libX11 dependency, and + * isn't done when running under native Wayland anyway. */ + + if (a11y_address == NULL) + { + msg = g_dbus_message_new_method_call ("org.a11y.Bus", "/org/a11y/bus", "org.a11y.Bus", "GetAddress"); + g_dbus_message_set_body (msg, g_variant_new ("()")); + reply = + g_dbus_connection_send_message_with_reply_sync (session_bus, msg, + G_DBUS_SEND_MESSAGE_FLAGS_NONE, + 30000, + NULL, + NULL, + NULL); + if (reply) { - g_variant_get (g_dbus_message_get_body (reply), - "(s)", &a11y_address); + if (g_dbus_message_to_gerror (reply, &local_error)) + { + if (!g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) + g_message ("Can't find a11y bus: %s", local_error->message); + } + else + { + g_variant_get (g_dbus_message_get_body (reply), + "(s)", &a11y_address); + g_debug ("Retrieved AT-SPI bus address \"%s\" from session bus", + a11y_address); + } } }