Cthulhu is no longer a fork. Now it is a screen reader written in Golang.
This commit is contained in:
1 parent
a998fe67de
commit
069fc674dc
708 files changed
+112482
-532
No files matched your search
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package preferences
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
#include "native.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"unsafe"
|
||||
|
||||
"git.stormux.org/storm/cthulhu/internal/braille"
|
||||
)
|
||||
|
||||
func setBrailleChoice(brief, verbose string, value int) {
|
||||
setCheck(brief, value == 0)
|
||||
setCheck(verbose, value != 0)
|
||||
}
|
||||
|
||||
func setBrailleIndicator(prefix string, value int) {
|
||||
suffix := map[int]string{0: "NoneButton", 0x40: "7Button", 0x80: "8Button", 0xc0: "BothButton"}[value]
|
||||
setCheck(prefix+suffix, true)
|
||||
}
|
||||
|
||||
func getBrailleIndicator(prefix string) int {
|
||||
for _, option := range []struct {
|
||||
suffix string
|
||||
dots int
|
||||
}{
|
||||
{"7Button", 0x40}, {"8Button", 0x80}, {"BothButton", 0xc0},
|
||||
} {
|
||||
if getCheck(prefix + option.suffix) {
|
||||
return option.dots
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (session *uiSession) set_braille_values(values Values) {
|
||||
setCheck("enableBrailleCheckButton", values.EnableBraille)
|
||||
setCheck("contractedBrailleCheckButton", values.EnableContractedBraille)
|
||||
setCheck("abbrevRolenames", values.Braille.AbbreviateRoles)
|
||||
setCheck("disableBrailleEOLCheckButton", values.Braille.DisableEOL)
|
||||
setCheck("enableBrailleWordWrapCheckButton", values.Braille.WordWrap)
|
||||
setCheck("enableFlashMessagesCheckButton", values.Braille.FlashMessages)
|
||||
setCheck("flashIsPersistentCheckButton", values.Braille.FlashPersistent)
|
||||
setCheck("flashIsDetailedCheckButton", values.Braille.FlashDetailed)
|
||||
setSpin("brailleFlashTimeSpinButton", float64(values.Braille.FlashTime)/1000)
|
||||
setBrailleChoice("brailleBriefButton", "brailleVerboseButton", values.Braille.Verbosity)
|
||||
setBrailleIndicator("brailleSelection", values.Braille.SelectionIndicator)
|
||||
setBrailleIndicator("brailleLink", values.Braille.LinkIndicator)
|
||||
session.contractionTables = braille.AvailableTables()
|
||||
comboID := C.CString("contractionTableCombo")
|
||||
C.prefs_combo_clear(comboID)
|
||||
defaultLabel := C.CString("Automatic for current language")
|
||||
C.prefs_combo_append(comboID, defaultLabel)
|
||||
C.free(unsafe.Pointer(defaultLabel))
|
||||
selected := 0
|
||||
for index, table := range session.contractionTables {
|
||||
label := C.CString(table.Label)
|
||||
C.prefs_combo_append(comboID, label)
|
||||
C.free(unsafe.Pointer(label))
|
||||
if table.File == values.BrailleContractionTable || filepath.Base(table.File) == values.BrailleContractionTable {
|
||||
selected = index + 1
|
||||
}
|
||||
}
|
||||
if values.BrailleContractionTable != "" && selected == 0 {
|
||||
// Keep a saved table available even after a locale change or package update.
|
||||
session.contractionTables = append(session.contractionTables, braille.TableOption{
|
||||
Label: "Saved: " + filepath.Base(values.BrailleContractionTable),
|
||||
File: values.BrailleContractionTable,
|
||||
})
|
||||
label := C.CString(session.contractionTables[len(session.contractionTables)-1].Label)
|
||||
C.prefs_combo_append(comboID, label)
|
||||
C.free(unsafe.Pointer(label))
|
||||
selected = len(session.contractionTables)
|
||||
}
|
||||
C.prefs_combo_set(comboID, C.int(selected))
|
||||
C.free(unsafe.Pointer(comboID))
|
||||
}
|
||||
|
||||
func (session *uiSession) get_braille_values(values *Values) error {
|
||||
values.EnableBraille = getCheck("enableBrailleCheckButton")
|
||||
values.EnableContractedBraille = getCheck("contractedBrailleCheckButton")
|
||||
values.Braille.AbbreviateRoles = getCheck("abbrevRolenames")
|
||||
values.Braille.DisableEOL = getCheck("disableBrailleEOLCheckButton")
|
||||
values.Braille.WordWrap = getCheck("enableBrailleWordWrapCheckButton")
|
||||
values.Braille.FlashMessages = getCheck("enableFlashMessagesCheckButton")
|
||||
values.Braille.FlashPersistent = getCheck("flashIsPersistentCheckButton")
|
||||
values.Braille.FlashDetailed = getCheck("flashIsDetailedCheckButton")
|
||||
values.Braille.FlashTime = int(getSpin("brailleFlashTimeSpinButton") * 1000)
|
||||
if getCheck("brailleVerboseButton") {
|
||||
values.Braille.Verbosity = 1
|
||||
}
|
||||
values.Braille.SelectionIndicator = getBrailleIndicator("brailleSelection")
|
||||
values.Braille.LinkIndicator = getBrailleIndicator("brailleLink")
|
||||
selectedTable := getCombo("contractionTableCombo")
|
||||
if selectedTable < 0 || selectedTable > len(session.contractionTables) {
|
||||
return errors.New("Choose a contraction table.")
|
||||
}
|
||||
if selectedTable > 0 {
|
||||
values.BrailleContractionTable = session.contractionTables[selectedTable-1].File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user