Attempt to fix bugs where Cthulhu was reading previous entry in comobo boxes in addition to the current entry.

This commit is contained in:
Storm Dragon committed 2026-11-15 15:20:33 -05:00
1 parent 124293e3c8
commit 322f151344
4 files changed
+59

No files matched your search

+15
View File
@@ -37,3 +37,18 @@ func (history *comboPresentation) observe(event atspi.Event) (text string, updat
}
return text, update, duplicate
}
// echoesSelection reports a closed GTK combo's menu-item selection whose value
// the focused combo already presented. GTK sends the combo's name change first.
func (history *comboPresentation) echoesSelection(event atspi.Event) bool {
if event.Type != atspi.SelectionChangedEvent || event.Source.Role != "menu item" ||
!history.focus.Valid() || atspi.NewObjectID(event.Source.BusName, event.OriginPath) != history.focus {
return false
}
text := event.Source.Name
duplicate := text != "" && text == history.value
if text != "" {
history.value = text
}
return duplicate
}
+32
View File
@@ -8,6 +8,7 @@ import (
"context"
"log/slog"
"reflect"
"strconv"
"testing"
"git.stormux.org/storm/cthulhu/internal/atspi"
@@ -58,3 +59,34 @@ func TestComboSelectionSpeaksValueWithoutRepeatingRoleSound(t *testing.T) {
})
}
}
func TestClosedGTKComboSelectionSpeaksOnlyNewValue(t *testing.T) {
queue := &modeSoundQueue{speech: &fakeSpeechQueue{spoken: make(chan string, 32)}, sounds: make(chan sound.Cue, 32)}
adapter := &fakeAdapter{events: make(chan atspi.Event, 32)}
combo := atspi.Snapshot{BusName: ":1.70", Path: "/combo", Role: "combo box", Name: "Speech synthesizer", Description: "kokoro", Focused: true}
focus := atspi.NewEvent(atspi.FocusedStateEvent, combo)
focus.Detail1 = 1
adapter.events <- focus
for index, value := range []string{"espeak-ng", "kokoro", "rhvoice"} {
// GTK renames the combo, selects the menu item, then restores the label.
combo.Description, combo.Focused = value, false
adapter.events <- atspi.NewEvent(atspi.AccessibleNameEvent, combo)
item := atspi.Snapshot{BusName: combo.BusName, Path: "/item" + strconv.Itoa(index), Role: "menu item", Name: value}
selection := atspi.NewEvent(atspi.SelectionChangedEvent, item)
selection.OriginPath = combo.Path
adapter.events <- selection
adapter.events <- atspi.NewEvent(atspi.AccessibleNameEvent, combo)
}
close(adapter.events)
options := presentation.DefaultOptions()
processEventsWithInput(context.Background(), slog.New(slog.DiscardHandler), queue, adapter, nil, nil, 0, nil, nil, nil, nil, options)
close(queue.speech.spoken)
var got []string
for text := range queue.speech.spoken {
got = append(got, text)
}
want := []string{"Speech synthesizer, combo box, kokoro", "espeak-ng", "kokoro", "rhvoice"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("speech = %q, want %q", got, want)
}
}
+6
View File
@@ -62,6 +62,7 @@ func (presenter *eventPresenter) speak(event atspi.Event, capturedIntent ...inpu
if comboDuplicate {
return
}
comboSelectionEcho := state.comboHistory.echoesSelection(event)
sequence := recentInput(inputSource).Sequence
intent := recentInput(inputSource).Intent
if len(capturedIntent) != 0 {
@@ -185,6 +186,11 @@ func (presenter *eventPresenter) speak(event atspi.Event, capturedIntent ...inpu
}
spoken, fallbackSpeech = prompt.focusSpeech(spoken.WithText(text), fallbackSpeech.WithText(fallbackText))
text, fallbackText = spoken.Text, fallbackSpeech.Text
if comboSelectionEcho {
// Keep the item's position cue without repeating the combo's value.
spoken, fallbackSpeech = spoken.WithText(""), fallbackSpeech.WithText("")
text, fallbackText = "", ""
}
cueKey := strings.Join(cueParts, "\x00")
// Adjacent characters can have the same text while the caret moves.
// Treat each character caret event as a new review position.