From b80c5e30320435526de447635ad3e4d6d805ddfd Mon Sep 17 00:00:00 2001 From: Anna Rose Wiggins Date: Sat, 12 Sep 2026 16:29:51 +0200 Subject: [PATCH] Formatting and changelog updates. (#14) Reviewed-on: https://codeberg.org/annabunches/joyful/pulls/14 --- CHANGELOG | 1 + internal/configparser/schema.go | 8 +++++--- internal/virtualdevice/init.go | 25 +++++++++++++------------ internal/virtualdevice/variables.go | 9 +++++---- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 25ae3dc..b2dd634 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ ### Added - Add `hold` parameter for button-to-axis mappings. +- Add ability to set VendorId and ProductId on virtual devices. ### Fixed - Fixed possible crash when TTS is disabled. (thanks [Tsudico](https://codeberg.org/Tsudico)) \ No newline at end of file diff --git a/internal/configparser/schema.go b/internal/configparser/schema.go index 387022a..17a27a2 100644 --- a/internal/configparser/schema.go +++ b/internal/configparser/schema.go @@ -10,9 +10,11 @@ type Config struct { // TODO: configure custom unmarshaling so we can overload Buttons, Axes, and RelativeAxes... type DeviceConfigVirtual struct { - Name string - VendorId string `yaml:"vendor_id,omitempty"` - DeviceId string `yaml:"device_id,omitempty"` + Name string + // VendorId is the uint16 vendor id, for default see internal/virtualdevice/variables.go + VendorId string `yaml:"vendor_id,omitempty"` + // DeviceId is the uint16 device id, for default see internal/virtualdevice/variables.go + DeviceId string `yaml:"device_id,omitempty"` Preset string NumButtons int `yaml:"num_buttons,omitempty"` NumAxes int `yaml:"num_axes,omitempty"` diff --git a/internal/virtualdevice/init.go b/internal/virtualdevice/init.go index 3a3242d..fa1a600 100644 --- a/internal/virtualdevice/init.go +++ b/internal/virtualdevice/init.go @@ -3,22 +3,23 @@ package virtualdevice import ( "fmt" + "strconv" + "git.annabunches.net/annabunches/joyful/internal/configparser" "git.annabunches.net/annabunches/joyful/internal/eventcodes" "git.annabunches.net/annabunches/joyful/internal/logger" "github.com/holoplot/go-evdev" - "strconv" ) func ParseUInt16(s string, def uint16) uint16 { - if s == "" { - return def - } - v, err := strconv.ParseUint(s, 0, 16) - if err != nil { - return def - } - return uint16(v) + if s == "" { + return def + } + v, err := strconv.ParseUint(s, 0, 16) + if err != nil { + return def + } + return uint16(v) } // NewEventBuffer takes a virtual device config specification, creates the underlying @@ -50,11 +51,11 @@ func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, erro device, err := evdev.CreateDevice( name, - // TODO: placeholders. BusType = differentiate between input bus (3 = usb), Vendor = uint16 vendor id, Product: uint16 devoce id, Version = device version (differentiate between differing versions of exact same device) evdev.InputID{ + // 3 specifies USB bus type BusType: 0x03, - Vendor: ParseUInt16(config.VendorId, VirtualDeviceVendorId), - Product: ParseUInt16(config.DeviceId, VirtualDeviceDeviceId), + Vendor: ParseUInt16(config.VendorId, VirtualDeviceDefaultVendorId), + Product: ParseUInt16(config.DeviceId, VirtualDeviceDefaultDeviceId), Version: 1, }, capabilities, diff --git a/internal/virtualdevice/variables.go b/internal/virtualdevice/variables.go index 5810adc..829b605 100644 --- a/internal/virtualdevice/variables.go +++ b/internal/virtualdevice/variables.go @@ -7,10 +7,11 @@ const ( DevicePresetGamepad = "gamepad" DevicePresetJoystick = "joystick" DevicePresetMouse = "mouse" - - VirtualDeviceVendorId = 0x4711 - VirtualDeviceDeviceId = 0x0816 - VirtualDeviceMaxButtons = 74 + + // These defaults are taken or inferred from the go-evdev library + VirtualDeviceDefaultVendorId = 0x4711 + VirtualDeviceDefaultDeviceId = 0x0816 + VirtualDeviceMaxButtons = 74 ) // Device Presets