started implementation of key recording

This commit is contained in:
Schrottkatze 2022-06-16 19:23:19 +02:00
parent 1241b947b5
commit 1a5d7f9ac9

View file

@ -1,3 +1,65 @@
fn main() { use std::os::raw::c_uint;
todo!(); use std::process::{exit, ExitCode};
use clap::Parser;
use x11::keysym::XK_Escape;
use x11::xinput2::XIGrabModeSync;
use x11::xlib::{CurrentTime, GrabModeAsync, GrabModeSync, GrabSuccess, KeyCode, KeyPress, KeyPressMask, SyncPointer, XEvent};
use easymacros::x11_safe_wrapper::{Keycode, XDisplay};
/// Macro recording module for easymacros. Outputs are partially compatible with xmacro.
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// The file that contains the macro to run.
#[clap(value_parser, value_name = "input_file", value_hint = clap::ValueHint::FilePath)]
output_file: std::path::PathBuf,
/// Display to run the macro on. This uses the $DISPLAY environment variable by default.
#[clap(short, long)]
display: Option<String>,
}
fn main() {
let args = Args::parse();
let display = XDisplay::open(args.display);
let stop_key = get_stop_key(display);
}
fn get_stop_key(display: XDisplay) -> Keycode {
let screen = display.get_default_screen();
let root = display.get_root_window(screen);
let potential_err = display.grab_keyboard(root, false, GrabModeSync, GrabModeAsync, CurrentTime);
if potential_err != GrabSuccess {
eprintln!("Couldn't grab keyboard!");
exit(1);
}
println!("Press the key you want to use to stop recording the macro.");
let mut stop_key = XK_Escape;
loop {
display.allow_events(SyncPointer, CurrentTime);
let ev = display.window_event(root, KeyPressMask);
unsafe {
match ev {
XEvent { key } => {
stop_key = key.keycode;
break;
}
_ => {},
}
}
}
stop_key
}
unsafe extern "C" fn ev_callback() {
} }