From 1b42dde756a24766c8fd3d7e86efc8a6904109bf Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 15 Nov 2026 17:56:36 -0500 Subject: [PATCH] Fix quick voice defaults and combo history with shared core v0.7.0 --- README.md | 2 +- docs/testing/voice-profiles.md | 2 +- go.mod | 2 +- go.sum | 2 + internal/app/combo_presentation.go | 4 +- internal/app/combo_presentation_test.go | 15 +++++ internal/app/preferences.go | 11 +++- internal/app/preferences_application.go | 1 + internal/app/preferences_apply.go | 2 +- internal/app/speech_settings.go | 80 ++++++++++++++----------- internal/app/speech_settings_test.go | 26 +++++++- internal/app/voice_profiles_test.go | 44 ++++++++++++++ 12 files changed, 149 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f5b6554..25f7224 100644 --- a/README.md +++ b/README.md @@ -670,7 +670,7 @@ the preset. Failed speech changes retain the previous configuration. Cthulhu's existing restriction on combining hardware primary speech with a separate echo synthesizer still applies. -Standalone builds pin `screenreader-common v0.6.1`, which supplies the shared +Standalone builds pin `screenreader-common v0.7.0`, which supplies the shared profile model and editor. A sibling Go workspace can use local common-module changes during development. See [profile verification](docs/testing/voice-profiles.md). diff --git a/docs/testing/voice-profiles.md b/docs/testing/voice-profiles.md index 381e25e..47bbcee 100644 --- a/docs/testing/voice-profiles.md +++ b/docs/testing/voice-profiles.md @@ -1,6 +1,6 @@ # Primary voice profiles -Standalone builds pin screenreader-common v0.6.1. Use `GOWORK=off` to verify +Standalone builds pin screenreader-common v0.7.0. Use `GOWORK=off` to verify the released dependency; a sibling workspace remains useful for development. Run shared tests with `GOWORK=off go test -race ./...` in screenreader-common. In Cthulhu, run `GOWORK=off go test ./internal/config ./internal/preferences diff --git a/go.mod b/go.mod index 7cf30f2..aceed94 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,4 @@ require github.com/godbus/dbus/v5 v5.1.0 require github.com/gorilla/websocket v1.5.3 -require git.stormux.org/storm/screenreader-common v0.6.1 +require git.stormux.org/storm/screenreader-common v0.7.0 diff --git a/go.sum b/go.sum index 6315dba..c378845 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ git.stormux.org/storm/screenreader-common v0.6.0 h1:iXsUBBjHOQTPu3ROTR9ysrPOi3iI git.stormux.org/storm/screenreader-common v0.6.0/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY= git.stormux.org/storm/screenreader-common v0.6.1 h1:IVIVyihIjI38XWsxGlI3hwdSrNNSyGbxa9rPgfan0Ac= git.stormux.org/storm/screenreader-common v0.6.1/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY= +git.stormux.org/storm/screenreader-common v0.7.0 h1:AUrvGrAFwT+7TTZVqq6sgdEeESsHnj7gFt1xPtbARC4= +git.stormux.org/storm/screenreader-common v0.7.0/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= diff --git a/internal/app/combo_presentation.go b/internal/app/combo_presentation.go index c773f5d..8e4f6ec 100644 --- a/internal/app/combo_presentation.go +++ b/internal/app/combo_presentation.go @@ -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 } diff --git a/internal/app/combo_presentation_test.go b/internal/app/combo_presentation_test.go index 8887d6a..02a8bf3 100644 --- a/internal/app/combo_presentation_test.go +++ b/internal/app/combo_presentation_test.go @@ -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") + } +} diff --git a/internal/app/preferences.go b/internal/app/preferences.go index 4fd103b..0dd807c 100644 --- a/internal/app/preferences.go +++ b/internal/app/preferences.go @@ -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, diff --git a/internal/app/preferences_application.go b/internal/app/preferences_application.go index fbcf732..64d5ddc 100644 --- a/internal/app/preferences_application.go +++ b/internal/app/preferences_application.go @@ -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 diff --git a/internal/app/preferences_apply.go b/internal/app/preferences_apply.go index 76eaa6b..ef6c156 100644 --- a/internal/app/preferences_apply.go +++ b/internal/app/preferences_apply.go @@ -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 diff --git a/internal/app/speech_settings.go b/internal/app/speech_settings.go index e4aaf3a..1c83852 100644 --- a/internal/app/speech_settings.go +++ b/internal/app/speech_settings.go @@ -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} +} diff --git a/internal/app/speech_settings_test.go b/internal/app/speech_settings_test.go index 5a07bb4..c34c269 100644 --- a/internal/app/speech_settings_test.go +++ b/internal/app/speech_settings_test.go @@ -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") diff --git a/internal/app/voice_profiles_test.go b/internal/app/voice_profiles_test.go index a6b2bb0..077a77b 100644 --- a/internal/app/voice_profiles_test.go +++ b/internal/app/voice_profiles_test.go @@ -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) + } +}