Extended check for being active window object 25/285425/4
authorLukasz Oleksak <l.oleksak@samsung.com>
Mon, 12 Dec 2022 11:32:11 +0000 (12:32 +0100)
committerLukasz Oleksak <l.oleksak@samsung.com>
Fri, 16 Dec 2022 10:46:44 +0000 (10:46 +0000)
This check enables dbus communication from TV screen reader not only with
object from the same process as active window but also with objects from
processes providing UIs embedded in active window.

This change aims to reduce chances of dbus calls from TV screen reader to background
processes that respond very slowly.

Change-Id: I0e1786d4cec4e619ec58eff273570cf5e8e2e89d

src/screen_reader_spi.c

index 998f62236fe50f74ed0ce5032483f5e0aeafd8c2..348fe16fb8f7b043869596bdf05a9f901209bda1 100644 (file)
@@ -204,20 +204,59 @@ static char *spi_on_text_delete(SpiData *spi, AtspiEvent *event)
        return g_strdup(ret);
 }
 
+static void clear(gpointer d)
+{
+       AtspiAccessible **data = d;
+       AtspiAccessible *obj = *data;
+       g_object_unref(obj);
+}
+
 static bool is_active_window_object(AtspiAccessible *accessible)
 {
-       AtspiAccessible *window = atspi_get_active_window();
-       if (!window)
+       AtspiAccessible *active_window = atspi_get_active_window();
+       if (!active_window)
                return false;
 
        gchar *accessible_bus_name = atspi_accessible_get_bus_name(accessible, NULL);
-       gchar *window_bus_name = atspi_accessible_get_bus_name(window, NULL);
-
-       bool result = is_same_str(accessible_bus_name, window_bus_name);
-
-       g_free(window_bus_name);
+       gchar *active_window_bus_name = atspi_accessible_get_bus_name(active_window, NULL);
+
+       bool result = is_same_str(accessible_bus_name, active_window_bus_name);
+
+       if (!result) {
+               GHashTable *attributes = g_hash_table_new(g_str_hash, g_str_equal);
+               g_hash_table_insert(attributes, "child_bus", accessible_bus_name);
+
+               AtspiMatchRule *rule = atspi_match_rule_new(
+                                                                       NULL,
+                                                                       ATSPI_Collection_MATCH_INVALID,
+                                                                       attributes,
+                                                                       ATSPI_Collection_MATCH_ANY,
+                                                                       NULL,
+                                                                       ATSPI_Collection_MATCH_INVALID,
+                                                                       NULL,
+                                                                       ATSPI_Collection_MATCH_INVALID,
+                                                                       FALSE);
+               AtspiCollection *col_iface = atspi_accessible_get_collection_iface(active_window);
+               GArray *query_result = atspi_collection_get_matches(
+                                                                       col_iface,
+                                                                       rule,
+                                                                       ATSPI_Collection_SORT_ORDER_CANONICAL,
+                                                                       0,
+                                                                       TRUE,
+                                                                       NULL);
+               g_hash_table_destroy(attributes);
+               g_object_unref(col_iface);
+
+               if (query_result) {
+                       result = query_result->len > 0;
+                       g_array_set_clear_func(query_result, clear);
+                       g_array_free(query_result, TRUE);
+               }
+               g_object_unref(rule);
+       }
+       g_free(active_window_bus_name);
        g_free(accessible_bus_name);
-       g_object_unref(window);
+       g_object_unref(active_window);
 
        return result;
 }