Check active window in spi_event_get_text_to_read() 67/285867/1
authorArtur Świgoń <a.swigon@samsung.com>
Tue, 6 Dec 2022 13:27:00 +0000 (14:27 +0100)
committerChun <jykeon@samsung.com>
Thu, 22 Dec 2022 01:49:25 +0000 (01:49 +0000)
This patch tries to prevent D-Bus communication with background
processes, which get very little CPU time and therefore may block
the Screen Reader for an unspecified amount of time.

Change-Id: Ic0a65ed5cc77fb232eba1f50c66379c186ec4bd9
(cherry picked from commit 5b9831e9abc2546204fa5a941603fc6efb9f566f)

src/screen_reader_spi.c

index 1d3870f51c911ecfa8e7b21dac8b15ec8ec5f97f..998f62236fe50f74ed0ce5032483f5e0aeafd8c2 100644 (file)
@@ -87,19 +87,14 @@ void free_shtd(SignalHandlingTimerData *shtd)
  */
 static void display_info(const AtspiEvent *event)
 {
-       AtspiAccessible *source = event->source;
-       gchar *name = atspi_accessible_get_name(source, NULL);
-       gchar *role = atspi_accessible_get_localized_role_name(source, NULL);
-       gchar *toolkit = atspi_accessible_get_toolkit_name(source, NULL);
+       gchar *unique_id = atspi_accessible_get_unique_id(event->source, NULL);
 
        DEBUG("--------------------------------------------------------");
-       DEBUG("Toolkit: %s; Event_type: %s; (%d, %d)", toolkit, event->type, event->detail1, event->detail2);
-       DEBUG("Name: %s; Role: %s; Source: %p", name, role, event->source);
+       DEBUG("Event_type: %s; (%d, %d)", event->type, event->detail1, event->detail2);
+       DEBUG("Source: %s", unique_id);
        DEBUG("--------------------------------------------------------");
 
-       g_free(name);
-       g_free(role);
-       g_free(toolkit);
+       g_free(unique_id);
 }
 
 bool allow_recursive_name(AtspiAccessible *obj)
@@ -209,6 +204,24 @@ static char *spi_on_text_delete(SpiData *spi, AtspiEvent *event)
        return g_strdup(ret);
 }
 
+static bool is_active_window_object(AtspiAccessible *accessible)
+{
+       AtspiAccessible *window = atspi_get_active_window();
+       if (!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);
+       g_free(accessible_bus_name);
+       g_object_unref(window);
+
+       return result;
+}
+
 void spi_event_get_text_to_read(
                SpiData *spi,
                char **text_to_read,
@@ -219,6 +232,17 @@ void spi_event_get_text_to_read(
        *text_to_read = NULL;
        *descr_to_read = NULL;
 
+       // Prioritize checking the focused event to enable an early return
+       if (!g_strcmp0(event->type, spi->tracking_signal_name)) {
+               spi->last_caret_position = -1;
+
+               if (event->detail1 == 0)
+                       return;
+       }
+
+       if (!is_active_window_object(event->source))
+               return;
+
        GHashTable *attrs = atspi_accessible_get_attributes(event->source, NULL);
        if (attrs) {
                char *val = g_hash_table_lookup(attrs, "suppress-screen-reader");
@@ -233,12 +257,11 @@ void spi_event_get_text_to_read(
 
        if (!g_strcmp0(event->type, spi->tracking_signal_name)) {
                /* tracking singal "focused" */
-               if (event->detail1 == 1) {
-                       ReadingComposerData *rc = reading_composer_data_get(event->source);
-                       *text_to_read = reading_composer_description_get(rc);
-                       *descr_to_read = reading_composer_extended_description_get(rc);
-                       reading_composer_data_free(rc);
-               }
+               // note: event->detail1 == 1
+               ReadingComposerData *rc = reading_composer_data_get(event->source);
+               *text_to_read = reading_composer_description_get(rc);
+               *descr_to_read = reading_composer_extended_description_get(rc);
+               reading_composer_data_free(rc);
 
        } else if (!g_strcmp0(event->type, CARET_MOVED_SIG)) {
                *text_to_read = spi_on_caret_move_get_text(spi, event);
@@ -272,9 +295,6 @@ void spi_event_get_text_to_read(
        } else if (!g_strcmp0(event->type, VALUE_CHANGED_SIG)) {
                *text_to_read = spi_on_value_changed_get_text(spi, event);
 
-       } else if (!g_strcmp0(event->type, STATE_FOCUSED_SIG)) {
-               spi->ignore_next_caret_move = EINA_TRUE;
-               spi->last_caret_position = -1;
        } else if (!g_strcmp0(event->type, STATE_CHECKED_SIG)) {
                if (event->detail1)
                        *text_to_read = g_strdup(_("IDS_ACCS_TBOPT_CHECKED_TTS"));