Refactor mapping rules.
This commit is contained in:
parent
b9d02e6482
commit
08fc828b46
6 changed files with 176 additions and 165 deletions
22
internal/mappingrules/mapping_rule_simple.go
Normal file
22
internal/mappingrules/mapping_rule_simple.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue