(WIP) Implement axis-to-relaxis repeats; similar to buttons but for discretized relative axis inputs. (i.e. mousewheel)

This commit is contained in:
Anna Rose Wiggins 2025-07-15 00:46:07 -04:00
parent 8bbb84da85
commit 0915ea059a
10 changed files with 224 additions and 18 deletions

View file

@ -19,10 +19,6 @@ type MappingRuleAxisToButton struct {
pressed bool
}
const (
NoNextEvent = time.Duration(-1)
)
func NewMappingRuleAxisToButton(base MappingRuleBase, input *RuleTargetAxis, output *RuleTargetButton, repeatRateMin, repeatRateMax int) *MappingRuleAxisToButton {
return &MappingRuleAxisToButton{
MappingRuleBase: base,
@ -50,6 +46,7 @@ func (rule *MappingRuleAxisToButton) MatchEvent(device RuleTargetDevice, event *
}
// If we aren't repeating, we trigger the event immediately
// TODO: we aren't using pressed correctly; that should be set *and released* in here...
if rule.RepeatRateMin == 0 || rule.RepeatRateMax == 0 {
rule.nextEvent = time.Millisecond
return nil, nil
@ -73,7 +70,7 @@ func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent {
}
// This indicates that we should not emit another event
if rule.nextEvent == -1 {
if rule.nextEvent == NoNextEvent {
rule.lastEvent = time.Now()
return nil
}
@ -86,3 +83,7 @@ func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent {
return nil
}
func (rule *MappingRuleAxisToButton) GetOutputDevice() *evdev.InputDevice {
return rule.Output.Device
}