Move enum Event to crate input, begin work on EventWriter

This commit is contained in:
htrefil 2020-09-17 17:49:23 +02:00
parent b99f49115c
commit 8c55c00a5f
4 changed files with 38 additions and 2 deletions

View file

@ -1 +1,32 @@
pub struct EventWriter {}
use crate::async_file::{AsyncFile, OpenMode};
use crate::bindings;
use libc::c_int;
use std::io::Error;
use std::os::unix::io::AsRawFd;
pub struct EventWriter {
file: AsyncFile,
}
impl EventWriter {
pub async fn new() -> Result<Self, Error> {
let file = AsyncFile::open("/dev/uinput", OpenMode::Write).await?;
let fd = file.as_raw_fd();
for evbit in &[bindings::EV_KEY, bindings::EV_REL] {
// Doesn't work, UI_SET_KEYBIT not found.
// Probably too complicated for bindgen to be able to do something with it.
check_ioctl(unsafe { libc::ioctl(fd, bindings::UI_SET_KEYBIT, evbit) })?;
}
Ok(EventWriter { file })
}
}
fn check_ioctl(ret: c_int) -> Result<(), Error> {
if ret == -1 {
return Err(Error::last_os_error());
}
Ok(())
}

View file

@ -1,4 +1,9 @@
mod async_file;
mod bindings;
mod event;
mod event_reader;
mod event_writer;
pub use event::Event;
pub use event_reader::EventReader;
pub use event_writer::EventWriter;

View file

@ -1 +1 @@
mod event;