Attempt to fix bugs where Cthulhu was reading previous entry in comobo boxes in addition to the current entry.
This commit is contained in:
1 parent
124293e3c8
commit
322f151344
4 files changed
+59
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -110,6 +110,12 @@ func (adapter *Adapter) captureNativeEventSnapshot(event *C.AtspiEvent, target *
|
||||
// Document focus/load presentation needs only the title. Real caret
|
||||
// events still capture text, including carets hosted on document roots.
|
||||
captureCaret := !isDocumentLifecycleEvent(eventType) && eventType != BusyStateEvent
|
||||
// GTK emits a combo's name change before later "changed" handlers can
|
||||
// publish its new value as the description. The cached description is
|
||||
// then the previous selection, so refresh only this combo's cache.
|
||||
if eventType == AccessibleNameEvent && C.atspi_accessible_get_role(target, nil) == C.ATSPI_ROLE_COMBO_BOX {
|
||||
C.atspi_accessible_clear_cache_single(target)
|
||||
}
|
||||
if eventType == FocusEvent || eventType == FocusedStateEvent {
|
||||
role := C.atspi_accessible_get_role(target, nil)
|
||||
captureCaret = role != C.ATSPI_ROLE_DOCUMENT_WEB && role != C.ATSPI_ROLE_DOCUMENT_FRAME && role != C.ATSPI_ROLE_EMBEDDED
|
||||
|
||||
Reference in new issue
Block a user