mirror of
https://github.com/htrefil/rkvm.git
synced 2025-01-30 20:34:13 +01:00
Move enum Event to crate input, begin work on EventWriter
This commit is contained in:
parent
b99f49115c
commit
8c55c00a5f
4 changed files with 38 additions and 2 deletions
|
@ -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(())
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
mod async_file;
|
mod async_file;
|
||||||
mod bindings;
|
mod bindings;
|
||||||
|
mod event;
|
||||||
mod event_reader;
|
mod event_reader;
|
||||||
mod event_writer;
|
mod event_writer;
|
||||||
|
|
||||||
|
pub use event::Event;
|
||||||
|
pub use event_reader::EventReader;
|
||||||
|
pub use event_writer::EventWriter;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
mod event;
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue