Skip to content

Commit f4be415

Browse files
committed
Review cleanup
Cleanup of scancodes Moved the scancode related logic/tables into single-source (per UI/backend) Renamed hidHash to hidHashTilde Used hid constants everywhere instead of binary values. Added logic to hide the shift-only legend when the unshifted is the same for layer=all Always center shift.nds/normal.nds Clean up CSS to be less fragile.
1 parent cd02d0e commit f4be415

25 files changed

Lines changed: 285 additions & 245 deletions

internal/keyboard/keyboard.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ func sanitizeName(name string) string {
593593
}
594594

595595
func approxEq(a, b float64) bool {
596-
return math.Abs(a-b) < 0.1
596+
return math.Abs(a-b) < 0.25
597597
}
598598

599599
func detectShape(x, w, h, w2, h2 float64, stepped, hasW2 bool) KeyShape {
@@ -674,7 +674,7 @@ func buildCharMap(keys []TransportKey) map[string]HIDCombo {
674674

675675
// Sort a copy by position for deterministic first-occurrence behaviour.
676676
// We must not mutate the original slice — it preserves KLE parse order,
677-
// which the scancodes metadata override uses (0-based index).
677+
// which the scancodes metadata override uses.
678678
sorted := make([]TransportKey, len(keys))
679679
copy(sorted, keys)
680680
slices.SortStableFunc(sorted, func(a, b TransportKey) int {
@@ -683,9 +683,8 @@ func buildCharMap(keys []TransportKey) map[string]HIDCombo {
683683
}
684684
return cmp.Compare(a.X, b.X)
685685
})
686-
keys = sorted
687686

688-
for _, key := range keys {
687+
for _, key := range sorted {
689688
if key.Scancode == 0 {
690689
continue // non-typeable keys and decals don't send HID events
691690
}
@@ -703,7 +702,7 @@ func addChar(m map[string]HIDCombo, legend *string, scancode, mods uint8) {
703702
if legend == nil || *legend == "" {
704703
return
705704
}
706-
if !scancodeProducesText(scancode) {
705+
if !ScancodeProducesText(scancode) {
707706
return
708707
}
709708
if utf8.RuneCountInString(*legend) != 1 {
@@ -720,31 +719,6 @@ func addChar(m map[string]HIDCombo, legend *string, scancode, mods uint8) {
720719
}
721720
}
722721

723-
func scancodeProducesText(scancode uint8) bool {
724-
// Alphabet keys
725-
if scancode >= hidA && scancode <= hidZ {
726-
return true
727-
}
728-
// Number row keys
729-
if scancode >= hidN1 && scancode <= hidN0 {
730-
return true
731-
}
732-
// Space and printable punctuation keys. Excludes Enter/Escape/Backspace/Tab.
733-
if scancode == hidSpace ||
734-
(scancode >= hidMinus && scancode <= hidSlash) ||
735-
scancode == hidHash ||
736-
scancode == hidISOKey {
737-
return true
738-
}
739-
// Numpad printable characters. Excludes NumLock and KPEnter.
740-
if (scancode >= hidKPSlash && scancode <= hidKPPlus) ||
741-
(scancode >= hidKP1 && scancode <= hidKPDot) {
742-
return true
743-
}
744-
745-
return false
746-
}
747-
748722
var controlLegendDisplayMap = map[string]string{
749723
"␛": "Esc",
750724
"␍": "⏎",
@@ -776,7 +750,7 @@ func normalizeControlLegendsForDisplay(keys []TransportKey) {
776750
if k.Scancode == 0 {
777751
continue
778752
}
779-
if scancodeProducesText(k.Scancode) && k.Scancode != hidSpace {
753+
if ScancodeProducesText(k.Scancode) && k.Scancode != hidSpace {
780754
continue
781755
}
782756
normalize(&k.Legends.Normal)

internal/keyboard/layouts/cs_CZ.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
{
129129
"h": 2
130130
},
131-
"+\n+"
131+
"\n+"
132132
],
133133
[
134134
{

internal/keyboard/layouts/da_DK.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
{
124124
"h": 2
125125
},
126-
"+\n+"
126+
"\n+"
127127
],
128128
[
129129
{

internal/keyboard/layouts/de_CH.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
{
124124
"h": 2
125125
},
126-
"+\n+"
126+
"\n+"
127127
],
128128
[
129129
{

internal/keyboard/layouts/de_DE.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
{
122122
"h": 2
123123
},
124-
"+\n+"
124+
"\n+"
125125
],
126126
[
127127
{

internal/keyboard/layouts/en_UK.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
{
117117
"h": 2
118118
},
119-
"+\n+"
119+
"\n+"
120120
],
121121
[
122122
{

internal/keyboard/layouts/en_US.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
{
112112
"h": 2
113113
},
114-
"+\n+"
114+
"\n+"
115115
],
116116
[
117117
{

internal/keyboard/layouts/es_ES.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
{
123123
"h": 2
124124
},
125-
"+\n+"
125+
"\n+"
126126
],
127127
[
128128
{

internal/keyboard/layouts/fr_BE.kle.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"name": "Belgisch Nederlands fr-BE/nl-BE (ISO 105)",
3+
"name": "Belgisch Nederlands fr-BE (ISO 105)",
44
"author": "JetKVM",
55
"deadKeys": [
66
"^",
@@ -45,7 +45,7 @@
4545
"d": true,
4646
"w": 4
4747
},
48-
"Belgisch Nederlands fr-BE/nl-BE (ISO 105)\nfr-BE\n\n(ISO 105)"
48+
"Belgisch Nederlands fr-BE (ISO 105)\nfr-BE\nnl-BE\n(ISO 105)"
4949
],
5050
[
5151
{
@@ -123,7 +123,7 @@
123123
{
124124
"h": 2
125125
},
126-
"+\n+"
126+
"\n+"
127127
],
128128
[
129129
{

internal/keyboard/layouts/fr_CH.kle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
{
124124
"h": 2
125125
},
126-
"+\n+"
126+
"\n+"
127127
],
128128
[
129129
{

0 commit comments

Comments
 (0)