Refactor mapping rules.

This commit is contained in:
Anna Rose Wiggins 2025-07-06 15:46:48 -04:00
parent b9d02e6482
commit 08fc828b46
6 changed files with 176 additions and 165 deletions

View file

@ -0,0 +1,22 @@
package mappingrules
import "github.com/holoplot/go-evdev"
// A Simple Mapping Rule can map a button to a button or an axis to an axis.
type MappingRuleSimple struct {
MappingRuleBase
Input RuleTarget
}
func (rule *MappingRuleSimple) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
if !rule.MappingRuleBase.modeCheck(mode) {
return nil
}
if device != rule.Input.GetDevice() ||
event.Code != rule.Input.GetCode() {
return nil
}
return rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
}