Add primary voice profiles from shared reader core v0.6.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Storm DragonandClaude Opus 5.5 committed 2026-11-15 14:26:44 -05:00
1 parent 0f5c2db158
commit 764a289071
26 files changed
+820 -5

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ func (worker *preferencesWorker) apply(ctx context.Context, request preferences.
// application preferences, so an application-scoped Apply never
// edits them: the base values pass through unchanged and only a
// global Apply can republish the governing Wine list.
request.Values.VoiceProfiles = base.VoiceProfiles.Clone()
request.Values.Wine = config.WineSettings{ControllerOnly: base.Wine.ControllerOnly,
ExcludedPrograms: append([]string(nil), base.Wine.ExcludedPrograms...)}
}
+51 -1
View File
@@ -169,6 +169,9 @@ func (host *quickSettingsHost) categories() []quicksettings.Category {
quicksettings.Entry{ID: "speech.language", Label: "Speech-dispatcher language", Kind: quicksettings.Choice, EmptyIsDefault: true},
quicksettings.Entry{ID: "speech.voice", Label: "Speech-dispatcher voice", Kind: quicksettings.Choice, EmptyIsDefault: true})
}
if len(host.settings.VoiceProfiles.Profiles) > 0 {
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},
@@ -218,6 +221,8 @@ func (host *quickSettingsHost) Value(entry quicksettings.Entry) quicksettings.Va
return quicksettings.Value{Number: int(math.Round(*value))}
}
switch entry.ID {
case "speech.profile":
return quicksettings.Value{Choice: settings.VoiceProfiles.Matching(config.Primary_voice(settings))}
case "speech.rate":
return number(settings.DefaultVoice.Rate, 0)
case "speech.pitch":
@@ -266,6 +271,15 @@ 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.settings.VoiceProfiles.Matching(config.Primary_voice(host.settings)) == "" {
options = append(options, quicksettings.Option{ID: "", Label: "Custom"})
}
for _, p := range host.settings.VoiceProfiles.Profiles {
options = append(options, quicksettings.Option{ID: p.Name, Label: p.Name, Literal: true})
}
return options
case "speech.module":
var options []quicksettings.Option
if host.hardware() {
@@ -396,7 +410,23 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
return worker.handle_extension_quick(ctx, setting, result.Value.Choice)
}
next := host.settings
speechChanged := host.set(&next, result.Entry, result.Value)
var speechChanged bool
if result.Entry.ID == "speech.profile" {
p, ok := next.VoiceProfiles.Find(result.Value.Choice)
if !ok {
worker.announceSpeechSetting("Choose a saved voice profile")
return false
}
var err error
next, err = config.Apply_primary_voice(next, p)
if err != nil {
worker.announceSpeechSetting("Voice profile was not changed: " + err.Error())
return false
}
speechChanged = true
} else {
speechChanged = host.set(&next, result.Entry, result.Value)
}
err := config.Validate(next)
if err == nil && speechChanged {
err = worker.updateSpeech(ctx, next)
@@ -415,6 +445,11 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
if worker.quickSpeech.adjusted == nil {
worker.quickSpeech.adjusted = make(map[string]bool)
}
if result.Entry.ID == "speech.profile" {
for _, id := range []string{"speech.rate", "speech.pitch", "speech.volume", "speech.module", "speech.language", "speech.voice"} {
delete(worker.quickSpeech.adjusted, id)
}
}
worker.quickSpeech.settings = next
worker.quickSpeech.adjusted[result.Entry.ID] = true
change := quickSpeechSettings{settings: next, adjusted: map[string]bool{result.Entry.ID: true}}
@@ -447,6 +482,14 @@ func (quick quickSpeechSettings) apply(settings config.Settings) config.Settings
entry.Kind = quicksettings.Toggle
}
value := host.Value(entry)
if id == "speech.profile" {
settings.SpeechServerFactory = quick.settings.SpeechServerFactory
settings.SpeechOutputModule = quick.settings.SpeechOutputModule
settings.HardwareSpeechDevice = quick.settings.HardwareSpeechDevice
settings.HardwareSpeechBaudRate = quick.settings.HardwareSpeechBaudRate
settings.DefaultVoice = quick.settings.DefaultVoice
continue
}
if id == "speech.module" || id == "speech.language" || id == "speech.voice" {
// A voice belongs to its synthesizer, and a hardware synthesizer also
// needs its transport. Keep this selection valid across app profiles.
@@ -468,6 +511,13 @@ func sortedQuickIDs(ids map[string]bool) []string {
result = append(result, id)
}
sort.Strings(result)
// Apply the preset before individual adjustments.
for index, id := range result {
if id == "speech.profile" {
result = append([]string{id}, append(result[:index], result[index+1:]...)...)
break
}
}
return result
}
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"context"
"errors"
"git.stormux.org/storm/cthulhu/internal/config"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/speech"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
"log/slog"
"path/filepath"
"reflect"
"testing"
)
func TestQuickVoiceProfilesFailurePersistenceAndApplicationInheritance(t *testing.T) {
settings := config.DefaultSettings()
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
settings.VoiceProfiles.Profiles = []voiceprofiles.Profile{{Name: "Reading", Driver: "speech-dispatcher", Rate: 30, Pitch: 5, Volume: 80}, {Name: "Presentation", Driver: "speech-dispatcher", Rate: -10, Pitch: 0, Volume: 100}}
var failure error
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, settingsUpdateFunc(func(context.Context, speech.Settings) error { return failure }))
selectQuickSetting(t, worker, "speech.profile")
failure = errors.New("fixture unavailable")
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
if !reflect.DeepEqual(worker.settings.DefaultVoice, settings.DefaultVoice) {
t.Fatal("failed profile changed current voice")
}
failure = nil
for _, name := range []string{"Reading", "Presentation", "Reading"} {
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
if got := worker.settings.VoiceProfiles.Matching(config.Primary_voice(worker.settings)); got != name {
t.Fatal(got, name, worker.settings.DefaultVoice)
}
}
worker.handleSpeechCommand(t.Context(), input.SaveSpeechSettings)
loaded, err := config.Load(settings.Path)
if err != nil || *loaded.DefaultVoice.Rate != 30 || len(loaded.VoiceProfiles.Profiles) != 2 {
t.Fatal(loaded, err)
}
application := config.DefaultSettings()
application = worker.quickSpeech.apply(application)
if *application.DefaultVoice.Rate != 30 || *application.DefaultVoice.Gain != 80 {
t.Fatal("profile lost across applications")
}
if !reflect.DeepEqual(application.EchoVoice, settings.EchoVoice) || !reflect.DeepEqual(application.SystemVoice, settings.SystemVoice) {
t.Fatal("profile changed auxiliary voices")
}
}
+5
View File
@@ -102,6 +102,9 @@ func migrateSpeechScale(document *writableDocument) {
}
func effectiveSettings(document writableDocument) (Settings, error) {
if err := document.VoiceProfiles.Validate(); err != nil {
return Settings{}, err
}
if strings.TrimSpace(document.ActiveProfile) == "" {
return Settings{}, errors.New("validate configuration: active-profile is empty")
}
@@ -137,6 +140,7 @@ func effectiveSettings(document writableDocument) (Settings, error) {
}
settings := DefaultSettings()
applyProfile(&settings, profile)
settings.VoiceProfiles = document.VoiceProfiles.Clone()
settings.ActiveProfile = document.ActiveProfile
return settings, nil
}
@@ -156,6 +160,7 @@ func encodeWritable(settings Settings) ([]byte, error) {
if profileName == "" {
profileName = document.ActiveProfile
}
document.VoiceProfiles = settings.VoiceProfiles.Clone()
document.ActiveProfile = profileName
document.Profiles = map[string]writableProfile{profileName: profileFromSettings(settings)}
return encodeDocument(document)
+2
View File
@@ -19,6 +19,7 @@ package config
import (
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
)
const CurrentSchemaVersion = 3
@@ -27,6 +28,7 @@ const CurrentSchemaVersion = 3
const speechScaleSchemaVersion = 3
type writableDocument struct {
VoiceProfiles voiceprofiles.Collection `toml:"voice-profiles,omitempty"`
SchemaVersion int `toml:"schema-version"`
ActiveProfile string `toml:"active-profile"`
Profiles map[string]writableProfile `toml:"profiles"`
+2
View File
@@ -19,6 +19,7 @@ package config
import (
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
)
type VoiceFamily struct {
@@ -124,6 +125,7 @@ type WineSettings struct {
}
type Settings struct {
VoiceProfiles voiceprofiles.Collection
Wine WineSettings
StructuralNavigationTriggersFocusMode bool
+1
View File
@@ -22,6 +22,7 @@ import (
)
func cloneSettings(settings Settings) Settings {
settings.VoiceProfiles = settings.VoiceProfiles.Clone()
settings.Wine.ExcludedPrograms = append([]string(nil), settings.Wine.ExcludedPrograms...)
settings.SpeechInterruption.Keys = append([]string(nil), settings.SpeechInterruption.Keys...)
settings.KeyBindings = input.CloneBindingOverrides(settings.KeyBindings)
+3
View File
@@ -167,6 +167,9 @@ func (store *Store) save(settings Settings, application string) error {
if application != "" {
profile = applicationProfileDifference(global, settings)
}
if application == "" {
document.VoiceProfiles = settings.VoiceProfiles.Clone()
}
document.Profiles[profileName] = profile
contents, err := encodeDocument(document)
if err != nil {
+3
View File
@@ -42,6 +42,9 @@ func ValidWineProgramName(name string) bool {
}
func validate(settings Settings) error {
if err := settings.VoiceProfiles.Validate(); err != nil {
return err
}
if len(settings.Wine.ExcludedPrograms) > 256 {
return errors.New("too many Wine hook exclusions")
}
+69
View File
@@ -0,0 +1,69 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package config
import (
"fmt"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
"math"
"strings"
)
func Primary_voice(settings Settings) voiceprofiles.Profile {
p := voiceprofiles.Profile{Driver: "speech-dispatcher", Module: settings.SpeechOutputModule, Volume: 100}
number := func(v *float64, fallback int) int {
if v != nil {
return int(math.Round(*v))
}
return fallback
}
p.Rate = number(settings.DefaultVoice.Rate, 0)
p.Pitch = number(settings.DefaultVoice.AveragePitch, 0)
p.Volume = number(settings.DefaultVoice.Gain, 100)
if f := settings.DefaultVoice.Family; f != nil {
p.Voice = f.Name
p.Language = strings.TrimSuffix(f.Lang+"-"+f.Dialect, "-")
p.Variant = f.Variant
}
if settings.SpeechServerFactory == "hardwarefactory" {
p.Driver = settings.SpeechOutputModule
p.Module = ""
p.Voice = ""
p.Language = ""
p.Variant = ""
p.Device = settings.HardwareSpeechDevice
p.BaudRate = settings.HardwareSpeechBaudRate
}
return p
}
func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
if err := p.Normalize().Validate(); err != nil {
return settings, err
}
next := settings
next.SpeechServerFactory = "speechdispatcherfactory"
next.SpeechOutputModule = p.Module
voice := Voice{}
rate, pitch, volume := float64(p.Rate), float64(p.Pitch), float64(p.Volume)
voice.Rate = &rate
voice.AveragePitch = &pitch
voice.Gain = &volume
if p.Driver != "speech-dispatcher" {
if p.Driver == "dectalk-usb" {
return settings, fmt.Errorf("DECtalk USB is not supported by Cthulhu")
}
next.SpeechServerFactory = "hardwarefactory"
next.SpeechOutputModule = p.Driver
next.HardwareSpeechDevice = p.Device
next.HardwareSpeechBaudRate = p.BaudRate
} else if p.Voice != "" || p.Language != "" {
voice.Family = &VoiceFamily{Name: p.Voice, Lang: p.Language, Variant: p.Variant}
}
next.DefaultVoice = voice
if err := Validate(next); err != nil {
return settings, err
}
return next, nil
}
+60
View File
@@ -0,0 +1,60 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package config
import (
"git.stormux.org/storm/screenreader-common/voiceprofiles"
"path/filepath"
"reflect"
"testing"
)
func TestVoiceProfilesPersistencePrimaryScopeAndApplicationSave(t *testing.T) {
settings := DefaultSettings()
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
rate := float64(25)
settings.EchoVoice = Voice{Rate: &rate, Family: &VoiceFamily{Name: "Echo", Lang: "en"}}
settings.SystemVoice = Voice{Rate: &rate}
settings.UseCustomEchoVoice = true
p := voiceprofiles.Profile{Name: "Reading", Driver: "speech-dispatcher", Module: "fixture", Voice: "Reader", Language: "es", Rate: 30, Pitch: -5, Volume: 80}
settings.VoiceProfiles.Profiles = []voiceprofiles.Profile{p}
store, err := NewStore(settings.Path)
if err != nil {
t.Fatal(err)
}
if err = store.Save(settings); err != nil {
t.Fatal(err)
}
loaded, err := store.Load()
if err != nil || !reflect.DeepEqual(loaded.VoiceProfiles, settings.VoiceProfiles) {
t.Fatal(loaded.VoiceProfiles, err)
}
loaded, err = Apply_primary_voice(loaded, p)
if err != nil || loaded.DefaultVoice.Family.Name != "Reader" || *loaded.DefaultVoice.Rate != 30 {
t.Fatal(loaded, err)
}
if !reflect.DeepEqual(loaded.EchoVoice, settings.EchoVoice) || !reflect.DeepEqual(loaded.SystemVoice, settings.SystemVoice) || loaded.UseCustomEchoVoice != settings.UseCustomEchoVoice {
t.Fatal("profile changed echo/system voices")
}
loaded.VoiceProfiles.Profiles[0].Name = "Application must not change catalog"
if err = store.SaveForApplication("fixture-application", loaded); err != nil {
t.Fatal(err)
}
global, err := store.Load()
if err != nil || global.VoiceProfiles.Profiles[0].Name != "Reading" {
t.Fatal(global.VoiceProfiles, err)
}
current := store.Current()
current.VoiceProfiles.Profiles[0].Name = "Mutated"
if store.Current().VoiceProfiles.Profiles[0].Name != "Reading" {
t.Fatal("profile list aliased store")
}
global.VoiceProfiles = global.VoiceProfiles.Remove(0)
if err = store.Save(global); err != nil {
t.Fatal(err)
}
global, err = store.Load()
if err != nil || len(global.VoiceProfiles.Profiles) != 0 {
t.Fatal(global.VoiceProfiles, err)
}
}
+1 -1
View File
@@ -330,7 +330,7 @@ void prefs_wine_validation(const char *message) {
apply_sensitivity();
}
void prefs_present(void) { gtk_window_present(GTK_WINDOW(prefs_widget("window"))); }
void prefs_close(void) { prefs_extensions_close(); busy_focus = NULL; gtk_widget_destroy(prefs_widget("window")); g_object_unref(builder); builder = NULL; }
void prefs_close(void) { prefs_profile_close(); prefs_extensions_close(); busy_focus = NULL; gtk_widget_destroy(prefs_widget("window")); g_object_unref(builder); builder = NULL; }
void prefs_status(const char *message, int focus) {
gtk_entry_set_text(GTK_ENTRY(prefs_widget("status")), message);
atk_object_set_name(gtk_widget_get_accessible(prefs_widget("status")), message);
+18
View File
@@ -104,3 +104,21 @@ void prefs_extension_option(const char *page, const char *id, const char *option
void prefs_extension_set(const char *page, const char *id, int kind, const char *text, int checked);
const char *prefs_extension_text(const char *page, const char *id, int kind);
int prefs_extension_checked(const char *page, const char *id);
void prefs_profiles_init(void);
void prefs_profiles_clear(void);
void prefs_profiles_append(const char *name);
void prefs_profiles_select(int index, int count);
int prefs_profiles_selected(void);
void prefs_profile_begin(void);
void prefs_profile_control(const char *id, const char *label, int kind, int row, int maxLength, double minimum, double maximum, double step);
void prefs_profile_option(const char *id, const char *label);
void prefs_profile_clear(const char *id);
void prefs_profile_set(const char *id, int kind, const char *text, double number, int selected, int hidden);
const char *prefs_profile_text(const char *id);
double prefs_profile_number(const char *id);
int prefs_profile_selected(const char *id);
void prefs_profile_show(void);
int prefs_profile_response(void);
void prefs_profile_status(const char *message);
void prefs_profile_close(void);
+145
View File
@@ -0,0 +1,145 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
#include "native_internal.h"
static GtkWidget *profilePage, *profileCombo, *profileAdd, *profileEdit, *profileRemove, *profileUse;
static GtkWidget *profileDialog, *profileGrid, *profileStatus;
static GHashTable *profileWidgets, *profileRows;
static int profileResponse;
static void profile_combo_changed(GtkComboBox *combo, gpointer data) {
(void)data;
const char *label = g_object_get_data(G_OBJECT(combo), "profile-label");
prefs_describe_combo(GTK_WIDGET(combo), label);
}
static void profile_action(GtkButton *button, gpointer data) {
(void)button;
prefs_set_action(GPOINTER_TO_INT(data));
}
void prefs_profiles_init(void) {
profilePage = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
gtk_container_set_border_width(GTK_CONTAINER(profilePage), 12);
profileCombo = gtk_combo_box_text_new();
atk_object_set_name(gtk_widget_get_accessible(profileCombo), "Voice Profiles");
gtk_box_pack_start(GTK_BOX(profilePage), profileCombo, FALSE, FALSE, 0);
GtkWidget **buttons[] = {&profileAdd, &profileEdit, &profileRemove, &profileUse};
const char *labels[] = {"Add Voice Profile", "Edit Voice Profile", "Remove Voice Profile", "Use Voice Profile"};
for (unsigned i = 0; i < G_N_ELEMENTS(buttons); i++) {
*buttons[i] = gtk_button_new_with_label(labels[i]);
g_signal_connect(*buttons[i], "clicked", G_CALLBACK(profile_action), GINT_TO_POINTER(30 + i));
gtk_box_pack_start(GTK_BOX(profilePage), *buttons[i], FALSE, FALSE, 0);
}
gtk_notebook_append_page(GTK_NOTEBOOK(prefs_widget("notebook")), profilePage, gtk_label_new("Voice Profiles"));
gtk_widget_show_all(profilePage);
}
void prefs_profiles_clear(void) {
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(profileCombo));
}
void prefs_profiles_append(const char *name) {
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(profileCombo), name);
}
void prefs_profiles_select(int index, int count) {
gtk_combo_box_set_active(GTK_COMBO_BOX(profileCombo), count ? MAX(0, MIN(index, count - 1)) : -1);
gtk_widget_set_visible(profileCombo, count > 0);
gtk_widget_set_visible(profileEdit, count > 0);
gtk_widget_set_visible(profileRemove, count > 0);
gtk_widget_set_visible(profileUse, count > 0);
GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(prefs_widget("window")));
if (focus && !gtk_widget_is_visible(focus)) gtk_widget_grab_focus(profileAdd);
}
int prefs_profiles_selected(void) { return gtk_combo_box_get_active(GTK_COMBO_BOX(profileCombo)); }
static void profile_response(GtkDialog *dialog, int response, gpointer data) {
(void)dialog; (void)data;
profileResponse = response == GTK_RESPONSE_OK ? 1 : 2;
}
void prefs_profile_begin(void) {
profileResponse = 0;
profileDialog = gtk_dialog_new_with_buttons("Voice Profile", GTK_WINDOW(prefs_widget("window")),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, NULL);
gtk_window_set_default_size(GTK_WINDOW(profileDialog), 480, -1);
g_signal_connect(profileDialog, "response", G_CALLBACK(profile_response), NULL);
profileGrid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(profileGrid), 8);
gtk_grid_set_column_spacing(GTK_GRID(profileGrid), 12);
gtk_container_set_border_width(GTK_CONTAINER(profileGrid), 12);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(profileDialog))), profileGrid, TRUE, TRUE, 0);
profileWidgets = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
profileRows = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
profileStatus = gtk_label_new("");
atk_object_set_name(gtk_widget_get_accessible(profileStatus), "Voice profile status");
gtk_widget_set_can_focus(profileStatus, TRUE);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(profileDialog))), profileStatus, FALSE, FALSE, 4);
}
void prefs_profile_control(const char *id, const char *label, int kind, int row, int maxLength, double minimum, double maximum, double step) {
GtkWidget *widget;
if (kind == 4) {
widget = gtk_dialog_add_button(GTK_DIALOG(profileDialog), label, g_str_equal(id, "save") ? GTK_RESPONSE_OK : GTK_RESPONSE_CANCEL);
g_hash_table_insert(profileWidgets, g_strdup(id), widget);
return;
}
if (kind == 2) {
widget = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(widget), maxLength);
if (g_str_equal(id, "name")) atk_object_set_description(gtk_widget_get_accessible(widget), "Leave blank to use the synthesizer and voice name");
} else if (kind == 1) {
widget = gtk_spin_button_new_with_range(minimum, maximum, step);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(widget), TRUE);
} else {
widget = gtk_combo_box_text_new();
g_object_set_data_full(G_OBJECT(widget), "profile-label", g_strdup(label), g_free);
g_signal_connect(widget, "changed", G_CALLBACK(profile_combo_changed), NULL);
}
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
GtkWidget *caption = gtk_label_new(label);
gtk_label_set_mnemonic_widget(GTK_LABEL(caption), widget);
atk_object_set_name(gtk_widget_get_accessible(widget), label);
gtk_widget_set_hexpand(widget, TRUE);
gtk_box_pack_start(GTK_BOX(box), caption, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), widget, TRUE, TRUE, 0);
gtk_grid_attach(GTK_GRID(profileGrid), box, 0, row, 1, 1);
g_hash_table_insert(profileWidgets, g_strdup(id), widget);
g_hash_table_insert(profileRows, g_strdup(id), box);
}
void prefs_profile_option(const char *id, const char *label) {
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g_hash_table_lookup(profileWidgets, id)), label);
}
void prefs_profile_clear(const char *id) {
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(g_hash_table_lookup(profileWidgets, id)));
}
void prefs_profile_set(const char *id, int kind, const char *text, double number, int selected, int hidden) {
GtkWidget *widget = g_hash_table_lookup(profileWidgets, id);
if (kind == 2) gtk_entry_set_text(GTK_ENTRY(widget), text);
if (kind == 1) gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), number);
if (kind == 5) gtk_combo_box_set_active(GTK_COMBO_BOX(widget), selected);
GtkWidget *row = g_hash_table_lookup(profileRows, id);
if (row) { gtk_widget_set_no_show_all(row, hidden); if (!hidden) gtk_widget_show_all(row); else gtk_widget_hide(row); }
}
const char *prefs_profile_text(const char *id) {
return gtk_entry_get_text(GTK_ENTRY(g_hash_table_lookup(profileWidgets, id)));
}
double prefs_profile_number(const char *id) {
GtkSpinButton *spin = GTK_SPIN_BUTTON(g_hash_table_lookup(profileWidgets, id));
gtk_spin_button_update(spin);
return gtk_spin_button_get_value(spin);
}
int prefs_profile_selected(const char *id) {
return gtk_combo_box_get_active(GTK_COMBO_BOX(g_hash_table_lookup(profileWidgets, id)));
}
void prefs_profile_show(void) {
gtk_widget_show_all(profileDialog);
gtk_widget_grab_focus(g_hash_table_lookup(profileWidgets, "name"));
}
int prefs_profile_response(void) { int response = profileResponse; profileResponse = 0; return response; }
void prefs_profile_status(const char *message) {
gtk_label_set_text(GTK_LABEL(profileStatus), message);
atk_object_set_name(gtk_widget_get_accessible(profileStatus), message);
gtk_widget_grab_focus(profileStatus);
}
void prefs_profile_close(void) {
if (!profileDialog) return;
gtk_widget_destroy(profileDialog);
g_hash_table_destroy(profileWidgets);
g_hash_table_destroy(profileRows);
profileDialog = NULL;
gtk_widget_grab_focus(profileAdd);
}
+2
View File
@@ -13,9 +13,11 @@ import (
"git.stormux.org/storm/cthulhu/internal/speech"
"git.stormux.org/storm/cthulhu/internal/tentacle"
"git.stormux.org/storm/cthulhu/internal/tentaclewire"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
)
type Values struct {
VoiceProfiles voiceprofiles.Collection
StructuralNavigationTriggersFocusMode bool
// Wine is global-only: it is edited only in global preferences, and
+6
View File
@@ -9,11 +9,17 @@ import (
"git.stormux.org/storm/cthulhu/internal/config"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/speech"
ui "git.stormux.org/storm/screenreader-common/internalui"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
)
// uiSession lives for one helper window. Only the locked GTK thread in Run
// accesses these fields; pipe readers deliver immutable responses by channel.
type uiSession struct {
profiles voiceprofiles.Collection
profileEditor *voiceprofiles.Editor
profileIndex int
profileControls []ui.Control
extensionPages []ExtensionPage
progressBar config.ProgressBarSettings
wine config.WineSettings
+10
View File
@@ -66,6 +66,9 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
}
session := &uiSession{catalog: initial.Catalog, speechDefaults: initial.SpeechDefaults, soundThemes: []string{"default", "none"},
wineEditable: initial.Application == ""}
if session.wineEditable {
C.prefs_profiles_init()
}
session.setValues(initial.Values)
if err := session.set_extension_pages(initial.ExtensionPages); err != nil {
return err
@@ -142,10 +145,17 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
status(response.Message, !response.Accepted)
case <-ticker.C:
C.prefs_iterate()
if session.profile_tick() {
continue
}
session.refreshEchoVoices()
session.refreshSpeechVoices()
session.refreshKeyBindingLayout()
action := C.prefs_action()
if action >= 30 && action <= 33 && !busy && session.wineEditable {
session.profile_action(int(action))
continue
}
if action >= C.PREFS_TENTACLE_REPOSITORY_ADD && action <= C.PREFS_TENTACLE_UPDATE && !busy {
request, err := tentacles.action(int(action))
if err != nil {
+3
View File
@@ -5,6 +5,8 @@
package preferences
func (session *uiSession) setValues(values Values) {
session.profiles = values.VoiceProfiles.Clone()
session.populate_profiles(0)
// The Wine page exists only in global preferences. Application
// preferences retain the values their base carries and submit them
// unchanged, so they are never a Wine editing surface.
@@ -28,6 +30,7 @@ func (session *uiSession) setValues(values Values) {
func (session *uiSession) getValues() (Values, error) {
var values Values
values.VoiceProfiles = session.profiles.Clone()
var err error
if session.wineEditable {
if values.Wine, err = getWineValues(); err != nil {
+2 -1
View File
@@ -12,7 +12,7 @@ import (
)
func FromSettings(settings config.Settings) Values {
return Values{StructuralNavigationTriggersFocusMode: settings.StructuralNavigationTriggersFocusMode, Wine: cloneWineSettings(settings.Wine), OCR: settings.OCR, Pronunciations: append([]config.PronunciationEntry(nil), settings.Pronunciations...),
return Values{VoiceProfiles: settings.VoiceProfiles.Clone(), StructuralNavigationTriggersFocusMode: settings.StructuralNavigationTriggersFocusMode, Wine: cloneWineSettings(settings.Wine), OCR: settings.OCR, Pronunciations: append([]config.PronunciationEntry(nil), settings.Pronunciations...),
TextAttributes: config.TextAttributeSettings{Choices: append([]config.TextAttributeChoice(nil), settings.TextAttributes.Choices...), Indicator: settings.TextAttributes.Indicator},
KeyboardLayout: settings.KeyboardLayout, CthulhuModifierKeys: append([]string(nil), settings.CthulhuModifierKeys...),
KeyBindings: input.CloneBindingOverrides(settings.KeyBindings), TimeFormat: settings.TimeFormat, DateFormat: settings.DateFormat,
@@ -78,6 +78,7 @@ func (values Values) Merge(settings config.Settings) (config.Settings, error) {
if err != nil {
return settings, err
}
settings.VoiceProfiles = values.VoiceProfiles.Clone()
settings.Wine = wine
settings.Pronunciations = append([]config.PronunciationEntry(nil), values.Pronunciations...)
settings.TextAttributes = config.TextAttributeSettings{Choices: append([]config.TextAttributeChoice(nil), values.TextAttributes.Choices...), Indicator: values.TextAttributes.Indicator}
+185
View File
@@ -0,0 +1,185 @@
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package preferences
/*
#include <stdlib.h>
#include "native.h"
*/
import "C"
import (
"git.stormux.org/storm/cthulhu/internal/config"
ui "git.stormux.org/storm/screenreader-common/internalui"
"git.stormux.org/storm/screenreader-common/voiceprofiles"
"unsafe"
)
func (session *uiSession) populate_profiles(index int) {
if !session.wineEditable {
return
}
C.prefs_profiles_clear()
for _, p := range session.profiles.Profiles {
name := C.CString(p.Name)
C.prefs_profiles_append(name)
C.free(unsafe.Pointer(name))
}
C.prefs_profiles_select(C.int(index), C.int(len(session.profiles.Profiles)))
}
func (session *uiSession) profile_action(action int) {
index := int(C.prefs_profiles_selected())
if action == 32 {
session.profiles = session.profiles.Remove(index)
session.populate_profiles(index)
return
}
if action == 33 {
if index < 0 || index >= len(session.profiles.Profiles) {
return
}
values, err := session.getValues()
if err != nil {
status(err.Error(), true)
return
}
settings := primary_settings(values)
next, err := config.Apply_primary_voice(settings, session.profiles.Profiles[index])
if err != nil {
status(err.Error(), true)
return
}
session.activeVoiceType = 0
session.setSpeechVoice(FromSettings(next))
return
}
values, err := session.getValues()
if err != nil {
status(err.Error(), true)
return
}
settings := primary_settings(values)
p := config.Primary_voice(settings)
p.Name = ""
if p.Device == "" {
p.Device = "/dev/ttyUSB0"
}
if p.BaudRate == 0 {
p.BaudRate = 9600
}
if action == 31 {
if index < 0 || index >= len(session.profiles.Profiles) {
return
}
p = session.profiles.Profiles[index]
} else {
index = -1
}
drivers := []voiceprofiles.Driver{}
for _, d := range voiceprofiles.Drivers() {
if d.ID != "dectalk-usb" {
drivers = append(drivers, d)
}
}
session.profileEditor = voiceprofiles.New_editor(p, drivers, session.catalog)
session.profileIndex = index
session.profileControls = session.profileEditor.Form().Tabs[0].Controls
C.prefs_profile_begin()
for row, c := range session.profileControls {
id, label := C.CString(c.ID), C.CString(c.Label)
C.prefs_profile_control(id, label, C.int(c.Kind), C.int(row), C.int(c.MaxLength), C.double(c.Min), C.double(c.Max), C.double(c.Step))
C.free(unsafe.Pointer(id))
C.free(unsafe.Pointer(label))
set_profile_control(c)
}
C.prefs_profile_show()
}
func set_profile_control(c ui.Control) {
id, text := C.CString(c.ID), C.CString(c.Text)
defer C.free(unsafe.Pointer(id))
defer C.free(unsafe.Pointer(text))
if c.Kind == ui.ComboBox {
C.prefs_profile_clear(id)
for _, option := range c.Choices {
label := C.CString(option.Label)
C.prefs_profile_option(id, label)
C.free(unsafe.Pointer(label))
}
}
C.prefs_profile_set(id, C.int(c.Kind), text, C.double(c.Number), C.int(c.Selected), boolean(c.Hidden))
}
func (session *uiSession) profile_tick() bool {
if session.profileEditor == nil {
return false
}
values := map[string]ui.Control{}
for _, c := range session.profileControls {
id := C.CString(c.ID)
switch c.Kind {
case ui.Entry:
c.Text = C.GoString(C.prefs_profile_text(id))
case ui.Number:
c.Number = float64(C.prefs_profile_number(id))
case ui.ComboBox:
c.Selected = int(C.prefs_profile_selected(id))
}
C.free(unsafe.Pointer(id))
values[voiceprofiles.PageID+"."+c.ID] = c
}
for _, c := range session.profileEditor.Refresh(values) {
// Hidden entries retain their edited contents; only combo choices change.
if c.Kind == ui.Entry {
c.Text = values[voiceprofiles.PageID+"."+c.ID].Text
}
set_profile_control(c)
values[voiceprofiles.PageID+"."+c.ID] = c
for index, old := range session.profileControls {
if old.ID == c.ID {
session.profileControls[index] = c
break
}
}
}
response := int(C.prefs_profile_response())
if response == 0 {
return true
}
if response == 1 {
p, err := session.profileEditor.Read(values)
if err == nil {
session.profiles, err = session.profiles.Put(session.profileIndex, p)
if err == nil && session.profileIndex < 0 {
session.profileIndex = len(session.profiles.Profiles) - 1
}
}
if err != nil {
text := C.CString(err.Error())
C.prefs_profile_status(text)
C.free(unsafe.Pointer(text))
return true
}
}
C.prefs_profile_close()
session.profileEditor = nil
session.populate_profiles(max(0, session.profileIndex))
return true
}
func primary_settings(values Values) config.Settings {
settings := config.DefaultSettings()
settings.SpeechServerFactory = values.SpeechServerFactory
settings.SpeechOutputModule = values.SpeechOutputModule
settings.HardwareSpeechDevice = values.HardwareSpeechDevice
settings.HardwareSpeechBaudRate = values.HardwareSpeechBaudRate
settings.DefaultVoice = config.Voice{Rate: values.Rate, AveragePitch: values.Pitch, Gain: values.Volume, Family: values.SpeechVoiceFamily}
settings.UppercaseVoice = values.UppercaseVoice
settings.HyperlinkVoice = values.HyperlinkVoice
settings.SystemVoice = values.SystemVoice
settings.UseCustomEchoVoice = values.UseCustomEchoVoice
settings.UseCustomEchoSpeechServer = values.UseCustomEchoSpeechServer
return settings
}