Rename interface.

This commit is contained in:
Anna Rose Wiggins 2025-07-18 19:08:47 -04:00
parent 3bfcdc830f
commit bad104a794
11 changed files with 27 additions and 27 deletions

View file

@ -7,7 +7,7 @@ import (
) )
type MappingRule interface { type MappingRule interface {
MatchEvent(RuleTargetDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent) MatchEvent(Device, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
} }
type TimedEventEmitter interface { type TimedEventEmitter interface {
@ -35,13 +35,13 @@ type RuleTarget interface {
// for most implementations. // for most implementations.
CreateEvent(int32, *string) *evdev.InputEvent CreateEvent(int32, *string) *evdev.InputEvent
MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool MatchEvent(device Device, event *evdev.InputEvent) bool
} }
// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing // Device is an interface abstraction on top of evdev.InputDevice, implementing
// only the methods we need in this package. This is used for testing, and the // only the methods we need in this package. This is used for testing, and the
// RuleTargetDevice can be safely cast to an *evdev.InputDevice when necessary. // Device can be safely cast to an *evdev.InputDevice when necessary.
type RuleTargetDevice interface { type Device interface {
AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error) AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error)
} }

View file

@ -17,7 +17,7 @@ func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *Rul
} }
} }
func (rule *MappingRuleAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { func (rule *MappingRuleAxis) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) || if !rule.MappingRuleBase.modeCheck(mode) ||
!rule.Input.MatchEvent(device, event) { !rule.Input.MatchEvent(device, event) {
return nil, nil return nil, nil

View file

@ -39,7 +39,7 @@ func NewMappingRuleAxisToButton(base MappingRuleBase, input *RuleTargetAxis, out
} }
} }
func (rule *MappingRuleAxisToButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { func (rule *MappingRuleAxisToButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) || if !rule.MappingRuleBase.modeCheck(mode) ||
!rule.Input.MatchEventDeviceAndCode(device, event) { !rule.Input.MatchEventDeviceAndCode(device, event) {
@ -105,5 +105,5 @@ func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent {
} }
func (rule *MappingRuleAxisToButton) GetOutputDevice() *evdev.InputDevice { func (rule *MappingRuleAxisToButton) GetOutputDevice() *evdev.InputDevice {
return rule.Output.Device return rule.Output.Device.(*evdev.InputDevice)
} }

View file

@ -43,7 +43,7 @@ func NewMappingRuleAxisToRelaxis(
} }
func (rule *MappingRuleAxisToRelaxis) MatchEvent( func (rule *MappingRuleAxisToRelaxis) MatchEvent(
device RuleTargetDevice, device Device,
event *evdev.InputEvent, event *evdev.InputEvent,
mode *string) (*evdev.InputDevice, *evdev.InputEvent) { mode *string) (*evdev.InputDevice, *evdev.InputEvent) {

View file

@ -21,7 +21,7 @@ func NewMappingRuleButton(
} }
} }
func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { func (rule *MappingRuleButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil return nil, nil
} }
@ -31,5 +31,5 @@ func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.
return nil, nil return nil, nil
} }
return rule.Output.Device, rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode) return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
} }

View file

@ -23,7 +23,7 @@ func NewMappingRuleButtonCombo(
} }
} }
func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { func (rule *MappingRuleButtonCombo) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil return nil, nil
} }
@ -53,10 +53,10 @@ func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *e
targetState := len(rule.Inputs) targetState := len(rule.Inputs)
if oldState == targetState-1 && rule.State == targetState { if oldState == targetState-1 && rule.State == targetState {
return rule.Output.Device, rule.Output.CreateEvent(1, mode) return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(1, mode)
} }
if oldState == targetState && rule.State == targetState-1 { if oldState == targetState && rule.State == targetState-1 {
return rule.Output.Device, rule.Output.CreateEvent(0, mode) return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(0, mode)
} }
return nil, nil return nil, nil
} }

View file

@ -22,7 +22,7 @@ func NewMappingRuleButtonLatched(
} }
} }
func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { func (rule *MappingRuleButtonLatched) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil return nil, nil
} }
@ -42,5 +42,5 @@ func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event
value = 0 value = 0
} }
return rule.Output.Device, rule.Output.CreateEvent(value, mode) return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(value, mode)
} }

View file

@ -22,7 +22,7 @@ func NewMappingRuleModeSelect(
} }
func (rule *MappingRuleModeSelect) MatchEvent( func (rule *MappingRuleModeSelect) MatchEvent(
device RuleTargetDevice, device Device,
event *evdev.InputEvent, event *evdev.InputEvent,
mode *string) (*evdev.InputDevice, *evdev.InputEvent) { mode *string) (*evdev.InputDevice, *evdev.InputEvent) {

View file

@ -9,7 +9,7 @@ import (
type RuleTargetAxis struct { type RuleTargetAxis struct {
DeviceName string DeviceName string
Device RuleTargetDevice Device Device
Axis evdev.EvCode Axis evdev.EvCode
Inverted bool Inverted bool
DeadzoneStart int32 DeadzoneStart int32
@ -19,7 +19,7 @@ type RuleTargetAxis struct {
} }
func NewRuleTargetAxis(device_name string, func NewRuleTargetAxis(device_name string,
device RuleTargetDevice, device Device,
axis evdev.EvCode, axis evdev.EvCode,
inverted bool, inverted bool,
deadzoneStart int32, deadzoneStart int32,
@ -89,13 +89,13 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu
} }
} }
func (target *RuleTargetAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { func (target *RuleTargetAxis) MatchEvent(device Device, event *evdev.InputEvent) bool {
return target.MatchEventDeviceAndCode(device, event) && return target.MatchEventDeviceAndCode(device, event) &&
!target.InDeadZone(event.Value) !target.InDeadZone(event.Value)
} }
// TODO: Add tests // TODO: Add tests
func (target *RuleTargetAxis) MatchEventDeviceAndCode(device RuleTargetDevice, event *evdev.InputEvent) bool { func (target *RuleTargetAxis) MatchEventDeviceAndCode(device Device, event *evdev.InputEvent) bool {
return device == target.Device && return device == target.Device &&
event.Type == evdev.EV_ABS && event.Type == evdev.EV_ABS &&
event.Code == target.Axis event.Code == target.Axis

View file

@ -4,12 +4,12 @@ import "github.com/holoplot/go-evdev"
type RuleTargetButton struct { type RuleTargetButton struct {
DeviceName string DeviceName string
Device *evdev.InputDevice Device Device
Button evdev.EvCode Button evdev.EvCode
Inverted bool Inverted bool
} }
func NewRuleTargetButton(device_name string, device *evdev.InputDevice, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) { func NewRuleTargetButton(device_name string, device Device, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) {
return &RuleTargetButton{ return &RuleTargetButton{
DeviceName: device_name, DeviceName: device_name,
Device: device, Device: device,
@ -36,7 +36,7 @@ func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.Input
} }
} }
func (target *RuleTargetButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { func (target *RuleTargetButton) MatchEvent(device Device, event *evdev.InputEvent) bool {
return device == target.Device && return device == target.Device &&
event.Type == evdev.EV_KEY && event.Type == evdev.EV_KEY &&
event.Code == target.Button event.Code == target.Button

View file

@ -6,13 +6,13 @@ import (
type RuleTargetRelaxis struct { type RuleTargetRelaxis struct {
DeviceName string DeviceName string
Device RuleTargetDevice Device Device
Axis evdev.EvCode Axis evdev.EvCode
Inverted bool Inverted bool
} }
func NewRuleTargetRelaxis(device_name string, func NewRuleTargetRelaxis(device_name string,
device RuleTargetDevice, device Device,
axis evdev.EvCode, axis evdev.EvCode,
inverted bool) (*RuleTargetRelaxis, error) { inverted bool) (*RuleTargetRelaxis, error) {
@ -41,6 +41,6 @@ func (target *RuleTargetRelaxis) CreateEvent(value int32, mode *string) *evdev.I
} }
// Relative axis is only supported for output. // Relative axis is only supported for output.
func (target *RuleTargetRelaxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { func (target *RuleTargetRelaxis) MatchEvent(device Device, event *evdev.InputEvent) bool {
return false return false
} }