Change way Inject backend handles multiline matches on Linux

This commit is contained in:
Federico Terzi 2020-03-08 19:10:26 +01:00
parent 23095d4394
commit 33cfb156db
5 changed files with 20 additions and 15 deletions

View File

@ -295,6 +295,10 @@ void send_string(const char * string) {
xdo_enter_text_window(xdo_context, CURRENTWINDOW, string, 1000);
}
void send_enter() {
xdo_send_keysequence_window(xdo_context, CURRENTWINDOW, "Return", 1000);
}
void delete_string(int32_t count) {
for (int i = 0; i<count; i++) {
xdo_send_keysequence_window(xdo_context, CURRENTWINDOW, "BackSpace", 1000);

View File

@ -67,6 +67,11 @@ extern "C" void send_string(const char * string);
*/
extern "C" void delete_string(int32_t count);
/*
* Send an Enter key press
*/
extern "C" void send_enter();
/*
* Send the left arrow keypress, *count* times.
*/

View File

@ -40,6 +40,7 @@ extern {
pub fn send_string(string: *const c_char);
pub fn delete_string(count: i32);
pub fn left_arrow(count: i32);
pub fn send_enter();
pub fn trigger_paste();
pub fn trigger_terminal_paste();
pub fn trigger_shift_ins_paste();

View File

@ -209,22 +209,15 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa
match backend {
BackendType::Inject => {
// Send the expected string. On linux, newlines are managed automatically
// while on windows and macos, we need to emulate a Enter key press.
// To handle newlines, substitute each "\n" char with an Enter key press.
let splits = target_string.split('\n');
if cfg!(target_os = "linux") {
self.keyboard_manager.send_string(&target_string);
}else{
// To handle newlines, substitute each "\n" char with an Enter key press.
let splits = target_string.split('\n');
for (i, split) in splits.enumerate() {
if i > 0 {
self.keyboard_manager.send_enter();
}
self.keyboard_manager.send_string(split);
for (i, split) in splits.enumerate() {
if i > 0 {
self.keyboard_manager.send_enter();
}
self.keyboard_manager.send_string(split);
}
},
BackendType::Clipboard => {

View File

@ -35,7 +35,9 @@ impl super::KeyboardManager for LinuxKeyboardManager {
}
fn send_enter(&self) {
// On linux this is not needed, so NOOP
unsafe {
send_enter();
}
}
fn trigger_paste(&self, shortcut: &PasteShortcut) {