mirror of
https://codeberg.org/icewind/shortcutd.git
synced 2026-06-03 09:14:07 +02:00
listen to all keyboards
This commit is contained in:
parent
b07bf5012a
commit
4fbdc1164c
7 changed files with 50 additions and 15 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -79,6 +79,12 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
|
@ -355,6 +361,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"dbus",
|
||||
"evdev",
|
||||
"glob",
|
||||
"main_error",
|
||||
"num_enum",
|
||||
"parse-display",
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
|
|||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "shortcutd_client"
|
||||
name = "shortcutd"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "shortcutd_server"
|
||||
name = "shortcutd"
|
||||
path = "src/server.rs"
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -18,6 +18,7 @@ main_error = "0.1.0"
|
|||
num_enum = "0.4.3"
|
||||
dbus = "0.8.2"
|
||||
parse-display = "0.1.1"
|
||||
glob = "0.3.0"
|
||||
|
||||
[dev-dependencies]
|
||||
test-case = "1.0.0"
|
||||
|
|
@ -22,7 +22,7 @@ contain at least one modifier key.
|
|||
## Rust api
|
||||
|
||||
```rust
|
||||
use shortcutd_client::{Shortcut, ShortcutClient};
|
||||
use shortcutd::{Shortcut, ShortcutClient};
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use shortcutd_client::{Shortcut, ShortcutClient};
|
||||
use shortcutd::{Shortcut, ShortcutClient};
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
|
|||
28
shortcutd.service
Normal file
28
shortcutd.service
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[Unit]
|
||||
Description=shortcutd
|
||||
|
||||
[Service]
|
||||
# restrict permissions as much as possible
|
||||
ProtectControlGroups=true
|
||||
ProtectHome=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectSystem=full
|
||||
RestrictSUIDSGID=true
|
||||
PrivateNetwork=true
|
||||
CapabilityBoundingSet=true
|
||||
RestrictNamespaces=true
|
||||
RestrictAddressFamilies=AF_UNIX
|
||||
PrivateUsers=true
|
||||
PrivateTmp=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
NoNewPrivileges=true
|
||||
SystemCallFilter=@system-service
|
||||
SystemCallFilter=~@resources
|
||||
MemoryDenyWriteExecute=true
|
||||
IPAddressDeny=any
|
||||
|
||||
ExecStart=/usr/bin/shortcutd
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -153,7 +153,6 @@ impl Shortcut {
|
|||
#[cfg(test)]
|
||||
mod triggered_tests {
|
||||
use crate::keyboard::{Key, Shortcut};
|
||||
|
||||
use test_case::test_case;
|
||||
|
||||
#[test_case("<Ctrl>-KeyP", & [] => false)]
|
||||
|
|
@ -187,7 +186,7 @@ impl ShortcutListener {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn listen(&self, mut device: Device) -> Receiver<Shortcut> {
|
||||
pub fn listen(&self, mut devices: Vec<Device>) -> Receiver<Shortcut> {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let shortcuts = self.shortcuts.clone();
|
||||
|
|
@ -198,7 +197,11 @@ impl ShortcutListener {
|
|||
loop {
|
||||
let mut got_event = false;
|
||||
|
||||
for ev in device.events().unwrap() {
|
||||
let events = devices
|
||||
.iter_mut()
|
||||
.flat_map(|device| device.events().unwrap());
|
||||
|
||||
for ev in events {
|
||||
got_event = true;
|
||||
|
||||
if let Ok(key) = Key::try_from(ev.code) {
|
||||
|
|
|
|||
|
|
@ -63,19 +63,15 @@ impl<M: MethodType<D> + 'static, D: DataType + 'static> MutateTree<M, D> {
|
|||
}
|
||||
|
||||
fn main() -> Result<(), MainError> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let device = if args.len() > 1 {
|
||||
Device::open(&args[1])?
|
||||
} else {
|
||||
eprintln!("Usage {} </dev/input/...>", args[0]);
|
||||
return Ok(());
|
||||
};
|
||||
let devices = glob::glob("/dev/input/by-id/*-kbd")?
|
||||
.map(|path| Ok(Device::open(&path.unwrap())?))
|
||||
.collect::<Result<Vec<Device>, MainError>>()?;
|
||||
|
||||
let listener = Arc::new(ShortcutListener::new());
|
||||
|
||||
let mut signals: HashMap<String, Arc<Signal<()>>> = HashMap::default();
|
||||
|
||||
let rx = listener.listen(device);
|
||||
let rx = listener.listen(devices);
|
||||
|
||||
let mut connection = LocalConnection::new_system()?;
|
||||
connection.request_name(INTERFACE, false, true, false)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue