Files

43 lines
1.0 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package input
import (
"slices"
"git.stormux.org/storm/fenrir/internal/command"
)
// LearnKey describes a captured fresh press. Command is metadata only: it is
// never placed in Decision.Command and cannot launch an action or script.
type LearnKey struct {
Code uint16
Held []uint16
Command command.ID
Bare bool
}
func (r *Router) learn_key(device int, key uint16, numLock bool) *LearnKey {
pressed := &LearnKey{Code: key, Bare: r.empty()}
seen := map[uint16]bool{}
for _, held := range r.keys {
for code := range held {
seen[code] = true
}
}
for code := range seen {
pressed.Held = append(pressed.Held, code)
}
slices.Sort(pressed.Held)
id, scriptChord := r.script_binding(key, numLock)
if !scriptChord {
id = r.binding(key, numLock)
}
if !pure_modifier(key) && !r.reader_modifier(key, numLock) {
id = r.multi_press(device, r.binding_chord(key, numLock), id, scriptChord)
}
pressed.Command = id
return pressed
}