From 9a01087c73019d945118aae0212509918455dd93 Mon Sep 17 00:00:00 2001 From: Anna Rose Wiggins Date: Wed, 16 Jul 2025 15:14:07 -0400 Subject: [PATCH] Fix max buttons --- docs/readme.md | 2 +- internal/config/devices.go | 6 +++--- internal/config/make_rule_targets.go | 4 ++-- internal/config/variables.go | 8 +++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 958bf64..799f6b5 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -42,7 +42,7 @@ Ways to specify keycodes are: * Using evdev's Keycodes. This is the best way to be absolutely certain about which axis you're referencing. You can specify these keycodes in two forms: * Using the code's identifier from . e.g., `ABS_X`, `REL_WHEEL`, `BTN_TRIGGER`. * Alternately, you can omit the `ABS_` type prefix, and Joyful will automatically add it from context. So for a button input, you can simply specify `button: trigger` instead of `BTN_TRIGGER`. -* You can use the hexadecimal value of the keycode directly, via `0x`. This can be useful if you want to force a specific numeric value that isn't represented by a Linux keycode directly. Note however that not all keycodes will work. Only the first 8 axes are available, and see for a list of valid button outputs. +* You can use the hexadecimal value of the keycode directly, via `"0x"`. This can be useful if you want to force a specific numeric value that isn't represented by a Linux keycode directly. Note however that not all keycodes will work. Only the first 8 axes are available, and see for a list of valid button outputs. This is most useful with input configurations. **Note: You must use quotation marks around the hex value to prevent the yaml parser from automatically converting it to decimal.** * For buttons, you can specify the button number, as in `button: 3`. There are 74 buttons available, and the first button is button number `0`. As a result, valid values are 0-73. Note that buttons 12-14 and buttons 55-73 may not work in all Linux-native games. For input, you can figure out what keycodes your device is emitting by running the Linux utility `evtest`. `evtest` works well with `grep`, so if you just want to see button inputs, you can do: diff --git a/internal/config/devices.go b/internal/config/devices.go index d904779..2fb0e50 100644 --- a/internal/config/devices.go +++ b/internal/config/devices.go @@ -82,9 +82,9 @@ func (parser *ConfigParser) ConnectPhysicalDevices() map[string]*evdev.InputDevi } func makeButtons(numButtons int) []evdev.EvCode { - if numButtons > 56 { - numButtons = 56 - logger.Log("Limiting virtual device buttons to 56") + if numButtons > VirtualDeviceMaxButtons { + numButtons = VirtualDeviceMaxButtons + logger.Logf("Limiting virtual device buttons to %d", VirtualDeviceMaxButtons) } buttons := make([]evdev.EvCode, numButtons) diff --git a/internal/config/make_rule_targets.go b/internal/config/make_rule_targets.go index f752fef..d46c83c 100644 --- a/internal/config/make_rule_targets.go +++ b/internal/config/make_rule_targets.go @@ -26,7 +26,7 @@ func makeRuleTargetButton(targetConfig RuleTargetConfig, devs map[string]*evdev. } case strings.HasPrefix(buttonConfig, "0X"): - codeInt, err := strconv.ParseUint(buttonConfig[2:], 16, 32) + codeInt, err := strconv.ParseUint(buttonConfig[2:], 16, 0) if err != nil { return nil, err } @@ -147,6 +147,6 @@ func makeRuleTargetModeSelect(targetConfig RuleTargetConfig, allModes []string) } // hasError exists solely to switch on errors in case statements -func hasError(_ interface{}, err error) bool { +func hasError(_ any, err error) bool { return err != nil } diff --git a/internal/config/variables.go b/internal/config/variables.go index 97390d6..f954372 100644 --- a/internal/config/variables.go +++ b/internal/config/variables.go @@ -15,6 +15,8 @@ const ( RuleTypeModeSelect = "mode-select" RuleTypeAxisToButton = "axis-to-button" RuleTypeAxisToRelaxis = "axis-to-relaxis" + + VirtualDeviceMaxButtons = 74 ) var ( @@ -31,9 +33,9 @@ var ( evdev.BTN_BASE4, evdev.BTN_BASE5, evdev.BTN_BASE6, - evdev.EvCode(0x12c), - evdev.EvCode(0x12d), - evdev.EvCode(0x12e), + evdev.EvCode(0x12c), // decimal 300 + evdev.EvCode(0x12d), // decimal 301 + evdev.EvCode(0x12e), // decimal 302 evdev.BTN_DEAD, evdev.BTN_TRIGGER_HAPPY1, evdev.BTN_TRIGGER_HAPPY2,