espanso/src/keyboard/linux.rs

56 lines
1.6 KiB
Rust
Raw Normal View History

2019-09-15 16:29:11 +00:00
/*
* This file is part of espanso.
*
* Copyright (C) 2019 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::ffi::CString;
2019-09-07 11:35:45 +00:00
use crate::bridge::linux::*;
2019-09-13 13:03:03 +00:00
pub struct LinuxKeyboardManager {
}
2019-09-13 13:03:03 +00:00
impl super::KeyboardManager for LinuxKeyboardManager {
fn send_string(&self, s: &str) {
let res = CString::new(s);
match res {
Ok(cstr) => unsafe { send_string(cstr.as_ptr()); }
Err(e) => panic!(e.to_string())
}
}
2019-09-06 20:19:28 +00:00
fn send_enter(&self) {
// On linux this is not needed, so NOOP
}
fn trigger_paste(&self) {
2019-09-13 21:05:01 +00:00
unsafe {
let is_terminal = is_current_window_terminal();
2019-09-13 21:05:01 +00:00
// Terminals use a different keyboard combination to paste from clipboard,
// so we need to check the correct situation.
if is_terminal == 0 {
trigger_paste();
}else{
trigger_terminal_paste();
}
}
}
fn delete_string(&self, count: i32) {
unsafe {delete_string(count)}
}
}