Refactor Everything. Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
43 lines
979 B
Go
43 lines
979 B
Go
package mappingrules
|
|
|
|
import "github.com/holoplot/go-evdev"
|
|
|
|
type RuleTargetButton struct {
|
|
DeviceName string
|
|
Device *evdev.InputDevice
|
|
Button evdev.EvCode
|
|
Inverted bool
|
|
}
|
|
|
|
func NewRuleTargetButton(device_name string, device *evdev.InputDevice, code evdev.EvCode, inverted bool) *RuleTargetButton {
|
|
return &RuleTargetButton{
|
|
DeviceName: device_name,
|
|
Device: device,
|
|
Button: code,
|
|
Inverted: inverted,
|
|
}
|
|
}
|
|
|
|
func (target *RuleTargetButton) NormalizeValue(value int32) int32 {
|
|
if target.Inverted {
|
|
if value == 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
return value
|
|
}
|
|
|
|
func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.InputEvent {
|
|
return &evdev.InputEvent{
|
|
Type: evdev.EV_KEY,
|
|
Code: target.Button,
|
|
Value: value,
|
|
}
|
|
}
|
|
|
|
func (target *RuleTargetButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) bool {
|
|
return device == target.Device &&
|
|
event.Type == evdev.EV_KEY &&
|
|
event.Code == target.Button
|
|
}
|