Adopt common v0.8.0 and preserve canceled hardware settings

This commit is contained in:
Storm Dragon committed 2026-11-16 20:10:47 -05:00
1 parent b21fceb311
commit 5dfa038706
410 files changed
+5353 -4803

No files matched your search

+5 -5
View File
@@ -31,7 +31,7 @@ type applicationIdentity struct {
pid int
}
func application_choices(accessible []applicationIdentity, windows []xorg.ApplicationWindow) []string {
func applicationChoices(accessible []applicationIdentity, windows []xorg.ApplicationWindow) []string {
names := make(map[string]bool)
byPID := make(map[int]string)
add := func(name string) {
@@ -61,7 +61,7 @@ func application_choices(accessible []applicationIdentity, windows []xorg.Applic
return choices
}
func running_applications() []string {
func runningApplications() []string {
var count C.int
native := C.prefs_application_names(&count)
defer C.prefs_free_application_names(native, count)
@@ -78,13 +78,13 @@ func running_applications() []string {
}
reader := xorg.OpenForegroundReader()
defer reader.Close()
return application_choices(accessible, reader.ApplicationWindows())
return applicationChoices(accessible, reader.ApplicationWindows())
}
// The chooser shares the preferences child and bounded pipe protocol. Cancel
// emits no request, so it cannot open a profile or submit settings.
func choose_application(ctx context.Context, updates <-chan Response, errorsIn <-chan error, output io.Writer) (Response, bool, error) {
choices := running_applications()
func chooseApplication(ctx context.Context, updates <-chan Response, errorsIn <-chan error, output io.Writer) (Response, bool, error) {
choices := runningApplications()
if C.prefs_application_chooser_init() == 0 {
return Response{}, false, errors.New("cannot open application chooser on this display")
}
+1 -1
View File
@@ -17,7 +17,7 @@ func TestApplicationChoicesUseProfileIdentityAndWineChildren(t *testing.T) {
{Application: "Example Editor", PID: 4},
}
want := []string{"Example Browser", "Example Editor", "Example Terminal", "Game.exe", "Other Unknown PID Application", "Unknown PID Application"}
if got := application_choices(accessible, windows); !reflect.DeepEqual(got, want) {
if got := applicationChoices(accessible, windows); !reflect.DeepEqual(got, want) {
t.Fatalf("applications = %v, want %v", got, want)
}
}
+2 -2
View File
@@ -42,7 +42,7 @@ func getBrailleIndicator(prefix string) int {
return 0
}
func (session *uiSession) set_braille_values(values Values) {
func (session *uiSession) setBrailleValues(values Values) {
setCheck("enableBrailleCheckButton", values.EnableBraille)
setCheck("contractedBrailleCheckButton", values.EnableContractedBraille)
setCheck("abbrevRolenames", values.Braille.AbbreviateRoles)
@@ -85,7 +85,7 @@ func (session *uiSession) set_braille_values(values Values) {
C.free(unsafe.Pointer(comboID))
}
func (session *uiSession) get_braille_values(values *Values) error {
func (session *uiSession) getBrailleValues(values *Values) error {
values.EnableBraille = getCheck("enableBrailleCheckButton")
values.EnableContractedBraille = getCheck("contractedBrailleCheckButton")
values.Braille.AbbreviateRoles = getCheck("abbrevRolenames")
+2 -2
View File
@@ -81,9 +81,9 @@ func EncodeInitial(encoder *json.Encoder, response Response) error {
return encoder.Encode(catalogPart{})
}
// read_responses owns catalog assembly for the lifetime of the helper pipe.
// readResponses owns catalog assembly for the lifetime of the helper pipe.
// Only complete responses reach GTK, including after application selection.
func read_responses(ctx context.Context, input io.Reader, updates chan<- Response, errorsIn chan<- error) {
func readResponses(ctx context.Context, input io.Reader, updates chan<- Response, errorsIn chan<- error) {
scanner := bufio.NewScanner(input)
scanner.Buffer(make([]byte, 4096), 1024*1024)
var initial *Response
@@ -51,7 +51,7 @@ func TestInitialCatalogRoundTrip(t *testing.T) {
}
updates := make(chan Response, 3)
errorsIn := make(chan error, 1)
read_responses(t.Context(), &wire, updates, errorsIn)
readResponses(t.Context(), &wire, updates, errorsIn)
if err := <-errorsIn; err != nil {
t.Fatal(err)
}
@@ -82,13 +82,13 @@ func TestInitialCatalogRejectsOversizedEntry(t *testing.T) {
func TestInitialCatalogIncompleteAndCancellation(t *testing.T) {
updates := make(chan Response, 1)
errorsIn := make(chan error, 1)
read_responses(t.Context(), strings.NewReader(`{"CatalogPending":true}`+"\n"), updates, errorsIn)
readResponses(t.Context(), strings.NewReader(`{"CatalogPending":true}`+"\n"), updates, errorsIn)
if err := <-errorsIn; !errors.Is(err, io.ErrUnexpectedEOF) || len(updates) != 0 {
t.Fatalf("incomplete catalog reached the UI: %v", err)
}
ctx, cancel := context.WithCancel(t.Context())
cancel()
read_responses(ctx, strings.NewReader("{}\n"), make(chan Response), errorsIn)
readResponses(ctx, strings.NewReader("{}\n"), make(chan Response), errorsIn)
}
func TestDefaultVoicesFiltersESpeakAndDefaultAlias(t *testing.T) {
@@ -96,18 +96,18 @@ func TestDefaultVoicesFiltersESpeakAndDefaultAlias(t *testing.T) {
voices := []speech.Voice{{Name: "German", Language: "de"}, {Name: "English", Language: "en-US"}}
session := &uiSession{catalog: speech.Catalog{"": voices, "espeak-ng": voices, "other": voices}}
for _, module := range []string{"", "espeak-ng"} {
if got := session.default_voices(module); !reflect.DeepEqual(got, voices[1:]) {
if got := session.defaultVoices(module); !reflect.DeepEqual(got, voices[1:]) {
t.Fatalf("module %q: %v", module, got)
}
}
if got := session.default_voices("other"); !reflect.DeepEqual(got, voices) {
if got := session.defaultVoices("other"); !reflect.DeepEqual(got, voices) {
t.Fatal("other synthesizer was filtered")
}
if !reflect.DeepEqual(session.catalog["espeak-ng"], voices) {
t.Fatal("language selection lost the full catalog")
}
session.catalog[""] = voices[:1]
if got := session.default_voices(""); !reflect.DeepEqual(got, voices[:1]) {
if got := session.defaultVoices(""); !reflect.DeepEqual(got, voices[:1]) {
t.Fatal("unidentified default synthesizer was filtered")
}
}
+2 -2
View File
@@ -11,10 +11,10 @@ import (
"git.stormux.org/storm/cthulhu/internal/speech"
)
// default_voices filters eSpeak's language/variant combinations for controls
// defaultVoices filters eSpeak's language/variant combinations for controls
// without an explicit language selection. Saved voices remain available through
// the caller's selected-family entry, and the full language catalog is retained.
func (session *uiSession) default_voices(module string) []speech.Voice {
func (session *uiSession) defaultVoices(module string) []speech.Voice {
voices := session.catalog[module]
if strings.Contains(strings.ToLower(module), "espeak") {
return speech.LocaleVoices(voices)
+3 -3
View File
@@ -103,7 +103,7 @@ func (session *uiSession) populateEchoFamilies(module string, selected *config.V
session.echoFamilies = []*config.VoiceFamily{nil}
labels := []string{"Default"}
index := 0
for _, voice := range session.default_voices(module) {
for _, voice := range session.defaultVoices(module) {
family := &config.VoiceFamily{Name: voice.Name, Lang: voice.Language, Variant: voice.Variant}
session.echoFamilies = append(session.echoFamilies, family)
labels = append(labels, voice.Name+" ("+voice.Language+")")
@@ -154,7 +154,7 @@ func (session *uiSession) getEchoVoice() (config.Voice, string) {
return voice, session.selectedEchoModule()
}
func set_echo_checks(values Values) {
func setEchoChecks(values Values) {
setCheck("keyEchoDisabledRadio", !values.EnableKeyEcho)
setCheck("keyEchoEnabledRadio", values.EnableKeyEcho && !values.KeyEchoInEditFieldsOnly)
setCheck("keyEchoEditFieldsRadio", values.EnableKeyEcho && values.KeyEchoInEditFieldsOnly)
@@ -163,7 +163,7 @@ func set_echo_checks(values Values) {
}
}
func get_echo_checks(values *Values) {
func getEchoChecks(values *Values) {
values.EnableKeyEcho = !getCheck("keyEchoDisabledRadio")
values.KeyEchoInEditFieldsOnly = getCheck("keyEchoEditFieldsRadio")
for _, check := range echoChecks(values) {
+14 -15
View File
@@ -11,20 +11,19 @@ import "C"
import (
"fmt"
"git.stormux.org/storm/cthulhu/internal/interaction"
"git.stormux.org/storm/cthulhu/internal/tentaclewire"
"unsafe"
)
func extension_page_key(page ExtensionPage) string { return page.Session + "/" + page.ID }
func extensionPageKey(page ExtensionPage) string { return page.Session + "/" + page.ID }
// GTK owns native focus. Refreshes keep unchanged widgets and their unapplied
// drafts, and move focus to the notebook before removing a revoked page.
func (session *uiSession) set_extension_pages(pages []ExtensionPage) error {
func (session *uiSession) setExtensionPages(pages []ExtensionPage) error {
selected := C.GoString(C.prefs_extension_selected())
ids := map[string]bool{}
for _, page := range pages {
key := extension_page_key(page)
key := extensionPageKey(page)
if page.Session == "" || ids[key] {
return fmt.Errorf("invalid extension page identity")
}
@@ -35,9 +34,9 @@ func (session *uiSession) set_extension_pages(pages []ExtensionPage) error {
}
keep := map[string]bool{}
for _, previous := range session.extensionPages {
key := extension_page_key(previous)
key := extensionPageKey(previous)
for _, page := range pages {
if extension_page_key(page) == key && page.Revision == previous.Revision {
if extensionPageKey(page) == key && page.Revision == previous.Revision {
keep[key] = true
break
}
@@ -49,7 +48,7 @@ func (session *uiSession) set_extension_pages(pages []ExtensionPage) error {
}
}
for _, page := range pages {
key := extension_page_key(page)
key := extensionPageKey(page)
if keep[key] {
continue
}
@@ -68,7 +67,7 @@ func (session *uiSession) set_extension_pages(pages []ExtensionPage) error {
}
value := page.Values[element.ID]
text := value.Text
if element.Kind == interaction.List {
if element.Kind == tentaclewire.List {
text = value.Selected
}
cText := C.CString(text)
@@ -86,20 +85,20 @@ func (session *uiSession) set_extension_pages(pages []ExtensionPage) error {
}
return nil
}
func (session *uiSession) extension_drafts() ([]PageDraft, error) {
func (session *uiSession) extensionDrafts() ([]PageDraft, error) {
var drafts []PageDraft
for _, page := range session.extensionPages {
values := map[string]interaction.Value{}
key := C.CString(extension_page_key(page))
values := map[string]tentaclewire.Value{}
key := C.CString(extensionPageKey(page))
for _, element := range page.Elements {
id := C.CString(element.ID)
value := interaction.Value{}
value := tentaclewire.Value{}
switch element.Kind {
case interaction.List:
case tentaclewire.List:
value.Selected = C.GoString(C.prefs_extension_text(key, id, C.int(element.Kind)))
case interaction.Entry:
case tentaclewire.Entry:
value.Text = C.GoString(C.prefs_extension_text(key, id, C.int(element.Kind)))
case interaction.CheckBox:
case tentaclewire.CheckBox:
value.Checked = C.prefs_extension_checked(key, id) != 0
}
C.free(unsafe.Pointer(id))
+3 -3
View File
@@ -15,8 +15,8 @@ import (
"time"
"unsafe"
"git.stormux.org/storm/cthulhu/internal/datetime"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/screenreader-common/datetime"
)
func setFormatCombo(name string, options []datetime.Option, value string) {
@@ -40,7 +40,7 @@ func formatIndex(options []datetime.Option, value string) int {
return 0
}
func (session *uiSession) set_general_values(values Values) {
func (session *uiSession) setGeneralValues(values Values) {
setCheck("structuralNavigationFocusCheckButton", values.StructuralNavigationTriggersFocusMode)
session.progressBar = values.ProgressBar
session.setKeyBindings(values)
@@ -51,7 +51,7 @@ func (session *uiSession) set_general_values(values Values) {
setFormatCombo("dateFormatCombo", datetime.DateOptions(now), values.DateFormat)
}
func (session *uiSession) get_general_values(values *Values) error {
func (session *uiSession) getGeneralValues(values *Values) error {
values.StructuralNavigationTriggersFocusMode = getCheck("structuralNavigationFocusCheckButton")
values.KeyBindings = input.CloneBindingOverrides(session.bindingDraft)
values.KeyboardLayout = 1
+1 -1
View File
@@ -37,7 +37,7 @@ void prefs_hardware_devices_clear(void);
void prefs_hardware_device_append(const char *text);
void prefs_hardware_device_set(const char *text);
const char *prefs_hardware_device_get(void);
void prefs_hardware_sensitivity(int enabled);
void prefs_hardware_sensitivity(int enabled, int serial);
void prefs_combo_set(const char *id, int value);
int prefs_combo_get(const char *id);
+3 -3
View File
@@ -59,9 +59,9 @@ void prefs_hardware_device_set(const char *text) {
const char *prefs_hardware_device_get(void) {
return gtk_entry_get_text(GTK_ENTRY(prefs_widget("hardwareDeviceEntry")));
}
void prefs_hardware_sensitivity(int enabled) {
gtk_widget_set_sensitive(prefs_widget("hardwareDeviceEntry"), enabled);
gtk_widget_set_sensitive(prefs_widget("hardwareBaudCombo"), enabled);
void prefs_hardware_sensitivity(int enabled, int serial) {
gtk_widget_set_sensitive(prefs_widget("hardwareDeviceEntry"), enabled && serial);
gtk_widget_set_sensitive(prefs_widget("hardwareBaudCombo"), enabled && serial);
gtk_widget_set_sensitive(prefs_widget("speechLanguages"), !enabled);
gtk_widget_set_sensitive(prefs_widget("speechFamilies"), !enabled);
}
+1 -2
View File
@@ -9,7 +9,6 @@ package preferences
import (
"git.stormux.org/storm/cthulhu/internal/config"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/interaction"
"git.stormux.org/storm/cthulhu/internal/speech"
"git.stormux.org/storm/cthulhu/internal/tentacle"
"git.stormux.org/storm/cthulhu/internal/tentaclewire"
@@ -103,7 +102,7 @@ type PageDraft struct {
Session string
ID string
Revision uint64
Values map[string]interaction.Value
Values map[string]tentaclewire.Value
}
type Request struct {
+4 -4
View File
@@ -46,26 +46,26 @@ func (session *uiSession) setSoundTheme(theme string) {
comboItems("soundThemeCombo", labels, selected)
}
func set_sound_checks(values Values) {
func setSoundChecks(values Values) {
for _, check := range soundChecks(&values) {
setCheck(check.id, *check.value)
}
}
func (session *uiSession) set_sound_values(values Values) {
func (session *uiSession) setSoundValues(values Values) {
setRange("soundVolumeScale", values.SoundVolume)
setCombo("soundSinkCombo", map[string]int{"auto": 0, "pipewire": 1, "pulse": 2, "alsa": 3}[values.SoundSink])
session.setSoundTheme(values.SoundTheme)
setCombo("roleSoundPresentationCombo", map[string]int{"sound_and_speech": 0, "speech_only": 1, "sound_only": 2}[values.RoleSoundPresentation])
}
func get_sound_checks(values *Values) {
func getSoundChecks(values *Values) {
for _, check := range soundChecks(values) {
*check.value = getCheck(check.id)
}
}
func (session *uiSession) get_sound_values(values *Values) error {
func (session *uiSession) getSoundValues(values *Values) error {
values.SoundVolume = getRange("soundVolumeScale")
sink, theme, presentation := getCombo("soundSinkCombo"), getCombo("soundThemeCombo"), getCombo("roleSoundPresentationCombo")
if sink < 0 || sink > 3 || theme < 0 || theme >= len(session.soundThemes) || presentation < 0 || presentation > 2 {
+32 -23
View File
@@ -57,23 +57,23 @@ func (session *uiSession) setSpeechVoice(values Values) {
}
}
setCombo("hardwareBaudCombo", baudIndex)
C.prefs_hardware_sensitivity(C.int(session.activeSpeechSystem))
session.populateSpeechModules(values)
session.load_voice_editor()
session.updateHardwareSensitivity()
session.loadVoiceEditor()
}
var hardwareBaudRates = []int{1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200}
func (session *uiSession) populateSpeechModules(values Values) {
if session.activeSpeechSystem == 1 {
session.speechModules = []string{"litetalk", "doubletalk", "tripletalk", "dectalk"}
session.speechModules = []string{"litetalk", "doubletalk", "tripletalk", "dectalk", "dectalk-usb"}
selected := 0
for index, module := range session.speechModules {
if module == values.SpeechOutputModule {
selected = index
}
}
comboItems("speechServers", []string{"LiteTalk", "DoubleTalk", "TripleTalk", "DECtalk"}, selected)
comboItems("speechServers", []string{"LiteTalk", "DoubleTalk", "TripleTalk", "DECtalk", "DECtalk USB"}, selected)
session.activeSpeechModule = session.speechModules[selected]
comboItems("speechLanguages", []string{"Default"}, 0)
comboItems("speechFamilies", []string{"Default"}, 0)
@@ -143,7 +143,7 @@ func (session *uiSession) populateSpeechFamilies(module, language string, select
index := 0
voices := session.catalog[module]
if language == "" {
voices = session.default_voices(module)
voices = session.defaultVoices(module)
}
for _, voice := range voices {
if language != "" && !strings.EqualFold(voice.Language, language) {
@@ -165,6 +165,14 @@ func (session *uiSession) populateSpeechFamilies(module, language string, select
comboItems("speechFamilies", labels, index)
}
// updateHardwareSensitivity enables the serial device and baud rate only for
// hardware synthesizers that use them; DECtalk USB finds its own device.
func (session *uiSession) updateHardwareSensitivity() {
hardware := session.activeSpeechSystem == 1
serial := !hardware || session.selectedSpeechModule() != "dectalk-usb"
C.prefs_hardware_sensitivity(C.int(session.activeSpeechSystem), boolean(serial))
}
func (session *uiSession) selectedSpeechModule() string {
i := getCombo("speechServers")
if i >= 0 && i < len(session.speechModules) {
@@ -190,7 +198,7 @@ func (session *uiSession) selectedSpeechFamily() *config.VoiceFamily {
func (session *uiSession) refreshSpeechVoices() {
voiceType := getCombo("voiceTypesCombo")
if voiceType >= 0 && voiceType < len(session.voiceDrafts) && voiceType != session.activeVoiceType {
voice, err := session.read_voice_editor()
voice, err := session.readVoiceEditor()
if err != nil {
status(err.Error(), true)
setCombo("voiceTypesCombo", session.activeVoiceType)
@@ -198,12 +206,12 @@ func (session *uiSession) refreshSpeechVoices() {
}
session.voiceDrafts[session.activeVoiceType] = voice
session.activeVoiceType = voiceType
session.load_voice_editor()
session.loadVoiceEditor()
return
}
system := getCombo("speechSystems")
if system != session.activeSpeechSystem {
if voice, err := session.read_voice_editor(); err == nil {
if voice, err := session.readVoiceEditor(); err == nil {
session.voiceDrafts[session.activeVoiceType] = voice
}
if session.activeSpeechSystem == 0 {
@@ -217,21 +225,22 @@ func (session *uiSession) refreshSpeechVoices() {
module = session.hardwareModule
}
session.populateSpeechModules(Values{SpeechOutputModule: module})
C.prefs_hardware_sensitivity(C.int(system))
session.updateHardwareSensitivity()
if system == 0 {
session.reconcile_voice_families(session.selectedSpeechModule())
session.reconcileVoiceFamilies(session.selectedSpeechModule())
}
session.load_voice_editor()
session.loadVoiceEditor()
}
if system == 1 {
session.updateHardwareSensitivity()
return
}
module := session.selectedSpeechModule()
if module != session.activeSpeechModule {
if voice, err := session.read_voice_editor(); err == nil {
if voice, err := session.readVoiceEditor(); err == nil {
session.voiceDrafts[session.activeVoiceType] = voice
}
session.reconcile_voice_families(module)
session.reconcileVoiceFamilies(module)
session.populateSpeechLanguages(module, session.activeSpeechLanguage, session.voiceDrafts[session.activeVoiceType].Family)
return
}
@@ -245,7 +254,7 @@ func (session *uiSession) refreshSpeechVoices() {
}
}
func (session *uiSession) reconcile_voice_families(module string) {
func (session *uiSession) reconcileVoiceFamilies(module string) {
for index, voice := range session.voiceDrafts {
family := voice.Family
if family == nil {
@@ -273,7 +282,7 @@ func (session *uiSession) reconcile_voice_families(module string) {
}
}
func set_speech_support(values Values) {
func setSpeechSupport(values Values) {
setCheck("interruptAllKeysRadio", values.SpeechInterruption.Mode != input.InterruptCommonKeys && values.SpeechInterruption.Mode != input.InterruptCustomKeys)
setCheck("interruptCommonKeysRadio", values.SpeechInterruption.Mode == input.InterruptCommonKeys)
setCheck("interruptCustomKeysRadio", values.SpeechInterruption.Mode == input.InterruptCustomKeys)
@@ -294,7 +303,7 @@ func set_speech_support(values Values) {
setCheck("indentationSpeechAndBeepsButton", mode == "both")
}
func set_speech_numbers(values Values, inherited config.Voice, defaults speech.Settings) {
func setSpeechNumbers(values Values, inherited config.Voice, defaults speech.Settings) {
for _, item := range []struct {
id string
value *float64
@@ -322,7 +331,7 @@ func set_speech_numbers(values Values, inherited config.Voice, defaults speech.S
}
}
func set_speech_presentation(values Values) {
func setSpeechPresentation(values Values) {
setChoice("punctuation", values.Punctuation)
setCheck("raisePitchForCapitals", values.RaisePitchForCapitals)
setCheck("beepForCapitals", values.BeepForCapitals)
@@ -330,7 +339,7 @@ func set_speech_presentation(values Values) {
setReading(values)
}
func get_speech_support(values *Values) {
func getSpeechSupport(values *Values) {
values.SpeechInterruption.Mode = input.InterruptAllKeys
if getCheck("interruptCommonKeysRadio") {
values.SpeechInterruption.Mode = input.InterruptCommonKeys
@@ -359,8 +368,8 @@ func get_speech_support(values *Values) {
}
}
func (session *uiSession) get_speech_values(values *Values) error {
voice, err := session.read_voice_editor()
func (session *uiSession) getSpeechValues(values *Values) error {
voice, err := session.readVoiceEditor()
if err != nil {
return err
}
@@ -392,7 +401,7 @@ func (session *uiSession) get_speech_values(values *Values) error {
return nil
}
func (session *uiSession) load_voice_editor() {
func (session *uiSession) loadVoiceEditor() {
voice := session.voiceDrafts[session.activeVoiceType]
settings := config.Settings{RaisePitchForCapitals: true, DefaultVoice: session.voiceDrafts[0], UppercaseVoice: session.voiceDrafts[1], HyperlinkVoice: session.voiceDrafts[2], SystemVoice: session.voiceDrafts[3]}
kind := []string{"default", "uppercase", "hyperlink", "system"}[session.activeVoiceType]
@@ -400,13 +409,13 @@ func (session *uiSession) load_voice_editor() {
if session.activeSpeechSystem == 1 {
defaults = speech.Settings{}
}
set_speech_numbers(Values{Rate: voice.Rate, Pitch: voice.AveragePitch, Volume: voice.Gain}, config.EffectiveVoice(settings, kind), defaults)
setSpeechNumbers(Values{Rate: voice.Rate, Pitch: voice.AveragePitch, Volume: voice.Gain}, config.EffectiveVoice(settings, kind), defaults)
if session.activeSpeechSystem != 1 {
session.populateSpeechLanguages(session.selectedSpeechModule(), "", voice.Family)
}
}
func (session *uiSession) read_voice_editor() (config.Voice, error) {
func (session *uiSession) readVoiceEditor() (config.Voice, error) {
voice := session.voiceDrafts[session.activeVoiceType]
for _, item := range []struct {
id string
+2 -2
View File
@@ -30,7 +30,7 @@ type tentaclePage struct {
selectedKey string
}
func tentacle_rows(snapshot *tentacle.Snapshot, origin string) []tentacleRow {
func tentacleRows(snapshot *tentacle.Snapshot, origin string) []tentacleRow {
if snapshot == nil {
return nil
}
@@ -99,7 +99,7 @@ func (page *tentaclePage) controls() {
}
func (page *tentaclePage) render() {
page.rows = tentacle_rows(page.snapshot, page.origin())
page.rows = tentacleRows(page.snapshot, page.origin())
C.prefs_tentacles_clear()
selectedRow := -1
for index, row := range page.rows {
+5 -5
View File
@@ -17,24 +17,24 @@ func TestTentacleRepositoryViewsAndRemovedSource(t *testing.T) {
{URL: second, ID: "example.second", Tentacles: []tentacle.Manifest{{ID: "echo"}}},
},
}
all := tentacle_rows(snapshot, "")
all := tentacleRows(snapshot, "")
if len(all) != 4 || !all[0].installed || !all[0].status.Entry.Enabled || all[2].installed || all[0].key == all[3].key {
t.Fatalf("All view: %+v", all)
}
filtered := tentacle_rows(snapshot, first)
filtered := tentacleRows(snapshot, first)
if len(filtered) != 2 || filtered[0].status.Entry.ID != "installed" || filtered[1].status.Entry.ID != "other" {
t.Fatalf("repository view: %+v", filtered)
}
snapshot.Repositories[0].ID = "example.replacement"
if replacement := tentacle_rows(snapshot, first); len(replacement) != 2 || replacement[0].installed {
if replacement := tentacleRows(snapshot, first); len(replacement) != 2 || replacement[0].installed {
t.Fatalf("replacement source claimed old installation: %+v", replacement)
}
snapshot.Repositories = snapshot.Repositories[1:]
remaining := tentacle_rows(snapshot, "")
remaining := tentacleRows(snapshot, "")
if len(remaining) != 3 || remaining[0].status.Entry.ID != "installed" {
t.Fatalf("removed source lost installed entry: %+v", remaining)
}
if rows := tentacle_rows(nil, ""); len(rows) != 0 {
if rows := tentacleRows(nil, ""); len(rows) != 0 {
t.Fatal(rows)
}
}
+8 -8
View File
@@ -37,7 +37,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
defer cancel()
updates := make(chan Response, 1)
errorsIn := make(chan error, 1)
go read_responses(ctx, input, updates, errorsIn)
go readResponses(ctx, input, updates, errorsIn)
var initial Response
select {
case initial = <-updates:
@@ -47,7 +47,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
return ctx.Err()
}
if initial.ChooseApplication {
response, chosen, err := choose_application(ctx, updates, errorsIn, output)
response, chosen, err := chooseApplication(ctx, updates, errorsIn, output)
if err != nil || !chosen {
return err
}
@@ -70,7 +70,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
C.prefs_profiles_init()
}
session.setValues(initial.Values)
if err := session.set_extension_pages(initial.ExtensionPages); err != nil {
if err := session.setExtensionPages(initial.ExtensionPages); err != nil {
return err
}
tentacles := &tentaclePage{}
@@ -96,7 +96,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
return err
case response := <-updates:
if response.ExtensionsOnly {
if err := session.set_extension_pages(response.ExtensionPages); err != nil {
if err := session.setExtensionPages(response.ExtensionPages); err != nil {
return err
}
continue
@@ -141,7 +141,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
busy, canSave = false, response.CanSave
if response.Accepted {
session.setValues(response.Values)
if err := session.set_extension_pages(response.ExtensionPages); err != nil {
if err := session.setExtensionPages(response.ExtensionPages); err != nil {
return err
}
C.prefs_voice_changed()
@@ -151,7 +151,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
status(response.Message, !response.Accepted)
case <-ticker.C:
C.prefs_iterate()
profileActive := session.profile_tick()
profileActive := session.profileTick()
if session.profilePreview != nil && !previewPending && !busy {
if err := encoder.Encode(Request{Values: *session.profilePreview, Preview: true}); err != nil {
return err
@@ -167,7 +167,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
session.refreshKeyBindingLayout()
action := C.prefs_action()
if action >= 30 && action <= 33 && !busy && session.wineEditable {
session.profile_action(int(action))
session.profileAction(int(action))
continue
}
if action >= C.PREFS_TENTACLE_REPOSITORY_ADD && action <= C.PREFS_TENTACLE_UPDATE && !busy {
@@ -219,7 +219,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
status(err.Error(), true)
continue
}
drafts, err := session.extension_drafts()
drafts, err := session.extensionDrafts()
if err != nil {
status(err.Error(), true)
continue
+15 -15
View File
@@ -6,7 +6,7 @@ package preferences
func (session *uiSession) setValues(values Values) {
session.profiles = values.VoiceProfiles.Clone()
session.populate_profiles(0)
session.populateProfiles(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.
@@ -17,15 +17,15 @@ func (session *uiSession) setValues(values Values) {
setPronunciations(values.Pronunciations)
setTextAttributes(values.TextAttributes)
setOCRValues(values.OCR)
session.set_general_values(values)
set_sound_checks(values)
set_speech_support(values)
session.set_braille_values(values)
session.set_sound_values(values)
session.setGeneralValues(values)
setSoundChecks(values)
setSpeechSupport(values)
session.setBrailleValues(values)
session.setSoundValues(values)
session.setEchoVoice(values)
session.setSpeechVoice(values)
set_echo_checks(values)
set_speech_presentation(values)
setEchoChecks(values)
setSpeechPresentation(values)
}
func (session *uiSession) getValues() (Values, error) {
@@ -44,20 +44,20 @@ func (session *uiSession) getValues() (Values, error) {
}
values.TextAttributes = getTextAttributes()
values.OCR = getOCRValues()
if err := session.get_general_values(&values); err != nil {
if err := session.getGeneralValues(&values); err != nil {
return values, err
}
get_sound_checks(&values)
get_speech_support(&values)
if err := session.get_braille_values(&values); err != nil {
getSoundChecks(&values)
getSpeechSupport(&values)
if err := session.getBrailleValues(&values); err != nil {
return values, err
}
if err := session.get_sound_values(&values); err != nil {
if err := session.getSoundValues(&values); err != nil {
return values, err
}
get_echo_checks(&values)
getEchoChecks(&values)
getReading(&values)
if err := session.get_speech_values(&values); err != nil {
if err := session.getSpeechValues(&values); err != nil {
return values, err
}
return values, nil
+26 -32
View File
@@ -16,7 +16,7 @@ import (
"unsafe"
)
func (session *uiSession) populate_profiles(index int) {
func (session *uiSession) populateProfiles(index int) {
if !session.wineEditable {
return
}
@@ -29,11 +29,11 @@ func (session *uiSession) populate_profiles(index int) {
C.prefs_profiles_select(C.int(index), C.int(len(session.profiles.Profiles)))
}
func (session *uiSession) profile_action(action int) {
func (session *uiSession) profileAction(action int) {
index := int(C.prefs_profiles_selected())
if action == 32 {
session.profiles = session.profiles.Remove(index)
session.populate_profiles(index)
session.populateProfiles(index)
return
}
if action == 33 {
@@ -45,15 +45,15 @@ func (session *uiSession) profile_action(action int) {
status(err.Error(), true)
return
}
settings := primary_settings(values)
next, err := config.Apply_primary_voice(settings, session.profiles.Profiles[index])
settings := primarySettings(values)
next, err := config.ApplyPrimaryVoice(settings, session.profiles.Profiles[index])
if err != nil {
status(err.Error(), true)
return
}
session.activeVoiceType = 0
session.setSpeechVoice(FromSettings(next))
preview := profile_preview_values(values, next)
preview := profilePreviewValues(values, next)
session.profilePreview = &preview
return
}
@@ -62,8 +62,8 @@ func (session *uiSession) profile_action(action int) {
status(err.Error(), true)
return
}
settings := primary_settings(values)
p := config.Primary_voice(settings)
settings := primarySettings(values)
p := config.PrimaryVoice(settings)
p.Name = ""
if p.Device == "" {
p.Device = "/dev/ttyUSB0"
@@ -79,13 +79,7 @@ func (session *uiSession) profile_action(action int) {
} 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.profileEditor = voiceprofiles.NewEditor(p, voiceprofiles.Drivers(), session.catalog)
session.profileBase = values
session.profileVoice = nil
session.profileIndex = index
@@ -96,12 +90,12 @@ func (session *uiSession) profile_action(action int) {
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)
setProfileControl(c)
}
C.prefs_profile_show()
}
func set_profile_control(c ui.Control) {
func setProfileControl(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))
@@ -116,15 +110,15 @@ func set_profile_control(c ui.Control) {
C.prefs_profile_set(id, C.int(c.Kind), text, C.double(c.Number), C.int(c.Selected), boolean(c.Hidden))
}
// set_profile_state updates a combo's selection and visibility in place.
func set_profile_state(c ui.Control) {
// setProfileState updates a combo's selection and visibility in place.
func setProfileState(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))
C.prefs_profile_set(id, C.int(c.Kind), text, C.double(c.Number), C.int(c.Selected), boolean(c.Hidden))
}
func same_choices(a, b []ui.Choice) bool {
func sameChoices(a, b []ui.Choice) bool {
if len(a) != len(b) {
return false
}
@@ -136,7 +130,7 @@ func same_choices(a, b []ui.Choice) bool {
return true
}
func (session *uiSession) profile_tick() bool {
func (session *uiSession) profileTick() bool {
if session.profileEditor == nil {
return false
}
@@ -161,10 +155,10 @@ func (session *uiSession) profile_tick() bool {
}
// Rebuilding the combo the user is changing moves GTK focus out of
// it. Like the main speech page, refill only lists that changed.
if old := values[voiceprofiles.PageID+"."+c.ID]; c.Kind != ui.ComboBox || !same_choices(old.Choices, c.Choices) {
set_profile_control(c)
if old := values[voiceprofiles.PageID+"."+c.ID]; c.Kind != ui.ComboBox || !sameChoices(old.Choices, c.Choices) {
setProfileControl(c)
} else if old.Selected != c.Selected || old.Hidden != c.Hidden {
set_profile_state(c)
setProfileState(c)
}
values[voiceprofiles.PageID+"."+c.ID] = c
for index, old := range session.profileControls {
@@ -174,7 +168,7 @@ func (session *uiSession) profile_tick() bool {
}
}
}
session.preview_profile(values)
session.previewProfile(values)
response := int(C.prefs_profile_response())
if response == 0 {
return true
@@ -200,27 +194,27 @@ func (session *uiSession) profile_tick() bool {
// Both Save and Cancel return to the unchanged parent speech draft.
preview := session.profileBase
session.profilePreview = &preview
session.populate_profiles(max(0, session.profileIndex))
session.populateProfiles(max(0, session.profileIndex))
return true
}
func (session *uiSession) preview_profile(values map[string]ui.Control) {
func (session *uiSession) previewProfile(values map[string]ui.Control) {
profile, err := session.profileEditor.Read(values)
if err != nil || session.profileVoice != nil && voiceprofiles.Same_voice(*session.profileVoice, profile) {
if err != nil || session.profileVoice != nil && voiceprofiles.SameVoice(*session.profileVoice, profile) {
return
}
next, err := config.Apply_primary_voice(primary_settings(session.profileBase), profile)
next, err := config.ApplyPrimaryVoice(primarySettings(session.profileBase), profile)
if err != nil {
return // Incomplete or unsupported edits retain the working voice.
}
preview := profile_preview_values(session.profileBase, next)
preview := profilePreviewValues(session.profileBase, next)
session.profileVoice = &profile
session.profilePreview = &preview
}
// Profile previews change only primary speech. The parent form and its other
// voice drafts remain intact and are restored when the child editor closes.
func profile_preview_values(base Values, settings config.Settings) Values {
func profilePreviewValues(base Values, settings config.Settings) Values {
voice := FromSettings(settings)
base.Rate, base.Pitch, base.Volume = voice.Rate, voice.Pitch, voice.Volume
base.SpeechServerFactory = voice.SpeechServerFactory
@@ -232,7 +226,7 @@ func profile_preview_values(base Values, settings config.Settings) Values {
return base
}
func primary_settings(values Values) config.Settings {
func primarySettings(values Values) config.Settings {
settings := config.DefaultSettings()
settings.SpeechServerFactory = values.SpeechServerFactory
settings.SpeechOutputModule = values.SpeechOutputModule