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"] }
|
serde = { version = "*", features = ["derive"] }
|
||||||
anyhow = "*"
|
anyhow = "*"
|
||||||
rfd = "*"
|
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 std::collections::HashMap;
|
||||||
|
|
||||||
use crate::graph_types::{Descriptor, NodeDescriptor};
|
use crate::graph_types::{Descriptor, NodeDescriptor};
|
||||||
|
@ -11,6 +11,31 @@ pub struct Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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> {
|
pub fn query() -> Vec<Device> {
|
||||||
evdev::enumerate()
|
evdev::enumerate()
|
||||||
.map(|(path, device)| {
|
.map(|(path, device)| {
|
||||||
|
|
Loading…
Reference in a new issue