From 2b571347ecaa1f85d7b0c15ff1f60e85a78e197e Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sun, 30 Jan 2022 21:33:58 +0100 Subject: [PATCH] Switch to different evdev crate --- Cargo.toml | 3 ++- src/device.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b58325b..cd0fcd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ strum_macros = "*" serde = { version = "*", features = ["derive"] } anyhow = "*" rfd = "*" -evdev = { git = "http://www.gavania.de/hodasemi/evdev-rs" } \ No newline at end of file +evdev-rs = "*" +# evdev = { git = "http://www.gavania.de/hodasemi/evdev-rs" } \ No newline at end of file diff --git a/src/device.rs b/src/device.rs index 1769dce..1c63eb5 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,4 +1,4 @@ -use evdev::{Device as EvDevice, EventType, InputEventKind}; +use evdev_rs::{Device as EvDevice, EventType, InputEventKind}; use std::collections::HashMap; use crate::graph_types::{Descriptor, NodeDescriptor}; @@ -11,6 +11,31 @@ pub struct Device { } impl Device { + fn enumerate() -> Vec { + let mut files = Vec::new(); + + if let Some(readdir) = std::fs::read_dir("/dev/input").ok() { + for entry in readdir { + let path = entry.unwrap().path(); + let fname = path.file_name().unwrap(); + if fname.as_bytes().starts_with(b"event") { + // Try to load read/write, then fall back to read-only. + if options + .read(true) + .write(true) + .open(path) + .or_else(|_| options.write(false).open(path)) + .is_ok() + { + files.push(fname); + } + } + } + } + + files + } + pub fn query() -> Vec { evdev::enumerate() .map(|(path, device)| {