Default laptop key set to capslock. Keys that can be set to fenrir key or script key selectable via checkbox.
This commit is contained in:
1 parent
47f18fdd28
commit
15e04aa8f8
47 files changed
+1560
-351
No files matched your search
+40
-10
@@ -26,6 +26,12 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
type Layout struct {
|
||||
Version int `toml:"version"`
|
||||
FenrirKeys []string `toml:"fenrir_keys"`
|
||||
Bindings []Binding `toml:"bindings"`
|
||||
}
|
||||
|
||||
type Binding struct {
|
||||
Name string `toml:"name"`
|
||||
Keys []string `toml:"keys"`
|
||||
@@ -71,24 +77,48 @@ type chord struct {
|
||||
var modifierNames = map[string]modifiers{"FENRIR": fenrirModifier, "CTRL": ctrlModifier, "SHIFT": shiftModifier, "ALT": altModifier}
|
||||
|
||||
// Decode_bindings rejects unsupported keys, commands and duplicate chords.
|
||||
func Decode_bindings(data []byte) ([]Binding, error) {
|
||||
var file struct {
|
||||
Version int `toml:"version"`
|
||||
Bindings []Binding `toml:"bindings"`
|
||||
}
|
||||
func Decode_bindings(data []byte) (Layout, error) {
|
||||
var file Layout
|
||||
if err := toml.NewDecoder(bytes.NewReader(data)).DisallowUnknownFields().Decode(&file); err != nil {
|
||||
return nil, err
|
||||
return Layout{}, err
|
||||
}
|
||||
if file.Version != 1 {
|
||||
return nil, fmt.Errorf("unsupported keyboard version %d", file.Version)
|
||||
return Layout{}, fmt.Errorf("unsupported keyboard version %d", file.Version)
|
||||
}
|
||||
_, err := New_router(file.Bindings)
|
||||
return file.Bindings, err
|
||||
_, err := New_router(file)
|
||||
return file, err
|
||||
}
|
||||
|
||||
// New_router compiles a private layout. Reset and capture preserve these bindings.
|
||||
func New_router(bindings []Binding) (Router, error) {
|
||||
func New_router(layout Layout) (Router, error) {
|
||||
bindings := layout.Bindings
|
||||
router := Router{bindings: make(map[chord]command.ID), doubleBindings: make(map[chord]command.ID), tripleBindings: make(map[chord]command.ID), multiPressTimeout: DefaultMultiPressTimeout}
|
||||
keys := layout.FenrirKeys
|
||||
if len(keys) == 0 {
|
||||
keys = []string{"INSERT", "SUPER", "KP0"}
|
||||
}
|
||||
router.readerKeys = make(map[uint16]bool)
|
||||
for _, name := range keys {
|
||||
var codes []uint16
|
||||
switch name {
|
||||
case "INSERT":
|
||||
codes = []uint16{KeyInsert}
|
||||
case "SUPER":
|
||||
codes = []uint16{KeyMeta, KeyRightMeta}
|
||||
case "CAPSLOCK":
|
||||
codes = []uint16{KeyCapsLock}
|
||||
case "KP0":
|
||||
codes = []uint16{KeyKP0}
|
||||
default:
|
||||
return Router{}, fmt.Errorf("unsupported Fenrir modifier %q", name)
|
||||
}
|
||||
for _, code := range codes {
|
||||
if router.readerKeys[code] {
|
||||
return Router{}, fmt.Errorf("duplicate Fenrir modifier %q", name)
|
||||
}
|
||||
router.readerKeys[code] = true
|
||||
}
|
||||
}
|
||||
if len(bindings) == 0 {
|
||||
return Router{}, fmt.Errorf("keyboard layout has no bindings")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user