Update to nix 0.22, remove custom conversion from nix::Error -> io::Error
This commit is contained in:
parent
4fbd2f17b0
commit
a458675fb8
5 changed files with 51 additions and 103 deletions
|
@ -14,7 +14,7 @@ tokio = ["tokio_1", "futures-core"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.89"
|
libc = "0.2.89"
|
||||||
bitvec = "0.21"
|
bitvec = "0.21"
|
||||||
nix = "0.20"
|
nix = "0.22"
|
||||||
|
|
||||||
tokio_1 = { package = "tokio", version = "1.0", features = ["net"], optional = true }
|
tokio_1 = { package = "tokio", version = "1.0", features = ["net"], optional = true }
|
||||||
futures-core = { version = "0.3", optional = true }
|
futures-core = { version = "0.3", optional = true }
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -86,8 +86,8 @@ pub mod uinput;
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
mod tokio_stream;
|
mod tokio_stream;
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use std::{fmt, io};
|
|
||||||
|
|
||||||
// pub use crate::constants::FFEffect::*;
|
// pub use crate::constants::FFEffect::*;
|
||||||
pub use attribute_set::{AttributeSet, AttributeSetRef};
|
pub use attribute_set::{AttributeSet, AttributeSetRef};
|
||||||
|
@ -277,16 +277,6 @@ fn timeval_to_systime(tv: &libc::timeval) -> SystemTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn nix_err(err: nix::Error) -> io::Error {
|
|
||||||
match err {
|
|
||||||
nix::Error::Sys(errno) => io::Error::from_raw_os_error(errno as i32),
|
|
||||||
nix::Error::InvalidPath => io::Error::new(io::ErrorKind::InvalidInput, err),
|
|
||||||
nix::Error::InvalidUtf8 => io::Error::new(io::ErrorKind::Other, err),
|
|
||||||
// TODO: io::ErrorKind::NotSupported once stable
|
|
||||||
nix::Error::UnsupportedOperation => io::Error::new(io::ErrorKind::Other, err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// SAFETY: T must not have any padding or otherwise uninitialized bytes inside of it
|
/// SAFETY: T must not have any padding or otherwise uninitialized bytes inside of it
|
||||||
pub(crate) unsafe fn cast_to_bytes<T: ?Sized>(mem: &T) -> &[u8] {
|
pub(crate) unsafe fn cast_to_bytes<T: ?Sized>(mem: &T) -> &[u8] {
|
||||||
std::slice::from_raw_parts(mem as *const T as *const u8, std::mem::size_of_val(mem))
|
std::slice::from_raw_parts(mem as *const T as *const u8, std::mem::size_of_val(mem))
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::path::Path;
|
||||||
use std::{io, mem};
|
use std::{io, mem};
|
||||||
|
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::{nix_err, sys, AttributeSet, AttributeSetRef, InputEvent, InputId, Key};
|
use crate::{sys, AttributeSet, AttributeSetRef, InputEvent, InputId, Key};
|
||||||
|
|
||||||
fn ioctl_get_cstring(
|
fn ioctl_get_cstring(
|
||||||
f: unsafe fn(RawFd, &mut [u8]) -> nix::Result<libc::c_int>,
|
f: unsafe fn(RawFd, &mut [u8]) -> nix::Result<libc::c_int>,
|
||||||
|
@ -96,9 +96,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let ty = {
|
let ty = {
|
||||||
let mut ty = AttributeSet::<EventType>::new();
|
let mut ty = AttributeSet::<EventType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_type(file.as_raw_fd(), ty.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_type(file.as_raw_fd(), ty.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
ty
|
ty
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -111,12 +109,12 @@ impl RawDevice {
|
||||||
|
|
||||||
let id = unsafe {
|
let id = unsafe {
|
||||||
let mut id = MaybeUninit::uninit();
|
let mut id = MaybeUninit::uninit();
|
||||||
sys::eviocgid(file.as_raw_fd(), id.as_mut_ptr()).map_err(nix_err)?;
|
sys::eviocgid(file.as_raw_fd(), id.as_mut_ptr())?;
|
||||||
id.assume_init()
|
id.assume_init()
|
||||||
};
|
};
|
||||||
let mut driver_version: i32 = 0;
|
let mut driver_version: i32 = 0;
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::eviocgversion(file.as_raw_fd(), &mut driver_version).map_err(nix_err)?;
|
sys::eviocgversion(file.as_raw_fd(), &mut driver_version)?;
|
||||||
}
|
}
|
||||||
let driver_version = (
|
let driver_version = (
|
||||||
((driver_version >> 16) & 0xff) as u8,
|
((driver_version >> 16) & 0xff) as u8,
|
||||||
|
@ -126,17 +124,13 @@ impl RawDevice {
|
||||||
|
|
||||||
let props = {
|
let props = {
|
||||||
let mut props = AttributeSet::<PropType>::new();
|
let mut props = AttributeSet::<PropType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgprop(file.as_raw_fd(), props.as_mut_raw_slice())? };
|
||||||
sys::eviocgprop(file.as_raw_fd(), props.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
props
|
props
|
||||||
}; // FIXME: handle old kernel
|
}; // FIXME: handle old kernel
|
||||||
|
|
||||||
let supported_keys = if ty.contains(EventType::KEY) {
|
let supported_keys = if ty.contains(EventType::KEY) {
|
||||||
let mut keys = AttributeSet::<Key>::new();
|
let mut keys = AttributeSet::<Key>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_key(file.as_raw_fd(), keys.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_key(file.as_raw_fd(), keys.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(keys)
|
Some(keys)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -144,10 +138,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_relative = if ty.contains(EventType::RELATIVE) {
|
let supported_relative = if ty.contains(EventType::RELATIVE) {
|
||||||
let mut rel = AttributeSet::<RelativeAxisType>::new();
|
let mut rel = AttributeSet::<RelativeAxisType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_relative(file.as_raw_fd(), rel.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_relative(file.as_raw_fd(), rel.as_mut_raw_slice())
|
|
||||||
.map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(rel)
|
Some(rel)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -155,10 +146,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_absolute = if ty.contains(EventType::ABSOLUTE) {
|
let supported_absolute = if ty.contains(EventType::ABSOLUTE) {
|
||||||
let mut abs = AttributeSet::<AbsoluteAxisType>::new();
|
let mut abs = AttributeSet::<AbsoluteAxisType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_absolute(file.as_raw_fd(), abs.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_absolute(file.as_raw_fd(), abs.as_mut_raw_slice())
|
|
||||||
.map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(abs)
|
Some(abs)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -166,10 +154,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_switch = if ty.contains(EventType::SWITCH) {
|
let supported_switch = if ty.contains(EventType::SWITCH) {
|
||||||
let mut switch = AttributeSet::<SwitchType>::new();
|
let mut switch = AttributeSet::<SwitchType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_switch(file.as_raw_fd(), switch.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_switch(file.as_raw_fd(), switch.as_mut_raw_slice())
|
|
||||||
.map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(switch)
|
Some(switch)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -177,9 +162,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_led = if ty.contains(EventType::LED) {
|
let supported_led = if ty.contains(EventType::LED) {
|
||||||
let mut led = AttributeSet::<LedType>::new();
|
let mut led = AttributeSet::<LedType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_led(file.as_raw_fd(), led.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_led(file.as_raw_fd(), led.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(led)
|
Some(led)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -187,9 +170,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_misc = if ty.contains(EventType::MISC) {
|
let supported_misc = if ty.contains(EventType::MISC) {
|
||||||
let mut misc = AttributeSet::<MiscType>::new();
|
let mut misc = AttributeSet::<MiscType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_misc(file.as_raw_fd(), misc.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_misc(file.as_raw_fd(), misc.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(misc)
|
Some(misc)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -199,9 +180,7 @@ impl RawDevice {
|
||||||
|
|
||||||
let supported_snd = if ty.contains(EventType::SOUND) {
|
let supported_snd = if ty.contains(EventType::SOUND) {
|
||||||
let mut snd = AttributeSet::<SoundType>::new();
|
let mut snd = AttributeSet::<SoundType>::new();
|
||||||
unsafe {
|
unsafe { sys::eviocgbit_sound(file.as_raw_fd(), snd.as_mut_raw_slice())? };
|
||||||
sys::eviocgbit_sound(file.as_raw_fd(), snd.as_mut_raw_slice()).map_err(nix_err)?
|
|
||||||
};
|
|
||||||
Some(snd)
|
Some(snd)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -217,9 +196,8 @@ impl RawDevice {
|
||||||
sys::eviocgrep(
|
sys::eviocgrep(
|
||||||
file.as_raw_fd(),
|
file.as_raw_fd(),
|
||||||
&mut auto_repeat as *mut AutoRepeat as *mut [u32; 2],
|
&mut auto_repeat as *mut AutoRepeat as *mut [u32; 2],
|
||||||
)
|
)?;
|
||||||
.map_err(nix_err)?
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Some(auto_repeat)
|
Some(auto_repeat)
|
||||||
} else {
|
} else {
|
||||||
|
@ -416,7 +394,7 @@ impl RawDevice {
|
||||||
|
|
||||||
// use libc::read instead of nix::unistd::read b/c we need to pass an uninitialized buf
|
// use libc::read instead of nix::unistd::read b/c we need to pass an uninitialized buf
|
||||||
let res = unsafe { libc::read(fd, spare_capacity.as_mut_ptr() as _, spare_capacity_size) };
|
let res = unsafe { libc::read(fd, spare_capacity.as_mut_ptr() as _, spare_capacity_size) };
|
||||||
let bytes_read = nix::errno::Errno::result(res).map_err(nix_err)?;
|
let bytes_read = nix::errno::Errno::result(res)?;
|
||||||
let num_read = bytes_read as usize / mem::size_of::<libc::input_event>();
|
let num_read = bytes_read as usize / mem::size_of::<libc::input_event>();
|
||||||
unsafe {
|
unsafe {
|
||||||
let len = self.event_buf.len();
|
let len = self.event_buf.len();
|
||||||
|
@ -472,9 +450,8 @@ impl RawDevice {
|
||||||
/// [`get_key_state`](Self::get_key_state) instead.
|
/// [`get_key_state`](Self::get_key_state) instead.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_key_state(&self, key_vals: &mut AttributeSet<Key>) -> io::Result<()> {
|
pub fn update_key_state(&self, key_vals: &mut AttributeSet<Key>) -> io::Result<()> {
|
||||||
unsafe { sys::eviocgkey(self.as_raw_fd(), key_vals.as_mut_raw_slice()) }
|
unsafe { sys::eviocgkey(self.as_raw_fd(), key_vals.as_mut_raw_slice())? };
|
||||||
.map(|_| ())
|
Ok(())
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the current kernel absolute axis state directly into the provided buffer.
|
/// Fetch the current kernel absolute axis state directly into the provided buffer.
|
||||||
|
@ -492,8 +469,7 @@ impl RawDevice {
|
||||||
// handling later removed. not sure what the intention of "handling that later" was
|
// handling later removed. not sure what the intention of "handling that later" was
|
||||||
// the abs data seems to be fine (tested ABS_MT_POSITION_X/Y)
|
// the abs data seems to be fine (tested ABS_MT_POSITION_X/Y)
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::eviocgabs(self.as_raw_fd(), idx as u32, &mut abs_vals[idx as usize])
|
sys::eviocgabs(self.as_raw_fd(), idx as u32, &mut abs_vals[idx as usize])?
|
||||||
.map_err(nix_err)?
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,9 +484,8 @@ impl RawDevice {
|
||||||
&self,
|
&self,
|
||||||
switch_vals: &mut AttributeSet<SwitchType>,
|
switch_vals: &mut AttributeSet<SwitchType>,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
unsafe { sys::eviocgsw(self.as_raw_fd(), switch_vals.as_mut_raw_slice()) }
|
unsafe { sys::eviocgsw(self.as_raw_fd(), switch_vals.as_mut_raw_slice())? };
|
||||||
.map(|_| ())
|
Ok(())
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the current kernel LED state directly into the provided buffer.
|
/// Fetch the current kernel LED state directly into the provided buffer.
|
||||||
|
@ -518,9 +493,8 @@ impl RawDevice {
|
||||||
/// [`get_led_state`](Self::get_led_state) instead.
|
/// [`get_led_state`](Self::get_led_state) instead.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_led_state(&self, led_vals: &mut AttributeSet<LedType>) -> io::Result<()> {
|
pub fn update_led_state(&self, led_vals: &mut AttributeSet<LedType>) -> io::Result<()> {
|
||||||
unsafe { sys::eviocgled(self.as_raw_fd(), led_vals.as_mut_raw_slice()) }
|
unsafe { sys::eviocgled(self.as_raw_fd(), led_vals.as_mut_raw_slice())? };
|
||||||
.map(|_| ())
|
Ok(())
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the auto repeat delays
|
/// Update the auto repeat delays
|
||||||
|
@ -530,12 +504,10 @@ impl RawDevice {
|
||||||
sys::eviocsrep(
|
sys::eviocsrep(
|
||||||
self.as_raw_fd(),
|
self.as_raw_fd(),
|
||||||
repeat as *const AutoRepeat as *const [u32; 2],
|
repeat as *const AutoRepeat as *const [u32; 2],
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map(|_| {
|
self.auto_repeat = Some(repeat.clone());
|
||||||
self.auto_repeat = Some(repeat.clone());
|
Ok(())
|
||||||
})
|
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the scancode for a keycode, if any
|
/// Retrieve the scancode for a keycode, if any
|
||||||
|
@ -547,10 +519,8 @@ impl RawDevice {
|
||||||
keycode,
|
keycode,
|
||||||
scancode: [0u8; 32],
|
scancode: [0u8; 32],
|
||||||
};
|
};
|
||||||
|
unsafe { sys::eviocgkeycode_v2(self.as_raw_fd(), &mut keymap)? };
|
||||||
unsafe { sys::eviocgkeycode_v2(self.as_raw_fd(), &mut keymap) }
|
Ok(keymap.scancode[..keymap.len as usize].to_vec())
|
||||||
.map(|_| keymap.scancode[..keymap.len as usize].to_vec())
|
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the keycode and scancode by index, starting at 0
|
/// Retrieve the keycode and scancode by index, starting at 0
|
||||||
|
@ -563,14 +533,11 @@ impl RawDevice {
|
||||||
scancode: [0u8; 32],
|
scancode: [0u8; 32],
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe { sys::eviocgkeycode_v2(self.as_raw_fd(), &mut keymap) }
|
unsafe { sys::eviocgkeycode_v2(self.as_raw_fd(), &mut keymap)? };
|
||||||
.map(|_| {
|
Ok((
|
||||||
(
|
keymap.keycode,
|
||||||
keymap.keycode,
|
keymap.scancode[..keymap.len as usize].to_vec(),
|
||||||
keymap.scancode[..keymap.len as usize].to_vec(),
|
))
|
||||||
)
|
|
||||||
})
|
|
||||||
.map_err(nix_err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update a scancode by index. The return value is the previous keycode
|
/// Update a scancode by index. The return value is the previous keycode
|
||||||
|
@ -592,9 +559,9 @@ impl RawDevice {
|
||||||
|
|
||||||
keymap.scancode[..len].copy_from_slice(scancode);
|
keymap.scancode[..len].copy_from_slice(scancode);
|
||||||
|
|
||||||
unsafe { sys::eviocskeycode_v2(self.as_raw_fd(), &keymap) }
|
let keycode = unsafe { sys::eviocskeycode_v2(self.as_raw_fd(), &keymap)? };
|
||||||
.map(|keycode| keycode as u32)
|
|
||||||
.map_err(nix_err)
|
Ok(keycode as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update a scancode. The return value is the previous keycode
|
/// Update a scancode. The return value is the previous keycode
|
||||||
|
@ -611,9 +578,9 @@ impl RawDevice {
|
||||||
|
|
||||||
keymap.scancode[..len].copy_from_slice(scancode);
|
keymap.scancode[..len].copy_from_slice(scancode);
|
||||||
|
|
||||||
unsafe { sys::eviocskeycode_v2(self.as_raw_fd(), &keymap) }
|
let keycode = unsafe { sys::eviocskeycode_v2(self.as_raw_fd(), &keymap)? };
|
||||||
.map(|keycode| keycode as u32)
|
|
||||||
.map_err(nix_err)
|
Ok(keycode as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
|
@ -699,8 +666,7 @@ mod tokio_stream {
|
||||||
impl EventStream {
|
impl EventStream {
|
||||||
pub(crate) fn new(device: RawDevice) -> io::Result<Self> {
|
pub(crate) fn new(device: RawDevice) -> io::Result<Self> {
|
||||||
use nix::fcntl;
|
use nix::fcntl;
|
||||||
fcntl::fcntl(device.as_raw_fd(), fcntl::F_SETFL(fcntl::OFlag::O_NONBLOCK))
|
fcntl::fcntl(device.as_raw_fd(), fcntl::F_SETFL(fcntl::OFlag::O_NONBLOCK))?;
|
||||||
.map_err(nix_err)?;
|
|
||||||
let device = AsyncFd::new(device)?;
|
let device = AsyncFd::new(device)?;
|
||||||
Ok(Self { device, index: 0 })
|
Ok(Self { device, index: 0 })
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,7 +677,6 @@ mod tokio_stream {
|
||||||
|
|
||||||
use tokio_1 as tokio;
|
use tokio_1 as tokio;
|
||||||
|
|
||||||
use crate::nix_err;
|
|
||||||
use crate::raw_stream::poll_fn;
|
use crate::raw_stream::poll_fn;
|
||||||
use futures_core::{ready, Stream};
|
use futures_core::{ready, Stream};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
@ -701,8 +700,7 @@ mod tokio_stream {
|
||||||
impl EventStream {
|
impl EventStream {
|
||||||
pub(crate) fn new(device: Device) -> io::Result<Self> {
|
pub(crate) fn new(device: Device) -> io::Result<Self> {
|
||||||
use nix::fcntl;
|
use nix::fcntl;
|
||||||
fcntl::fcntl(device.as_raw_fd(), fcntl::F_SETFL(fcntl::OFlag::O_NONBLOCK))
|
fcntl::fcntl(device.as_raw_fd(), fcntl::F_SETFL(fcntl::OFlag::O_NONBLOCK))?;
|
||||||
.map_err(nix_err)?;
|
|
||||||
let device = AsyncFd::new(device)?;
|
let device = AsyncFd::new(device)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
device,
|
device,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::constants::EventType;
|
use crate::constants::EventType;
|
||||||
use crate::inputid::{BusType, InputId};
|
use crate::inputid::{BusType, InputId};
|
||||||
use crate::{nix_err, sys, AttributeSetRef, InputEvent, Key, RelativeAxisType, SwitchType};
|
use crate::{sys, AttributeSetRef, InputEvent, Key, RelativeAxisType, SwitchType};
|
||||||
use libc::O_NONBLOCK;
|
use libc::O_NONBLOCK;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
@ -54,18 +54,16 @@ impl<'a> VirtualDeviceBuilder<'a> {
|
||||||
sys::ui_set_evbit(
|
sys::ui_set_evbit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
crate::EventType::KEY.0 as nix::sys::ioctl::ioctl_param_type,
|
crate::EventType::KEY.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
|
|
||||||
for bit in keys.iter() {
|
for bit in keys.iter() {
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::ui_set_keybit(
|
sys::ui_set_keybit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -76,18 +74,16 @@ impl<'a> VirtualDeviceBuilder<'a> {
|
||||||
sys::ui_set_evbit(
|
sys::ui_set_evbit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
crate::EventType::RELATIVE.0 as nix::sys::ioctl::ioctl_param_type,
|
crate::EventType::RELATIVE.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
|
|
||||||
for bit in axes.iter() {
|
for bit in axes.iter() {
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::ui_set_relbit(
|
sys::ui_set_relbit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -98,18 +94,16 @@ impl<'a> VirtualDeviceBuilder<'a> {
|
||||||
sys::ui_set_evbit(
|
sys::ui_set_evbit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
crate::EventType::SWITCH.0 as nix::sys::ioctl::ioctl_param_type,
|
crate::EventType::SWITCH.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
|
|
||||||
for bit in switches.iter() {
|
for bit in switches.iter() {
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::ui_set_swbit(
|
sys::ui_set_swbit(
|
||||||
self.file.as_raw_fd(),
|
self.file.as_raw_fd(),
|
||||||
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
bit.0 as nix::sys::ioctl::ioctl_param_type,
|
||||||
)
|
)?;
|
||||||
}
|
}
|
||||||
.map_err(nix_err)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -150,8 +144,8 @@ pub struct VirtualDevice {
|
||||||
impl VirtualDevice {
|
impl VirtualDevice {
|
||||||
/// Create a new virtual device.
|
/// Create a new virtual device.
|
||||||
fn new(file: File, usetup: &libc::uinput_setup) -> io::Result<Self> {
|
fn new(file: File, usetup: &libc::uinput_setup) -> io::Result<Self> {
|
||||||
unsafe { sys::ui_dev_setup(file.as_raw_fd(), usetup) }.map_err(nix_err)?;
|
unsafe { sys::ui_dev_setup(file.as_raw_fd(), usetup)? };
|
||||||
unsafe { sys::ui_dev_create(file.as_raw_fd()) }.map_err(nix_err)?;
|
unsafe { sys::ui_dev_create(file.as_raw_fd())? };
|
||||||
|
|
||||||
Ok(VirtualDevice { file })
|
Ok(VirtualDevice { file })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue