Big Refactor (#2)

Refactor Everything.

Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com>
Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
Anna Rose Wiggins 2025-07-08 03:26:24 +00:00 committed by Anna Rose
parent a0949e719f
commit ff38db6596
21 changed files with 413 additions and 309 deletions

View file

@ -0,0 +1,46 @@
package mappingrules
import "github.com/holoplot/go-evdev"
type MappingRuleButtonLatched struct {
MappingRuleBase
Input *RuleTargetButton
Output *RuleTargetButton
State bool
}
func NewMappingRuleButtonLatched(
base MappingRuleBase,
input *RuleTargetButton,
output *RuleTargetButton) *MappingRuleButtonLatched {
return &MappingRuleButtonLatched{
MappingRuleBase: base,
Input: input,
Output: output,
State: false,
}
}
func (rule *MappingRuleButtonLatched) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil
}
if device != rule.Input.Device ||
event.Code != rule.Input.Button ||
rule.Input.NormalizeValue(event.Value) == 0 {
return nil, nil
}
// Input is pressed, so toggle state and emit event
var value int32
rule.State = !rule.State
if rule.State {
value = 1
} else {
value = 0
}
return rule.Output.Device, rule.Output.CreateEvent(value, mode)
}