mirror of
https://codeberg.org/icewind/shortcutd.git
synced 2026-06-03 17:24:08 +02:00
don't expose dbus internals, docs
This commit is contained in:
parent
e65d8fbf57
commit
22cd9700bb
8 changed files with 72 additions and 29 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -421,9 +421,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "evdev-shortcut"
|
name = "evdev-shortcut"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cb870dc02f8a7955fa4ff451bbdd8bf9362d71b245a76bbe73a4c000cf012709"
|
checksum = "2b4f39c22648d85b48414b5fe5be7b1c392a4c67b9da4c167030878ed06bc1cf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"evdev",
|
"evdev",
|
||||||
|
|
@ -1070,7 +1070,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shortcutd"
|
name = "shortcutd"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"evdev-shortcut",
|
"evdev-shortcut",
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
pin_mut!(stream);
|
pin_mut!(stream);
|
||||||
|
|
||||||
while let Some(event) = stream.next().await {
|
while let Some(event) = stream.next().await {
|
||||||
println!("{} {}", event.shortcut, event.state.as_str());
|
println!("{} {}", event.shortcut, event.state);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "shortcutd"
|
name = "shortcutd"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "shortcutd client library"
|
description = "shortcutd client library"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/icewind1991/shortcutd"
|
repository = "https://github.com/icewind1991/shortcutd"
|
||||||
|
readme = "../README.md"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "shortcutd"
|
name = "shortcutd"
|
||||||
|
|
@ -14,7 +15,7 @@ path = "src/lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
zbus = { version = "3.13.1", features = ["tokio"], default-features = false }
|
zbus = { version = "3.13.1", features = ["tokio"], default-features = false }
|
||||||
evdev-shortcut = { version = "0.1.2", default_features = false }
|
evdev-shortcut = { version = "0.1.4", default_features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
test-case = "3.1.0"
|
test-case = "3.1.0"
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
pin_mut!(stream);
|
pin_mut!(stream);
|
||||||
|
|
||||||
while let Some(event) = stream.next().await {
|
while let Some(event) = stream.next().await {
|
||||||
println!("{} {}", event.shortcut, event.state.as_str());
|
println!("{} {}", event.shortcut, event.state);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
pin_mut!(stream);
|
pin_mut!(stream);
|
||||||
|
|
||||||
while let Some(event) = stream.next().await {
|
while let Some(event) = stream.next().await {
|
||||||
println!("{} {}", event.shortcut, event.state.as_str());
|
println!("{} {}", event.shortcut, event.state);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
client/src/dbus.rs
Normal file
20
client/src/dbus.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
use zbus::dbus_proxy;
|
||||||
|
use zbus::fdo;
|
||||||
|
|
||||||
|
#[dbus_proxy(
|
||||||
|
interface = "nl.icewind.shortcutd",
|
||||||
|
default_service = "nl.icewind.shortcutd",
|
||||||
|
default_path = "/register"
|
||||||
|
)]
|
||||||
|
trait Register {
|
||||||
|
async fn register(&self, shortcut: &str) -> fdo::Result<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[dbus_proxy(
|
||||||
|
interface = "nl.icewind.shortcutd",
|
||||||
|
default_service = "nl.icewind.shortcutd"
|
||||||
|
)]
|
||||||
|
trait ShortcutSignal {
|
||||||
|
#[dbus_proxy(signal)]
|
||||||
|
async fn triggered(&self, pressed: bool) -> fdo::Result<()>;
|
||||||
|
}
|
||||||
|
|
@ -1,42 +1,64 @@
|
||||||
|
//! shortcutd is a daemon and client library to allow listening for global shortcuts for systems that don't support it
|
||||||
|
//! otherwise (such as wayland).
|
||||||
|
//!
|
||||||
|
//! The shortcutd daemon hooks into the evdev system and exposes a dbus interface for clients to hook into to.
|
||||||
|
//! By separating out the code that hooks into evdev (which needs to be done as root) into a separate daemon
|
||||||
|
//! it allows non-privileged users to hook into global shortcuts.
|
||||||
|
//!
|
||||||
|
//! Protection against clients using the shortcutd daemon for a keylogger is done by only allowing 3 shortcuts without modifiers to be registered at the same time.
|
||||||
|
//!
|
||||||
|
//! See the [README](https://github.com/icewind1991/shortcutd) for instruction to running the shortcut daemon.
|
||||||
|
//!
|
||||||
|
//! Example:
|
||||||
|
//!
|
||||||
|
//! ```rust,no_run
|
||||||
|
//! # use futures::{pin_mut, StreamExt};
|
||||||
|
//! # use shortcutd::{Shortcut, ShortcutClient};
|
||||||
|
//! # use std::error::Error;
|
||||||
|
//! # #[tokio::main]
|
||||||
|
//! # async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
//! let client = ShortcutClient::new().await?;
|
||||||
|
//! let shortcut: Shortcut = "<Ctrl><Alt>-KeyO".parse()?;
|
||||||
|
//!
|
||||||
|
//! let stream = client.listen(shortcut).await?;
|
||||||
|
//! pin_mut!(stream);
|
||||||
|
//!
|
||||||
|
//! while let Some(event) = stream.next().await {
|
||||||
|
//! println!("{} {}", event.shortcut, event.state);
|
||||||
|
//! }
|
||||||
|
//! # Ok(())
|
||||||
|
//! # }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
|
||||||
|
mod dbus;
|
||||||
|
|
||||||
|
use dbus::{RegisterProxy, ShortcutSignalProxy};
|
||||||
pub use evdev_shortcut::{Key, Modifier, ModifierList, Shortcut, ShortcutEvent, ShortcutState};
|
pub use evdev_shortcut::{Key, Modifier, ModifierList, Shortcut, ShortcutEvent, ShortcutState};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use zbus::dbus_proxy;
|
use zbus::Connection;
|
||||||
use zbus::{fdo, Connection};
|
|
||||||
|
|
||||||
#[dbus_proxy(
|
|
||||||
interface = "nl.icewind.shortcutd",
|
|
||||||
default_service = "nl.icewind.shortcutd",
|
|
||||||
default_path = "/register"
|
|
||||||
)]
|
|
||||||
trait Register {
|
|
||||||
async fn register(&self, shortcut: &str) -> fdo::Result<String>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[dbus_proxy(
|
|
||||||
interface = "nl.icewind.shortcutd",
|
|
||||||
default_service = "nl.icewind.shortcutd"
|
|
||||||
)]
|
|
||||||
trait ShortcutSignal {
|
|
||||||
#[dbus_proxy(signal)]
|
|
||||||
async fn triggered(&self, pressed: bool) -> fdo::Result<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ShortcutClient {
|
pub struct ShortcutClient {
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShortcutClient {
|
impl ShortcutClient {
|
||||||
|
/// Create a new client by connecting to the system dbus
|
||||||
pub async fn new() -> Result<Self, zbus::Error> {
|
pub async fn new() -> Result<Self, zbus::Error> {
|
||||||
Ok(ShortcutClient {
|
Ok(ShortcutClient {
|
||||||
connection: Connection::system().await?,
|
connection: Connection::system().await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a client from an existing dbus connection
|
||||||
pub fn from_zbus(connection: Connection) -> Self {
|
pub fn from_zbus(connection: Connection) -> Self {
|
||||||
ShortcutClient { connection }
|
ShortcutClient { connection }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Listen to a shortcut
|
||||||
|
///
|
||||||
|
/// Returns a stream of of shortcut events
|
||||||
pub async fn listen(
|
pub async fn listen(
|
||||||
&self,
|
&self,
|
||||||
shortcut: Shortcut,
|
shortcut: Shortcut,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ path = "src/server.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
main_error = "0.1.0"
|
main_error = "0.1.0"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
evdev-shortcut = "0.1.3"
|
evdev-shortcut = "0.1.4"
|
||||||
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
zbus = { version = "3.13.1", features = ["tokio"], default-features = false }
|
zbus = { version = "3.13.1", features = ["tokio"], default-features = false }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue