Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/uinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -214,6 +215,48 @@ impl<'a> VirtualDeviceBuilder<'a> {
Ok(self)
}

/// Set the `SoundCode`s of this device.
pub fn with_sounds(self, sounds: &AttributeSetRef<SoundCode>) -> io::Result<Self> {
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<LedCode>) -> io::Result<Self> {
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
Expand Down