Support specifying physical devices via device file instead of device name.

This commit is contained in:
Anna Rose Wiggins 2025-08-05 15:51:59 -04:00
parent 890c19f1dc
commit 22e2046441
5 changed files with 64 additions and 10 deletions

View file

@ -88,21 +88,32 @@ func (parser *ConfigParser) ConnectPhysicalDevices() map[string]*evdev.InputDevi
continue
}
device, err := evdev.OpenByName(deviceConfig.DeviceName)
var infoName string
var device *evdev.InputDevice
var err error
if deviceConfig.DevicePath != "" {
infoName = deviceConfig.DevicePath
device, err = evdev.Open(deviceConfig.DevicePath)
} else {
infoName = deviceConfig.DeviceName
device, err = evdev.OpenByName(deviceConfig.DeviceName)
}
if err != nil {
logger.LogError(err, "Failed to open physical device, skipping. Confirm the device name with 'evlist'. Watch out for spaces.")
logger.LogError(err, "Failed to open physical device, skipping. Confirm the device name or path with 'evinfo'")
continue
}
if deviceConfig.Lock {
logger.LogDebugf("Locking device '%s'", deviceConfig.DeviceName)
logger.LogDebugf("Locking device '%s'", infoName)
err := device.Grab()
if err != nil {
logger.LogError(err, "Failed to grab device for exclusive access")
}
}
logger.Log(fmt.Sprintf("Connected to '%s' as '%s'", deviceConfig.DeviceName, deviceConfig.Name))
logger.Log(fmt.Sprintf("Connected to '%s' as '%s'", infoName, deviceConfig.Name))
deviceMap[deviceConfig.Name] = device
}

View file

@ -19,7 +19,7 @@ type DeviceConfig struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
DeviceName string `yaml:"device_name,omitempty"`
Uuid string `yaml:"uuid,omitempty"`
DevicePath string `yaml:"device_path,omitempty"`
Preset string `yaml:"preset,omitempty"`
NumButtons int `yaml:"num_buttons,omitempty"`
NumAxes int `yaml:"num_axes,omitempty"`
@ -64,7 +64,7 @@ func (dc *DeviceConfig) UnmarshalYAML(unmarshal func(data interface{}) error) er
Name string
Type string
DeviceName string `yaml:"device_name"`
Uuid string
DevicePath string `yaml:"device_path"`
Preset string
NumButtons int `yaml:"num_buttons"`
NumAxes int `yaml:"num_axes"`
@ -85,7 +85,7 @@ func (dc *DeviceConfig) UnmarshalYAML(unmarshal func(data interface{}) error) er
Name: raw.Name,
Type: raw.Type,
DeviceName: raw.DeviceName,
Uuid: raw.Uuid,
DevicePath: raw.DevicePath,
Preset: raw.Preset,
NumButtons: raw.NumButtons,
NumAxes: raw.NumAxes,