Fix quick voice defaults and combo history with shared core v0.7.0
This commit is contained in:
1 parent
cad3360bd8
commit
1b42dde756
12 files changed
+149
-42
No files matched your search
@@ -31,10 +31,12 @@ func (history *comboPresentation) observe(event atspi.Event) (text string, updat
|
||||
text = presentation.ComboBoxSelectionText(event.Source)
|
||||
update = !focusGain || event.Source.ID() == history.focus
|
||||
duplicate = update && event.Source.ID() == history.focus && text == history.value
|
||||
history.value = text
|
||||
if focusGain {
|
||||
history.focus = event.Source.ID()
|
||||
}
|
||||
if event.Source.ID() == history.focus {
|
||||
history.value = text
|
||||
}
|
||||
return text, update, duplicate
|
||||
}
|
||||
|
||||
|
||||
@@ -90,3 +90,18 @@ func TestClosedGTKComboSelectionSpeaksOnlyNewValue(t *testing.T) {
|
||||
t.Fatalf("speech = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComboHistoryKeepsFocusedValueAcrossOtherComboUpdates(t *testing.T) {
|
||||
var history comboPresentation
|
||||
combo := atspi.Snapshot{BusName: ":1.70", Path: "/focused", Role: "combo box", ValueText: "Selected"}
|
||||
history.observe(atspi.NewEvent(atspi.FocusEvent, combo))
|
||||
other := combo
|
||||
other.Path, other.ValueText = "/other", "Other selection"
|
||||
history.observe(atspi.NewEvent(atspi.AccessibleNameEvent, other))
|
||||
item := atspi.Snapshot{BusName: combo.BusName, Path: "/item", Role: "menu item", Name: "Selected"}
|
||||
selection := atspi.NewEvent(atspi.SelectionChangedEvent, item)
|
||||
selection.OriginPath = combo.Path
|
||||
if !history.echoesSelection(selection) {
|
||||
t.Fatal("another combo replaced the focused combo's remembered selection")
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,10 @@ type preferencesWorker struct {
|
||||
globalSettings config.Settings
|
||||
appSettings map[string]config.Settings
|
||||
quickSpeech quickSpeechSettings
|
||||
savedVoice *voiceprofiles.Profile // Quick settings "Default"; nil when unknown.
|
||||
savedVoice *voiceprofiles.Profile // Global quick settings "Default"; nil when unknown.
|
||||
// savedApplications holds each mapped application's saved settings for
|
||||
// its quick settings "Default" voice.
|
||||
savedApplications map[string]savedApplicationSettings
|
||||
laptopLayout bool
|
||||
activeApp string
|
||||
editApp string
|
||||
@@ -97,6 +100,12 @@ func (worker *preferencesWorker) setGlobalSettings(settings config.Settings) {
|
||||
}
|
||||
}
|
||||
|
||||
// savedApplicationSettings is an application's saved settings and the global
|
||||
// settings they were saved over.
|
||||
type savedApplicationSettings struct {
|
||||
global, application config.Settings
|
||||
}
|
||||
|
||||
func newPreferencesWorker(logger *slog.Logger, settings config.Settings, updater any) *preferencesWorker {
|
||||
saved := config.Primary_voice(settings)
|
||||
return &preferencesWorker{savedVoice: &saved, logger: logger, settings: settings, globalSettings: settings, appSettings: make(map[string]config.Settings), updater: updater,
|
||||
|
||||
@@ -60,6 +60,7 @@ func (worker *preferencesWorker) applicationSettings(application string) (config
|
||||
if !mapped {
|
||||
return worker.globalSettings, nil
|
||||
}
|
||||
worker.remember_application(application, persistedGlobal, settings)
|
||||
settings = config.RebaseApplicationSettings(persistedGlobal, worker.globalSettings, settings)
|
||||
worker.appSettings[application] = settings
|
||||
return worker.quickSpeech.apply(settings), nil
|
||||
|
||||
@@ -84,7 +84,7 @@ func (worker *preferencesWorker) applyNext(ctx context.Context, next config.Sett
|
||||
// An explicit preferences Apply replaces the session's quick speech choices.
|
||||
if worker.editingActive {
|
||||
worker.quickSpeech = quickSpeechSettings{}
|
||||
worker.remember_saved_voice(next)
|
||||
worker.remember_saved_voice(next, scopeApp)
|
||||
}
|
||||
if worker.editingActive {
|
||||
worker.editing = next
|
||||
|
||||
@@ -21,10 +21,6 @@ import (
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
)
|
||||
|
||||
// quickSavedVoice is the voice-profile choice for the saved speech settings.
|
||||
// Profile names are visible text, so this identifier cannot collide.
|
||||
const quickSavedVoice = "\x00saved"
|
||||
|
||||
// Use the settings worker's bounded mailbox, keeping discovery, disk writes,
|
||||
// and speech connection replacement off the input and focus paths.
|
||||
func (worker *preferencesWorker) SpeechCommand(command input.Command) {
|
||||
@@ -176,9 +172,8 @@ func (host *quickSettingsHost) categories() []quicksettings.Category {
|
||||
quicksettings.Entry{ID: "speech.rate", Label: "Rate", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
||||
quicksettings.Entry{ID: "speech.pitch", Label: "Pitch", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
||||
quicksettings.Entry{ID: "speech.volume", Label: "Volume", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep})
|
||||
if len(host.settings.VoiceProfiles.Profiles) > 0 {
|
||||
voice = append(voice, quicksettings.Entry{ID: "speech.profile", Label: "Voice profile", Kind: quicksettings.Choice})
|
||||
}
|
||||
// Always offered so "Default" can restore the saved voice without profiles.
|
||||
voice = append(voice, quicksettings.Entry{ID: "speech.profile", Label: "Voice profile", Kind: quicksettings.Choice})
|
||||
reading := []quicksettings.Entry{
|
||||
{ID: "reading.punctuation", Label: "Punctuation level", Kind: quicksettings.Choice},
|
||||
{ID: "reading.indentation", Label: "Indentation", Kind: quicksettings.Choice},
|
||||
@@ -279,22 +274,12 @@ func (host *quickSettingsHost) catalog() bool {
|
||||
func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksettings.Option {
|
||||
switch entry.ID {
|
||||
case "speech.profile":
|
||||
options := []quicksettings.Option{}
|
||||
if host.voice_profile_choice(host.settings) == "" {
|
||||
options = append(options, quicksettings.Option{ID: "", Label: "Custom"})
|
||||
}
|
||||
if host.worker != nil && host.worker.savedVoice != nil {
|
||||
options = append(options, quicksettings.Option{ID: quickSavedVoice, Label: "Default"})
|
||||
}
|
||||
for _, p := range host.settings.VoiceProfiles.Profiles {
|
||||
options = append(options, quicksettings.Option{ID: p.Name, Label: p.Name, Literal: true})
|
||||
}
|
||||
return options
|
||||
return host.settings.VoiceProfiles.Quick_options(config.Primary_voice(host.settings), host.saved_voice())
|
||||
case "speech.module":
|
||||
var options []quicksettings.Option
|
||||
if host.hardware() {
|
||||
for _, module := range hardwareSynthesizers {
|
||||
options = append(options, quicksettings.Option{ID: module, Label: module})
|
||||
options = append(options, quicksettings.Option{ID: module, Label: module, Literal: true})
|
||||
}
|
||||
return options
|
||||
}
|
||||
@@ -304,7 +289,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
||||
options = []quicksettings.Option{{ID: "", Label: "default"}}
|
||||
for module := range host.worker.catalog {
|
||||
if module != "" {
|
||||
options = append(options, quicksettings.Option{ID: module, Label: module})
|
||||
options = append(options, quicksettings.Option{ID: module, Label: module, Literal: true})
|
||||
}
|
||||
}
|
||||
sort.Slice(options[1:], func(i, j int) bool { return options[1+i].ID < options[1+j].ID })
|
||||
@@ -320,7 +305,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
||||
normalized := sd.NormalizeLanguage(language)
|
||||
if language != "" && !seen[normalized] {
|
||||
seen[normalized] = true
|
||||
options = append(options, quicksettings.Option{ID: language, Label: language})
|
||||
options = append(options, quicksettings.Option{ID: language, Label: language, Literal: true})
|
||||
}
|
||||
}
|
||||
return options
|
||||
@@ -336,7 +321,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
||||
voices = quickSpeechVoices(host.settings.SpeechOutputModule, voices)
|
||||
}
|
||||
for _, voice := range voices {
|
||||
options = append(options, quicksettings.Option{ID: voiceOptionID(&config.VoiceFamily{Name: voice.Name, Lang: voice.Language, Variant: voice.Variant}), Label: voice.Name})
|
||||
options = append(options, quicksettings.Option{ID: voiceOptionID(&config.VoiceFamily{Name: voice.Name, Lang: voice.Language, Variant: voice.Variant}), Label: voice.Name, Literal: true})
|
||||
}
|
||||
return options
|
||||
case "reading.punctuation":
|
||||
@@ -422,10 +407,7 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
|
||||
next := host.settings
|
||||
var speechChanged bool
|
||||
if result.Entry.ID == "speech.profile" {
|
||||
p, ok := next.VoiceProfiles.Find(result.Value.Choice)
|
||||
if result.Value.Choice == quickSavedVoice && worker.savedVoice != nil {
|
||||
p, ok = *worker.savedVoice, true
|
||||
}
|
||||
p, ok := next.VoiceProfiles.Quick_profile(result.Value.Choice, host.saved_voice())
|
||||
if !ok {
|
||||
worker.announceSpeechSetting("Choose a saved voice profile")
|
||||
return false
|
||||
@@ -547,19 +529,49 @@ func quickSpeechVoices(module string, voices []speech.Voice) []speech.Voice {
|
||||
// voice_profile_choice names the matching profile, then the saved voice, and
|
||||
// otherwise reports a custom session voice.
|
||||
func (host *quickSettingsHost) voice_profile_choice(settings config.Settings) string {
|
||||
primary := config.Primary_voice(settings)
|
||||
if name := settings.VoiceProfiles.Matching(primary); name != "" {
|
||||
return name
|
||||
return settings.VoiceProfiles.Quick_choice(config.Primary_voice(settings), host.saved_voice())
|
||||
}
|
||||
|
||||
func (host *quickSettingsHost) saved_voice() *voiceprofiles.Profile {
|
||||
if host.worker == nil {
|
||||
return nil
|
||||
}
|
||||
if host.worker != nil && host.worker.savedVoice != nil && voiceprofiles.Same_voice(*host.worker.savedVoice, primary) {
|
||||
return quickSavedVoice
|
||||
return host.worker.saved_voice()
|
||||
}
|
||||
|
||||
// saved_voice is the voice quick settings "Default" restores: the focused
|
||||
// application's saved voice when it has its own, otherwise the global voice
|
||||
// from startup or the last explicit Apply.
|
||||
func (worker *preferencesWorker) saved_voice() *voiceprofiles.Profile {
|
||||
saved, ok := worker.savedApplications[worker.activeApp]
|
||||
if worker.savedVoice == nil || !ok {
|
||||
return worker.savedVoice
|
||||
}
|
||||
return ""
|
||||
// Rebase onto the saved global voice so an application that inherits the
|
||||
// global voice keeps following it.
|
||||
global, err := config.Apply_primary_voice(saved.global, *worker.savedVoice)
|
||||
if err != nil {
|
||||
global = saved.global
|
||||
}
|
||||
voice := config.Primary_voice(worker.effective_settings(config.RebaseApplicationSettings(saved.global, global, saved.application)))
|
||||
return &voice
|
||||
}
|
||||
|
||||
// remember_saved_voice records the voice that quick settings "Default"
|
||||
// restores: the one in the settings at startup or the last explicit Apply.
|
||||
func (worker *preferencesWorker) remember_saved_voice(settings config.Settings) {
|
||||
// restores after an explicit Apply. An application Apply records only that
|
||||
// application's saved settings, over the global settings it was edited from.
|
||||
func (worker *preferencesWorker) remember_saved_voice(settings config.Settings, application string) {
|
||||
if application != "" {
|
||||
worker.remember_application(application, worker.globalSettings, settings)
|
||||
return
|
||||
}
|
||||
saved := config.Primary_voice(worker.effective_settings(settings))
|
||||
worker.savedVoice = &saved
|
||||
}
|
||||
|
||||
func (worker *preferencesWorker) remember_application(application string, global, settings config.Settings) {
|
||||
if worker.savedApplications == nil {
|
||||
worker.savedApplications = make(map[string]savedApplicationSettings)
|
||||
}
|
||||
worker.savedApplications[application] = savedApplicationSettings{global: global, application: settings}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func TestSpeechShortcutsApplySaveAndFailure(t *testing.T) {
|
||||
}
|
||||
updateError = nil
|
||||
worker.catalog = speech.Catalog{"": {{Name: "default", Language: "en"}}, "alpha": {{Name: "one", Language: "en"}, {Name: "two", Language: "en"}}, "beta": {{Name: "three", Language: "en"}}}
|
||||
for _, want := range []string{"Pitch 0", "Volume 100", "Speech-dispatcher module default"} {
|
||||
for _, want := range []string{"Pitch 0", "Volume 100", "Voice profile Custom", "Speech-dispatcher module default"} {
|
||||
command(input.SelectNextSpeechSetting)
|
||||
if message != want {
|
||||
t.Fatalf("got %q, want %q", message, want)
|
||||
@@ -453,7 +453,7 @@ func TestHardwareQuickSettingsOfferSynthesizersWithoutVoices(t *testing.T) {
|
||||
}
|
||||
var messages []string
|
||||
worker.announce = func(text string) { messages = append(messages, text) }
|
||||
for _, want := range []string{"Rate 0", "Pitch 0", "Volume 100", "Hardware synthesizer doubletalk"} {
|
||||
for _, want := range []string{"Rate 0", "Pitch 0", "Volume 100", "Voice profile Default", "Hardware synthesizer doubletalk"} {
|
||||
worker.handleSpeechCommand(t.Context(), input.SelectNextSpeechSetting)
|
||||
if got := messages[len(messages)-1]; got != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
@@ -551,6 +551,28 @@ func TestQuickSettingsRetainPartialDiscovery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuickSpeechNamesBypassTranslation(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.SpeechOutputModule = "all"
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, nil)
|
||||
worker.catalog = speech.Catalog{"all": {{Name: "default", Language: "en"}}}
|
||||
host := &quickSettingsHost{worker: worker, ctx: t.Context(), settings: settings}
|
||||
menu := quicksettings.New(nil, quicksettings.Messages{Translate: func(text string) string { return "translated " + text }})
|
||||
for _, id := range []string{"module", "language", "voice"} {
|
||||
entry := quicksettings.Entry{ID: "speech." + id, Kind: quicksettings.Choice}
|
||||
options := host.Options(entry)
|
||||
if len(options) != 2 {
|
||||
t.Fatal(id, options)
|
||||
}
|
||||
if got := menu.Describe(entry, quicksettings.Value{Choice: options[1].ID}, options); got != options[1].Label {
|
||||
t.Fatalf("%s name translated: %q", id, got)
|
||||
}
|
||||
if got := menu.Describe(entry, quicksettings.Value{}, options); got != "translated default" {
|
||||
t.Fatalf("%s default label not translated: %q", id, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuickSpeechLanguageFiltersVoicesAndKeepsDefaultLanguage(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
|
||||
@@ -71,3 +71,47 @@ func TestQuickVoiceProfileDefaultRestoresSavedVoiceFromCustom(t *testing.T) {
|
||||
t.Fatal("Default did not restore the saved voice", messages, worker.settings.DefaultVoice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQuickVoiceProfileDefaultIsFocusedApplicationVoice(t *testing.T) {
|
||||
global := config.DefaultSettings()
|
||||
global.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
store, err := config.NewStore(global.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.Save(global); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application := global
|
||||
rate, volume := 82.0, 40.0
|
||||
application.DefaultVoice.Rate, application.DefaultVoice.Gain = &rate, &volume
|
||||
if err := store.SaveForApplication("Voiced Application", application); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SaveForApplication("Plain Application", global); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), global, settingsUpdateFunc(func(context.Context, speech.Settings) error { return nil }))
|
||||
var messages []string
|
||||
worker.announce = func(text string) { messages = append(messages, text) }
|
||||
worker.switchApplication(t.Context(), "Voiced Application")
|
||||
selectQuickSetting(t, worker, "speech.profile")
|
||||
if got := messages[len(messages)-1]; got != "Voice profile Default" {
|
||||
t.Fatal("application voice not reported as Default", got)
|
||||
}
|
||||
selectQuickSetting(t, worker, "speech.rate")
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
selectQuickSetting(t, worker, "speech.profile")
|
||||
if got := messages[len(messages)-1]; got != "Voice profile Custom" {
|
||||
t.Fatal("changed application voice not reported as Custom", got)
|
||||
}
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
if got := messages[len(messages)-1]; got != "Default" || *worker.settings.DefaultVoice.Rate != 82 || *worker.settings.DefaultVoice.Gain != 40 {
|
||||
t.Fatal("Default did not restore the application voice", messages, worker.settings.DefaultVoice)
|
||||
}
|
||||
// An application without its own voice follows the global saved voice.
|
||||
worker.switchApplication(t.Context(), "Plain Application")
|
||||
if saved := worker.saved_voice(); saved == nil || !voiceprofiles.Same_voice(*saved, config.Primary_voice(global)) {
|
||||
t.Fatal("inherited application voice was not the global voice", saved)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user