(WIP) Move rule initialization into rule package.

This commit is contained in:
Anna Rose Wiggins 2025-08-11 19:09:37 -04:00
parent 727985f91c
commit 9e4062ba30
21 changed files with 366 additions and 489 deletions

View file

@ -1,6 +1,9 @@
package mappingrules
import "github.com/holoplot/go-evdev"
import (
"git.annabunches.net/annabunches/joyful/internal/configparser"
"github.com/holoplot/go-evdev"
)
// A Simple Mapping Rule can map a button to a button or an axis to an axis.
type MappingRuleButton struct {
@ -9,16 +12,26 @@ type MappingRuleButton struct {
Output *RuleTargetButton
}
func NewMappingRuleButton(
base MappingRuleBase,
input *RuleTargetButton,
output *RuleTargetButton) *MappingRuleButton {
func NewMappingRuleButton(ruleConfig configparser.RuleConfigButton,
pDevs map[string]Device,
vDevs map[string]Device,
base MappingRuleBase) (*MappingRuleButton, error) {
input, err := makeRuleTargetButton(ruleConfig.Input, pDevs)
if err != nil {
return nil, err
}
output, err := makeRuleTargetButton(ruleConfig.Output, vDevs)
if err != nil {
return nil, err
}
return &MappingRuleButton{
MappingRuleBase: base,
Input: input,
Output: output,
}
}, nil
}
func (rule *MappingRuleButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {