From e00a11cbbed21ae9725c8d0a6ccc539b792d3e82 Mon Sep 17 00:00:00 2001 From: Mara van der Laan <126646+laanwj@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:02:28 +0100 Subject: [PATCH] Add with_leds and with_sounds to uinput VirtualDeviceBuilder Complete the set of settable capabilities. --- src/uinput.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/uinput.rs b/src/uinput.rs index d79e3c7..93ecd1e 100644 --- a/src/uinput.rs +++ b/src/uinput.rs @@ -6,8 +6,9 @@ use crate::compat::{input_event, input_id, uinput_abs_setup, uinput_setup, UINPU use crate::ff::FFEffectData; use crate::inputid::{BusType, InputId}; use crate::{ - sys, AttributeSetRef, FFEffectCode, InputEvent, KeyCode, MiscCode, PropType, RelativeAxisCode, - SwitchCode, SynchronizationEvent, UInputCode, UInputEvent, UinputAbsSetup, + sys, AttributeSetRef, FFEffectCode, InputEvent, KeyCode, LedCode, MiscCode, PropType, + RelativeAxisCode, SoundCode, SwitchCode, SynchronizationEvent, UInputCode, UInputEvent, + UinputAbsSetup, }; use std::ffi::{CStr, OsStr}; use std::os::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; @@ -214,6 +215,48 @@ impl<'a> VirtualDeviceBuilder<'a> { Ok(self) } + /// Set the `SoundCode`s of this device. + pub fn with_sounds(self, sounds: &AttributeSetRef) -> io::Result { + unsafe { + sys::ui_set_evbit( + self.fd.as_raw_fd(), + crate::EventType::SOUND.0 as nix::sys::ioctl::ioctl_param_type, + )?; + } + + for bit in sounds.iter() { + unsafe { + sys::ui_set_sndbit( + self.fd.as_raw_fd(), + bit.0 as nix::sys::ioctl::ioctl_param_type, + )?; + } + } + + Ok(self) + } + + /// Set the `LedCode`s of this device. + pub fn with_leds(self, leds: &AttributeSetRef) -> io::Result { + unsafe { + sys::ui_set_evbit( + self.fd.as_raw_fd(), + crate::EventType::LED.0 as nix::sys::ioctl::ioctl_param_type, + )?; + } + + for bit in leds.iter() { + unsafe { + sys::ui_set_ledbit( + self.fd.as_raw_fd(), + bit.0 as nix::sys::ioctl::ioctl_param_type, + )?; + } + } + + Ok(self) + } + /// Finalize and register this device. /// /// # Errors