Move rule target builders into the correct locations.

This commit is contained in:
Anna Rose Wiggins 2025-08-11 20:53:01 -04:00
parent 9e4062ba30
commit 33b62496a3
17 changed files with 198 additions and 194 deletions

View file

@ -1,6 +1,12 @@
package mappingrules
import "github.com/holoplot/go-evdev"
import (
"fmt"
"git.annabunches.net/annabunches/joyful/internal/configparser"
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
"github.com/holoplot/go-evdev"
)
type RuleTargetButton struct {
DeviceName string
@ -9,6 +15,25 @@ type RuleTargetButton struct {
Inverted bool
}
func NewRuleTargetButtonFromConfig(targetConfig configparser.RuleTargetConfigButton, devs map[string]Device) (*RuleTargetButton, error) {
device, ok := devs[targetConfig.Device]
if !ok {
return nil, fmt.Errorf("non-existent device '%s'", targetConfig.Device)
}
eventCode, err := eventcodes.ParseCodeButton(targetConfig.Button)
if err != nil {
return nil, err
}
return NewRuleTargetButton(
targetConfig.Device,
device,
eventCode,
targetConfig.Inverted,
)
}
func NewRuleTargetButton(device_name string, device Device, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) {
return &RuleTargetButton{
DeviceName: device_name,