mirror of
https://codeberg.org/icewind/evdev-shortcut.git
synced 2026-06-03 18:14:10 +02:00
tracing/state str
This commit is contained in:
parent
72e1d694f6
commit
a00d4751a1
4 changed files with 65 additions and 34 deletions
76
Cargo.lock
generated
76
Cargo.lock
generated
|
|
@ -97,6 +97,7 @@ dependencies = [
|
||||||
"test-case",
|
"test-case",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -357,27 +358,25 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error"
|
name = "proc-macro-error"
|
||||||
version = "1.0.2"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-error-attr",
|
"proc-macro-error-attr",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.17",
|
"syn 1.0.109",
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error-attr"
|
name = "proc-macro-error-attr"
|
||||||
version = "1.0.2"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.17",
|
|
||||||
"syn-mid",
|
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -472,13 +471,13 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.17"
|
version = "1.0.109"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"unicode-xid",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -492,17 +491,6 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn-mid"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.17",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tap"
|
name = "tap"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
|
@ -528,7 +516,7 @@ dependencies = [
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.17",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -540,7 +528,7 @@ dependencies = [
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.17",
|
"syn 1.0.109",
|
||||||
"test-case-core",
|
"test-case-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -608,23 +596,49 @@ dependencies = [
|
||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing"
|
||||||
|
version = "0.1.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tracing-attributes",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-attributes"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.18",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-core"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
|
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.1"
|
version = "0.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ async-stream = { version = "0.3.5", optional = true }
|
||||||
num_enum = "0.6.1"
|
num_enum = "0.6.1"
|
||||||
parse-display = "0.8.1"
|
parse-display = "0.8.1"
|
||||||
thiserror = "1.0.40"
|
thiserror = "1.0.40"
|
||||||
|
tracing = "0.1.37"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-case = "3.1.0"
|
test-case = "3.1.0"
|
||||||
|
|
|
||||||
11
src/lib.rs
11
src/lib.rs
|
|
@ -235,12 +235,21 @@ mod triggered_tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
pub enum ShortcutState {
|
pub enum ShortcutState {
|
||||||
Pressed,
|
Pressed,
|
||||||
Released,
|
Released,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ShortcutState {
|
||||||
|
pub fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
ShortcutState::Pressed => "pressed",
|
||||||
|
ShortcutState::Released => "released",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ShortcutEvent {
|
pub struct ShortcutEvent {
|
||||||
pub shortcut: Shortcut,
|
pub shortcut: Shortcut,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use async_stream::stream;
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use futures::stream::{iter};
|
use futures::stream::{iter};
|
||||||
|
use tracing::{debug, trace, info};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ShortcutListener {
|
pub struct ShortcutListener {
|
||||||
|
|
@ -24,7 +25,11 @@ impl ShortcutListener {
|
||||||
|
|
||||||
let devices = devices
|
let devices = devices
|
||||||
.iter()
|
.iter()
|
||||||
.map(|path| Device::open(path).map_err(|_| DeviceOpenError))
|
.map(|path| {
|
||||||
|
let res = Device::open(path).map_err(|_| DeviceOpenError);
|
||||||
|
debug!(device = ?path.as_ref(), success = res.is_ok(), "opening input device");
|
||||||
|
res
|
||||||
|
})
|
||||||
.collect::<Result<Vec<Device>, DeviceOpenError>>()?;
|
.collect::<Result<Vec<Device>, DeviceOpenError>>()?;
|
||||||
let events = iter(devices.into_iter().flat_map(|device| device.into_event_stream()))
|
let events = iter(devices.into_iter().flat_map(|device| device.into_event_stream()))
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
@ -36,7 +41,7 @@ impl ShortcutListener {
|
||||||
pin_mut!(events);
|
pin_mut!(events);
|
||||||
|
|
||||||
while let Some(Ok(event)) = events.next().await {
|
while let Some(Ok(event)) = events.next().await {
|
||||||
// dbg!(&event);
|
trace!(?event, "evdev event");
|
||||||
if let Ok(key) = Key::try_from(event.code()) {
|
if let Ok(key) = Key::try_from(event.code()) {
|
||||||
match event.value() {
|
match event.value() {
|
||||||
1 => active_keys.insert(key),
|
1 => active_keys.insert(key),
|
||||||
|
|
@ -52,12 +57,14 @@ impl ShortcutListener {
|
||||||
let was_triggered = pressed_shortcuts.contains(&shortcut);
|
let was_triggered = pressed_shortcuts.contains(&shortcut);
|
||||||
if is_triggered && !was_triggered {
|
if is_triggered && !was_triggered {
|
||||||
pressed_shortcuts.insert(shortcut.clone());
|
pressed_shortcuts.insert(shortcut.clone());
|
||||||
|
info!(?shortcut, "pressed");
|
||||||
yield ShortcutEvent {
|
yield ShortcutEvent {
|
||||||
shortcut,
|
shortcut,
|
||||||
state: ShortcutState::Pressed,
|
state: ShortcutState::Pressed,
|
||||||
};
|
};
|
||||||
} else if !is_triggered && was_triggered {
|
} else if !is_triggered && was_triggered {
|
||||||
pressed_shortcuts.remove(&shortcut);
|
pressed_shortcuts.remove(&shortcut);
|
||||||
|
info!(?shortcut, "released");
|
||||||
yield ShortcutEvent {
|
yield ShortcutEvent {
|
||||||
shortcut,
|
shortcut,
|
||||||
state: ShortcutState::Released,
|
state: ShortcutState::Released,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue