"started" working on event_delay support. and added to the TODOs.

This commit is contained in:
Schrottkatze 2022-07-11 12:18:43 +02:00
parent 5e0936b827
commit 9521e26cbc
2 changed files with 15 additions and 10 deletions

View file

@ -21,6 +21,9 @@ This program is inspired by [**xmacro**](https://github.com/Ortega-Dan/xmacroInc
- [x] Delay - [x] Delay
- [x] Keyboard actions - [x] Keyboard actions
- [x] Mouse actions - [x] Mouse actions
- [ ] Utilities for playing macros
- [ ] Ignoring delays when playing
- [ ] Event delay support
# #
</details> </details>

View file

@ -8,7 +8,7 @@ use std::io::stdin;
use x11::keysym::XK_Shift_L; use x11::keysym::XK_Shift_L;
use easymacros::chartbl::CHARTBL; use easymacros::chartbl::CHARTBL;
/// Macro player module for easymacros. It's partially compatible with xmacro macros, with aim for full compatibility. /// Macro player module for easymacros. It's compatible with xmacro macros.
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)] #[clap(author, version, about, long_about = None)]
struct Args { struct Args {
@ -16,8 +16,11 @@ struct Args {
#[clap(value_parser, value_name = "input_file", value_hint = clap::ValueHint::FilePath)] #[clap(value_parser, value_name = "input_file", value_hint = clap::ValueHint::FilePath)]
input_file: Option<std::path::PathBuf>, input_file: Option<std::path::PathBuf>,
/// Display to run the macro on. This uses the $DISPLAY environment variable by default. /// Display to run the macro on. This uses the $DISPLAY environment variable by default.
#[clap(short, long)] #[clap(short = "D", long)]
display: Option<String>, display: Option<String>,
// Delay for events to be sent.
// #[clap(short, long)]
// event_delay: Option<u16>,
} }
fn main() { fn main() {
@ -33,6 +36,7 @@ fn main() {
run_instruction(instruction, &display); run_instruction(instruction, &display);
} }
} else { } else {
println!("No input file specified, reading from stdin.");
let stdin = stdin(); let stdin = stdin();
loop { loop {
@ -45,8 +49,6 @@ fn main() {
} }
} }
display.close(); display.close();
} }
@ -106,18 +108,17 @@ fn run_instruction(instruction: &str, dpy: &XDisplay) {
command.arg(arg); command.arg(arg);
} }
if instruction_split[0] == "ExecBlock" { if instruction_split[0] == "ExecBlock" {
command.status(); command.status().unwrap();
} else { } else {
command.spawn(); command.spawn().unwrap();
} }
} }
c => { c => panic!("Unknown command {:?}", instruction_split),
panic!("Unknown command {:?}", instruction_split)
}
} }
} }
fn send_char(dpy: &XDisplay, c: char) { fn send_char(dpy: &XDisplay, c: char) {
// get keystring from character and turn it into a keysym
let keysym = string_to_keysym(CHARTBL[c as usize].as_ref()); let keysym = string_to_keysym(CHARTBL[c as usize].as_ref());
let keycode = dpy.keysym_to_keycode(keysym); let keycode = dpy.keysym_to_keycode(keysym);
@ -127,13 +128,14 @@ fn send_char(dpy: &XDisplay, c: char) {
} }
let map_ks = dpy.get_keyboard_mapping(keycode, 1); let map_ks = dpy.get_keyboard_mapping(keycode, 1);
if unsafe { map_ks[0] } == 0 { if map_ks[0] == 0 {
eprintln!("XGetKeyboardMapping failed (keycode: {})", keycode); eprintln!("XGetKeyboardMapping failed (keycode: {})", keycode);
return; return;
} }
let (ks_lower, ks_upper) = dpy.convert_case(keysym); let (ks_lower, ks_upper) = dpy.convert_case(keysym);
// check if shift has to be pressed as well
let mut shift_needed = true; let mut shift_needed = true;
if keysym == map_ks[0] && (keysym == ks_lower && keysym == ks_upper) { if keysym == map_ks[0] && (keysym == ks_lower && keysym == ks_upper) {
shift_needed = false; shift_needed = false;