From 270b9bc19b89c620df3fcc1bda894e5c299e5af1 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 17 Jul 2026 13:53:03 -0400 Subject: [PATCH] Interrupt speech before key feedback --- accessibility_feedback.c | 60 ++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/accessibility_feedback.c b/accessibility_feedback.c index d99279f..0e05a7c 100644 --- a/accessibility_feedback.c +++ b/accessibility_feedback.c @@ -31,6 +31,8 @@ struct screen_reader { const char *service; const char *path; const char *interface; + const char *interrupt_path; + const char *interrupt_interface; }; static const struct screen_reader screen_readers[] = { @@ -38,11 +40,15 @@ static const struct screen_reader screen_readers[] = { "org.stormux.Cthulhu1.Service", "/org/stormux/Cthulhu1/Service", "org.stormux.Cthulhu1.Service", + "/org/stormux/Cthulhu1/Service/SpeechManager", + "org.stormux.Cthulhu1.SpeechManager", }, { "org.gnome.Orca1.Service", "/org/gnome/Orca1/Service", "org.gnome.Orca1.Service", + NULL, + NULL, }, }; @@ -135,6 +141,31 @@ static bool own_secure_input_name(GDBusConnection *connection) { reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER; } +static void interrupt_speech(GDBusConnection *connection, const struct screen_reader *reader) { + if (reader->interrupt_path == NULL || reader->interrupt_interface == NULL) { + return; + } + + GError *error = NULL; + GVariant *result = g_dbus_connection_call_sync( + connection, + reader->service, + reader->interrupt_path, + reader->interrupt_interface, + "InterruptSpeech", + g_variant_new("(b)", TRUE), + G_VARIANT_TYPE("(b)"), + G_DBUS_CALL_FLAGS_NONE, + 250, + NULL, + &error); + + if (result != NULL) { + g_variant_unref(result); + } + g_clear_error(&error); +} + static void report_worker_ready(int ready_fd, bool is_ready) { char status = is_ready ? ACCESSIBILITY_READY_OK : ACCESSIBILITY_READY_FAILED; ssize_t result; @@ -178,6 +209,8 @@ static void present_message(GDBusConnection *connection, const char *message) { continue; } + interrupt_speech(connection, reader); + GError *error = NULL; GVariant *result = g_dbus_connection_call_sync( connection, @@ -200,18 +233,6 @@ static void present_message(GDBusConnection *connection, const char *message) { } } -static void flush_stars(GDBusConnection *connection, size_t count) { - char message[640]; - size_t position = 0; - - for (size_t i = 0; i < count; i++) { - const char *separator = (i == 0 ? "" : " "); - position += snprintf(message + position, sizeof(message) - position, "%sstar", separator); - } - - present_message(connection, message); -} - static void close_sleep_lock_fd(void) { const char *sleep_lock_fd = getenv("XSS_SLEEP_LOCK_FD"); if (sleep_lock_fd == NULL || *sleep_lock_fd == '\0') { @@ -260,27 +281,12 @@ static void feedback_worker(int read_fd, int inherited_xcb_fd, int ready_fd) { } size_t count = (size_t)bytes_read / sizeof(feedback[0]); - size_t stars = 0; for (size_t i = 0; i < count; i++) { - if (feedback[i] == ACCESSIBILITY_CHARACTER_TYPED) { - stars++; - continue; - } - - if (connection != NULL && stars > 0) { - flush_stars(connection, stars); - } - stars = 0; - const char *message = feedback_message(feedback[i]); if (connection != NULL && message != NULL) { present_message(connection, message); } } - - if (connection != NULL && stars > 0) { - flush_stars(connection, stars); - } } if (connection != NULL) {