Add support for setting vendor/device IDs (#10)

Sets vendor and product IDs, defaults to the prior default values.
This is needed for some games to be able to correctly identify the virtual devices since not all games support device indexes.

Reviewed-on: https://codeberg.org/annabunches/joyful/pulls/10
This commit is contained in:
eviLu 2026-09-12 16:22:43 +02:00 committed by annabunches
parent 77ee020b2a
commit 7e4d4f3c20
3 changed files with 20 additions and 4 deletions

View file

@ -7,8 +7,20 @@ import (
"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)
}
// NewEventBuffer takes a virtual device config specification, creates the underlying
// evdev.InputDevice, and wraps it in a buffered event emitter.
func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, error) {
@ -38,11 +50,11 @@ func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, erro
device, err := evdev.CreateDevice(
name,
// TODO: placeholders. Who knows what these should actually be...
// 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{
BusType: 0x03,
Vendor: 0x4711,
Product: 0x0816,
Vendor: ParseUInt16(config.VendorId, VirtualDeviceVendorId),
Product: ParseUInt16(config.DeviceId, VirtualDeviceDeviceId),
Version: 1,
},
capabilities,

View file

@ -7,7 +7,9 @@ const (
DevicePresetGamepad = "gamepad"
DevicePresetJoystick = "joystick"
DevicePresetMouse = "mouse"
VirtualDeviceVendorId = 0x4711
VirtualDeviceDeviceId = 0x0816
VirtualDeviceMaxButtons = 74
)