Add with_switches to uinput

This commit is contained in:
Julius Lehmann 2021-08-08 16:29:38 +02:00 committed by Jeff Hiner
parent ed4245c380
commit 4fbd2f17b0

View file

@ -4,7 +4,7 @@
use crate::constants::EventType;
use crate::inputid::{BusType, InputId};
use crate::{nix_err, sys, AttributeSetRef, InputEvent, Key, RelativeAxisType};
use crate::{nix_err, sys, AttributeSetRef, InputEvent, Key, RelativeAxisType, SwitchType};
use libc::O_NONBLOCK;
use std::fs::{File, OpenOptions};
use std::io::{self, Write};
@ -93,6 +93,28 @@ impl<'a> VirtualDeviceBuilder<'a> {
Ok(self)
}
pub fn with_switches(self, switches: &AttributeSetRef<SwitchType>) -> io::Result<Self> {
unsafe {
sys::ui_set_evbit(
self.file.as_raw_fd(),
crate::EventType::SWITCH.0 as nix::sys::ioctl::ioctl_param_type,
)
}
.map_err(nix_err)?;
for bit in switches.iter() {
unsafe {
sys::ui_set_swbit(
self.file.as_raw_fd(),
bit.0 as nix::sys::ioctl::ioctl_param_type,
)
}
.map_err(nix_err)?;
}
Ok(self)
}
pub fn build(self) -> io::Result<VirtualDevice> {
// Populate the uinput_setup struct