diff --git a/src/config/mod.rs b/src/config/mod.rs index 78326e3..64463d4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -26,6 +26,7 @@ use std::fs::{File, create_dir_all}; use std::io::Read; use serde::{Serialize, Deserialize}; use crate::event::KeyModifier; +use crate::keyboard::PasteShortcut; use std::collections::{HashSet, HashMap}; use log::{error}; use std::fmt; @@ -97,6 +98,9 @@ pub struct Configs { #[serde(default = "default_toggle_interval")] pub toggle_interval: u32, + #[serde(default)] + pub paste_shortcut: PasteShortcut, + #[serde(default = "default_backspace_limit")] pub backspace_limit: i32, diff --git a/src/engine.rs b/src/engine.rs index 19f96f8..79f5e3d 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -206,7 +206,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa }, BackendType::Clipboard => { self.clipboard_manager.set_clipboard(&target_string); - self.keyboard_manager.trigger_paste(); + self.keyboard_manager.trigger_paste(&config.paste_shortcut); }, } @@ -221,7 +221,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa // Make sure the image exist beforehand if content.path.exists() { self.clipboard_manager.set_clipboard_image(&content.path); - self.keyboard_manager.trigger_paste(); + self.keyboard_manager.trigger_paste(&config.paste_shortcut); }else{ error!("Image not found in path: {:?}", content.path); } diff --git a/src/keyboard/linux.rs b/src/keyboard/linux.rs index 7b30028..1476316 100644 --- a/src/keyboard/linux.rs +++ b/src/keyboard/linux.rs @@ -19,6 +19,8 @@ use std::ffi::CString; use crate::bridge::linux::*; +use super::PasteShortcut; +use log::error; pub struct LinuxKeyboardManager { } @@ -36,16 +38,29 @@ impl super::KeyboardManager for LinuxKeyboardManager { // On linux this is not needed, so NOOP } - fn trigger_paste(&self) { + fn trigger_paste(&self, shortcut: &PasteShortcut) { unsafe { - let is_terminal = is_current_window_terminal(); + match shortcut { + PasteShortcut::Default => { + let is_terminal = is_current_window_terminal(); - // 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(); + // 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(); + } + }, + PasteShortcut::CtrlV => { + trigger_paste(); + }, + PasteShortcut::CtrlShiftV => { + trigger_terminal_paste(); + } + _ => { + error!("Linux backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.") + } } } } diff --git a/src/keyboard/macos.rs b/src/keyboard/macos.rs index 724845a..6cba0da 100644 --- a/src/keyboard/macos.rs +++ b/src/keyboard/macos.rs @@ -19,6 +19,8 @@ use std::ffi::CString; use crate::bridge::macos::*; +use super::PasteShortcut; +use log::error; pub struct MacKeyboardManager { } @@ -39,9 +41,18 @@ impl super::KeyboardManager for MacKeyboardManager { } } - fn trigger_paste(&self) { + fn trigger_paste(&self, shortcut: &PasteShortcut) { unsafe { - trigger_paste(); + match shortcut { + PasteShortcut::Default => { + unsafe { + trigger_paste(); + } + }, + _ => { + error!("MacOS backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.") + } + } } } diff --git a/src/keyboard/mod.rs b/src/keyboard/mod.rs index 5a9cc5b..d8f2611 100644 --- a/src/keyboard/mod.rs +++ b/src/keyboard/mod.rs @@ -17,6 +17,8 @@ * along with espanso. If not, see . */ +use serde::{Serialize, Deserialize, Deserializer}; + #[cfg(target_os = "windows")] mod windows; @@ -29,11 +31,26 @@ mod macos; pub trait KeyboardManager { fn send_string(&self, s: &str); fn send_enter(&self); - fn trigger_paste(&self); + fn trigger_paste(&self, shortcut: &PasteShortcut); fn delete_string(&self, count: i32); fn move_cursor_left(&self, count: i32); } +#[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 + } +} + // WINDOWS IMPLEMENTATION #[cfg(target_os = "windows")] pub fn get_manager() -> impl KeyboardManager { diff --git a/src/keyboard/windows.rs b/src/keyboard/windows.rs index 8193006..c4e110b 100644 --- a/src/keyboard/windows.rs +++ b/src/keyboard/windows.rs @@ -19,6 +19,8 @@ use widestring::{U16CString}; use crate::bridge::windows::*; +use super::PasteShortcut; +use log::error; pub struct WindowsKeyboardManager { } @@ -44,9 +46,18 @@ impl super::KeyboardManager for WindowsKeyboardManager { } } - fn trigger_paste(&self) { + fn trigger_paste(&self, shortcut: &PasteShortcut) { unsafe { - trigger_paste(); + match shortcut { + PasteShortcut::Default => { + unsafe { + trigger_paste(); + } + }, + _ => { + error!("Windows backend does not support this Paste Shortcut, please open an issue on GitHub if you need it.") + } + } } }