Add option to delay injected text on Linux. See #248

This commit is contained in:
Federico Terzi 2020-05-05 21:20:54 +02:00
parent eae013d16f
commit 23939a59b3
6 changed files with 15 additions and 7 deletions

View File

@ -325,7 +325,7 @@ void fast_release_all_keys() {
XFlush(xdo_context->xdpy); XFlush(xdo_context->xdpy);
} }
void fast_send_string(const char * string) { void fast_send_string(const char * string, int32_t delay) {
// It may happen that when an expansion is triggered, some keys are still pressed. // It may happen that when an expansion is triggered, some keys are still pressed.
// This causes a problem if the expanded match contains that character, as the injection // This causes a problem if the expanded match contains that character, as the injection
// will not be able to register that keypress (as it is already pressed). // will not be able to register that keypress (as it is already pressed).
@ -337,7 +337,12 @@ void fast_send_string(const char * string) {
int revert_to; int revert_to;
XGetInputFocus(xdo_context->xdpy, &focused, &revert_to); XGetInputFocus(xdo_context->xdpy, &focused, &revert_to);
fast_enter_text_window(xdo_context, focused, string, 1); int actual_delay = 1;
if delay > 0 {
actual_delay = delay * 1000;
}
fast_enter_text_window(xdo_context, focused, string, actual_delay);
} }
void _fast_send_keycode_to_focused_window(int KeyCode, int32_t count, int32_t delay) { void _fast_send_keycode_to_focused_window(int KeyCode, int32_t count, int32_t delay) {

View File

@ -65,7 +65,7 @@ extern "C" void send_string(const char * string);
/* /*
* Type the given string by simulating Key Presses using a faster inject method * Type the given string by simulating Key Presses using a faster inject method
*/ */
extern "C" void fast_send_string(const char * string); extern "C" void fast_send_string(const char * string, int32_t delay);
/* /*
* Send the backspace keypress, *count* times. * Send the backspace keypress, *count* times.

View File

@ -215,8 +215,7 @@ int fast_enter_text_window(const xdo_t *xdo, Window window, const char *string,
key.needs_binding = 0; key.needs_binding = 0;
fast_send_keysequence_window_list_do(xdo, window, &key, 1, False, NULL, delay / 2); fast_send_keysequence_window_list_do(xdo, window, &key, 1, False, NULL, delay / 2);
/* XXX: Flush here or at the end? or never? */ XFlush(xdo->xdpy);
//XFlush(xdo->xdpy);
} /* walk string generating a keysequence */ } /* walk string generating a keysequence */
//free(keys); //free(keys);

View File

@ -48,7 +48,7 @@ extern {
pub fn trigger_ctrl_alt_paste(); pub fn trigger_ctrl_alt_paste();
pub fn trigger_copy(); pub fn trigger_copy();
pub fn fast_send_string(string: *const c_char); pub fn fast_send_string(string: *const c_char, delay: i32);
pub fn fast_delete_string(count: i32, delay: i32); pub fn fast_delete_string(count: i32, delay: i32);
pub fn fast_left_arrow(count: i32); pub fn fast_left_arrow(count: i32);
pub fn fast_send_enter(); pub fn fast_send_enter();

View File

@ -63,6 +63,7 @@ fn default_enable_passive() -> bool { false }
fn default_enable_active() -> bool { true } fn default_enable_active() -> bool { true }
fn default_backspace_limit() -> i32 { 3 } fn default_backspace_limit() -> i32 { 3 }
fn default_backspace_delay() -> i32 { 0 } fn default_backspace_delay() -> i32 { 0 }
fn default_inject_delay() -> i32 { 0 }
fn default_restore_clipboard_delay() -> i32 { 300 } fn default_restore_clipboard_delay() -> i32 { 300 }
fn default_exclude_default_entries() -> bool {false} fn default_exclude_default_entries() -> bool {false}
fn default_secure_input_watcher_enabled() -> bool {true} fn default_secure_input_watcher_enabled() -> bool {true}
@ -172,6 +173,9 @@ pub struct Configs {
#[serde(default = "default_backspace_delay")] #[serde(default = "default_backspace_delay")]
pub backspace_delay: i32, pub backspace_delay: i32,
#[serde(default = "default_inject_delay")]
pub inject_delay: i32,
#[serde(default = "default_matches")] #[serde(default = "default_matches")]
pub matches: Vec<Match>, pub matches: Vec<Match>,

View File

@ -32,7 +32,7 @@ impl super::KeyboardManager for LinuxKeyboardManager {
match res { match res {
Ok(cstr) => unsafe { Ok(cstr) => unsafe {
if active_config.fast_inject { if active_config.fast_inject {
fast_send_string(cstr.as_ptr()); fast_send_string(cstr.as_ptr(), active_config.inject_delay);
}else{ }else{
send_string(cstr.as_ptr()); send_string(cstr.as_ptr());
} }