From 3bbae0c3680802e29f40bdb4153f52820fd5acee Mon Sep 17 00:00:00 2001 From: rrr-marble Date: Sat, 26 Jun 2021 20:58:50 +0300 Subject: [PATCH] initial commit --- .gitignore | 1 + Cargo.lock | 91 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++++ src/dpk.code-workspace | 8 ++++ src/main.rs | 33 +++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/dpk.code-workspace create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e7c74b8 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,91 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bitvec" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "470fbd40e959c961f16841fbf96edbbdcff766ead89a1ae2b53d22852be20998" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "cc" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "dpk" +version = "0.1.0" +dependencies = [ + "evdev", +] + +[[package]] +name = "evdev" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a9fbd0d18faa6e194945a35d8f57b504502835a4a82a622723b8184818e72a" +dependencies = [ + "bitvec", + "libc", + "nix", +] + +[[package]] +name = "funty" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" + +[[package]] +name = "libc" +version = "0.2.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" + +[[package]] +name = "nix" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", +] + +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8975499 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "dpk" +version = "0.1.0" +authors = ["rrr-marble "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +evdev = "0.11.0" \ No newline at end of file diff --git a/src/dpk.code-workspace b/src/dpk.code-workspace new file mode 100644 index 0000000..bab1b7f --- /dev/null +++ b/src/dpk.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b771106 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,33 @@ +use std::io::Write; + +fn main() -> ! { + let mut d = pick_device(); + println!("{}", d); + println!("Events:"); + loop { + for ev in d.fetch_events().unwrap() { + println!("{:?}", ev); + } + } +} + +fn pick_device() -> evdev::Device { + let mut args = std::env::args_os(); + args.next(); + + if let Some(dev_file) = args.next() { + evdev::Device::open(dev_file).unwrap() + } else { + let mut devices = evdev::enumerate().collect::>(); + devices.reverse(); + for (i, d) in devices.iter().enumerate() { + println!("{}: {}", i, d.name().unwrap_or("Unnamed device")); + } + print!("Select the device [0-{}]: ", devices.len()); + let _ = std::io::stdout().flush(); + let mut chosen = String::new(); + std::io::stdin().read_line(&mut chosen).unwrap(); + let n = chosen.trim().parse::().unwrap(); + devices.into_iter().nth(n).unwrap() + } +}