mirror of
https://github.com/deunix-educ/sourizz.git
synced 2026-11-25 04:39:43 +01:00
fee42ae92d
Spotlight, ring, trails, click effects, keystroke display and on-screen annotation for X11 and Wayland, written in Rust. One drawing engine (engine.rs) shared by an X11 backend (override-redirect ARGB windows, XInput2 raw events) and a Wayland backend (wlr-layer-shell, evdev input, Hyprland/KWin pointer sources), plus a tray, a CLI socket and an egui settings window. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
1.4 KiB
Rust
32 lines
1.4 KiB
Rust
//! Press a chord through XTEST: `fake_keys Control_L Alt_L Shift_L F9` (last key is the main one).
|
|
use x11rb::connection::Connection;
|
|
use x11rb::protocol::xproto::{self, ConnectionExt as _};
|
|
use x11rb::protocol::xtest::ConnectionExt as _;
|
|
|
|
fn main() {
|
|
let names: Vec<String> = std::env::args().skip(1).collect();
|
|
let (conn, sn) = x11rb::connect(None).unwrap();
|
|
let root = conn.setup().roots[sn].root;
|
|
let (min, max) = (conn.setup().min_keycode, conn.setup().max_keycode);
|
|
let map = conn.get_keyboard_mapping(min, max - min + 1).unwrap().reply().unwrap();
|
|
let per = map.keysyms_per_keycode as usize;
|
|
let code = |name: &str| -> u8 {
|
|
let sym = sourizz::keysym::from_name(name).unwrap_or_else(|| panic!("unknown key {name}"));
|
|
(0..(map.keysyms.len() / per))
|
|
.find(|r| map.keysyms[r * per] == sym)
|
|
.map(|r| min + r as u8)
|
|
.unwrap_or_else(|| panic!("{name} not on keyboard"))
|
|
};
|
|
let codes: Vec<u8> = names.iter().map(|n| code(n)).collect();
|
|
for c in &codes {
|
|
conn.xtest_fake_input(xproto::KEY_PRESS_EVENT, *c, 0, root, 0, 0, 0).unwrap();
|
|
conn.flush().unwrap();
|
|
std::thread::sleep(std::time::Duration::from_millis(30));
|
|
}
|
|
for c in codes.iter().rev() {
|
|
conn.xtest_fake_input(xproto::KEY_RELEASE_EVENT, *c, 0, root, 0, 0, 0).unwrap();
|
|
conn.flush().unwrap();
|
|
std::thread::sleep(std::time::Duration::from_millis(30));
|
|
}
|
|
}
|