Merge pull request #62 from waynr/enable-showing-system-path

enable getting system path for Device
This commit is contained in:
Noa 2022-01-25 12:00:02 -06:00 committed by GitHub
commit 93d8fb23e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View file

@ -9,7 +9,9 @@ pub fn pick_device() -> evdev::Device {
if let Some(dev_file) = args.next() {
evdev::Device::open(dev_file).unwrap()
} else {
let mut devices = evdev::enumerate().collect::<Vec<_>>();
let mut devices = evdev::enumerate()
.map(|t| t.1)
.collect::<Vec<_>>();
// readdir returns them in reverse order from their eventN names for some reason
devices.reverse();
for (i, d) in devices.iter().enumerate() {

View file

@ -87,6 +87,7 @@ pub mod uinput;
mod tokio_stream;
use std::fmt;
use std::path::PathBuf;
use std::time::{Duration, SystemTime};
// pub use crate::constants::FFEffect::*;
@ -249,9 +250,9 @@ pub struct EnumerateDevices {
inner: raw_stream::EnumerateDevices,
}
impl Iterator for EnumerateDevices {
type Item = Device;
fn next(&mut self) -> Option<Device> {
self.inner.next().map(Device::from_raw_device)
type Item = (PathBuf, Device);
fn next(&mut self) -> Option<(PathBuf, Device)> {
self.inner.next().map(|(pb, dev)| (pb, Device::from_raw_device(dev)))
}
}

View file

@ -2,7 +2,7 @@ use std::fs::{File, OpenOptions};
use std::io::Write;
use std::mem::MaybeUninit;
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::Path;
use std::path::{Path, PathBuf};
use std::{io, mem};
use crate::constants::*;
@ -656,8 +656,8 @@ pub struct EnumerateDevices {
readdir: Option<std::fs::ReadDir>,
}
impl Iterator for EnumerateDevices {
type Item = RawDevice;
fn next(&mut self) -> Option<RawDevice> {
type Item = (PathBuf, RawDevice);
fn next(&mut self) -> Option<(PathBuf, RawDevice)> {
use std::os::unix::ffi::OsStrExt;
let readdir = self.readdir.as_mut()?;
loop {
@ -666,7 +666,7 @@ impl Iterator for EnumerateDevices {
let fname = path.file_name().unwrap();
if fname.as_bytes().starts_with(b"event") {
if let Ok(dev) = RawDevice::open(&path) {
return Some(dev);
return Some((path, dev));
}
}
}