formatted with cargo, cleaned up imports and dependencies.

This commit is contained in:
Schrottkatze 2022-06-15 14:06:27 +02:00
parent 5dc96d6da4
commit b651009949
5 changed files with 117 additions and 104 deletions

View file

@ -1,26 +1,18 @@
use std::ffi::{CStr, CString};
use std::os::raw::{c_char, c_int, c_uint};
use std::process::exit;
use std::slice::from_raw_parts;
use std::{fs, thread};
use std::time::Duration;
use x11::xlib::{Display, XCloseDisplay, XDisplayString, XFlush, XKeysymToKeycode, XOpenDisplay, XStringToKeysym, XSync};
use clap::Parser;
use x11::keysym::{XK_d, XK_Super_L};
use x11::xtest::{XTestFakeButtonEvent, XTestFakeKeyEvent, XTestFakeMotionEvent, XTestGrabControl, XTestQueryExtension};
use x11_keysymdef::lookup_by_name;
use easymacros::x11_safe_wrapper::{Keysym, XDisplay};
use std::ffi::CString;
use std::process::exit;
use std::time::Duration;
use std::{fs, thread};
/// Macro program inspired by xmacro.
/// Macro player module for easymacros. It's partially compatible with xmacro macros, with aim for full compatibility.
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// Input file
/// The file that contains the macro to run.
#[clap(value_parser, value_name = "input_file", value_hint = clap::ValueHint::FilePath)]
input_file: std::path::PathBuf,
/// Display
/// Display to run the macro on. This uses the $DISPLAY environment variable by default.
#[clap(short, long)]
display: Option<String>,
// xmacro compatibility, currently the only supported input format anyway
@ -28,11 +20,12 @@ struct Args {
// xmacro: bool,
}
fn main () {
fn main() {
let args = Args::parse();
// let xmacro_mode = args.xmacro;
let input_file_contents = fs::read_to_string(args.input_file).expect("couldn't read macro file");
let input_file_contents =
fs::read_to_string(args.input_file).expect("couldn't read macro file");
let display = get_remote(args.display);
for instruction in input_file_contents.lines() {
@ -43,23 +36,29 @@ fn main () {
"Delay" => thread::sleep(Duration::from_millis(command[1].parse().unwrap())),
"ButtonPress" => display.send_fake_buttonpress(command[1].parse().unwrap()),
"ButtonRelease" => display.send_fake_buttonrelease(command[1].parse().unwrap()),
"MotionNotify" => display.send_fake_motion_event(command[1].parse().unwrap(), command[2].parse().unwrap()),
"MotionNotify" => display
.send_fake_motion_event(command[1].parse().unwrap(), command[2].parse().unwrap()),
"KeyCodePress" => display.send_fake_keypress_from_code(command[1].parse().unwrap()),
"KeyCodeRelease" => display.send_fake_keyrelease_from_code(command[1].parse().unwrap()),
"KeySymPress" => display.send_fake_keypress_from_keysym(command[1].parse().unwrap()),
"KeySymRelease" => display.send_fake_keyrelease_from_keysym(command[1].parse().unwrap()),
"KeySymRelease" => {
display.send_fake_keyrelease_from_keysym(command[1].parse().unwrap())
}
"KeySym" => {
let key: Keysym = command[1].parse().unwrap();
display.send_fake_keypress_from_keysym(key);
display.send_fake_keyrelease_from_keysym(key);
},
"KeyStrPress" => display.send_fake_keypress_from_string(CString::new(command[1]).unwrap().as_bytes()),
"KeyStrRelease" => display.send_fake_keyrelease_from_string(CString::new(command[1]).unwrap().as_bytes()),
}
"KeyStrPress" => {
display.send_fake_keypress_from_string(CString::new(command[1]).unwrap().as_bytes())
}
"KeyStrRelease" => display
.send_fake_keyrelease_from_string(CString::new(command[1]).unwrap().as_bytes()),
"KeyStr" => {
let keystring = CString::new(command[1]).unwrap();
display.send_fake_keypress_from_string(keystring.as_bytes());
display.send_fake_keyrelease_from_string(keystring.as_bytes());
},
}
"String" => {
println!("Strings are currently not supported.");
// for c in instruction[7..].chars() {
@ -67,7 +66,9 @@ fn main () {
// display.send_fake_keyrelease_from_string(CString::new(c.to_string()).unwrap().as_bytes());
// }
}
c => {panic!("Unknown command {}", c)}
c => {
panic!("Unknown command {}", c)
}
}
}

View file

@ -1,5 +1,3 @@
use easymacros::add;
fn main() {
println!("rec: {}", add(2, 2));
}
todo!();
}