Switch to different evdev crate
This commit is contained in:
parent
0c4e217fa7
commit
2b571347ec
2 changed files with 28 additions and 2 deletions
|
@ -15,4 +15,5 @@ strum_macros = "*"
|
|||
serde = { version = "*", features = ["derive"] }
|
||||
anyhow = "*"
|
||||
rfd = "*"
|
||||
evdev = { git = "http://www.gavania.de/hodasemi/evdev-rs" }
|
||||
evdev-rs = "*"
|
||||
# evdev = { git = "http://www.gavania.de/hodasemi/evdev-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<String> {
|
||||
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<Device> {
|
||||
evdev::enumerate()
|
||||
.map(|(path, device)| {
|
||||
|
|
Loading…
Reference in a new issue