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/>.
|
|
|
|
*/
|
|
|
|
|
2019-11-29 21:09:02 +00:00
|
|
|
use serde::{Serialize, Deserialize, Deserializer};
|
|
|
|
|
2019-08-30 17:45:27 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
mod windows;
|
|
|
|
|
2019-09-01 12:58:39 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
mod linux;
|
|
|
|
|
2019-09-05 15:20:52 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
mod macos;
|
|
|
|
|
2019-09-13 13:03:03 +00:00
|
|
|
pub trait KeyboardManager {
|
2019-09-06 14:06:41 +00:00
|
|
|
fn send_string(&self, s: &str);
|
|
|
|
fn send_enter(&self);
|
2019-11-29 21:09:02 +00:00
|
|
|
fn trigger_paste(&self, shortcut: &PasteShortcut);
|
2019-09-06 14:06:41 +00:00
|
|
|
fn delete_string(&self, count: i32);
|
2019-10-22 21:03:58 +00:00
|
|
|
fn move_cursor_left(&self, count: i32);
|
2019-09-06 14:06:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 21:09:02 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub enum PasteShortcut {
|
|
|
|
Default, // Default one for the current system
|
|
|
|
CtrlV, // Classic Ctrl+V shortcut
|
|
|
|
CtrlShiftV, // Could be used to paste without formatting in many applications
|
|
|
|
ShiftInsert, // Often used in Linux systems
|
|
|
|
MetaV, // Corresponding to Win+V on Windows and Linux, CMD+V on macOS
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PasteShortcut{
|
|
|
|
fn default() -> Self {
|
|
|
|
PasteShortcut::Default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 20:14:41 +00:00
|
|
|
// WINDOWS IMPLEMENTATION
|
2019-08-31 14:07:45 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2019-09-13 13:03:03 +00:00
|
|
|
pub fn get_manager() -> impl KeyboardManager {
|
|
|
|
windows::WindowsKeyboardManager{}
|
2019-09-01 12:58:39 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 20:14:41 +00:00
|
|
|
// LINUX IMPLEMENTATION
|
2019-09-01 12:58:39 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2019-09-13 13:03:03 +00:00
|
|
|
pub fn get_manager() -> impl KeyboardManager {
|
|
|
|
linux::LinuxKeyboardManager{}
|
2019-09-05 15:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MAC IMPLEMENTATION
|
|
|
|
#[cfg(target_os = "macos")]
|
2019-09-13 13:03:03 +00:00
|
|
|
pub fn get_manager() -> impl KeyboardManager {
|
|
|
|
macos::MacKeyboardManager{}
|
2019-08-30 17:45:27 +00:00
|
|
|
}
|