Merge pull request #427 from federico-terzi/dev
Fix clipboard bug on Windows. Fix #418
This commit is contained in:
commit
fc4b375a3c
|
@ -791,6 +791,7 @@ int32_t start_process(wchar_t * _cmd) {
|
||||||
// CLIPBOARD
|
// CLIPBOARD
|
||||||
|
|
||||||
int32_t set_clipboard(wchar_t *text) {
|
int32_t set_clipboard(wchar_t *text) {
|
||||||
|
int32_t result = 0;
|
||||||
const size_t len = wcslen(text) + 1;
|
const size_t len = wcslen(text) + 1;
|
||||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(wchar_t));
|
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(wchar_t));
|
||||||
memcpy(GlobalLock(hMem), text, len * sizeof(wchar_t));
|
memcpy(GlobalLock(hMem), text, len * sizeof(wchar_t));
|
||||||
|
@ -800,12 +801,14 @@ int32_t set_clipboard(wchar_t *text) {
|
||||||
}
|
}
|
||||||
EmptyClipboard();
|
EmptyClipboard();
|
||||||
if (!SetClipboardData(CF_UNICODETEXT, hMem)) {
|
if (!SetClipboardData(CF_UNICODETEXT, hMem)) {
|
||||||
return -2;
|
result = -2;
|
||||||
}
|
}
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t get_clipboard(wchar_t *buffer, int32_t size) {
|
int32_t get_clipboard(wchar_t *buffer, int32_t size) {
|
||||||
|
int32_t result = 0;
|
||||||
if (!OpenClipboard(NULL)) {
|
if (!OpenClipboard(NULL)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -813,19 +816,19 @@ int32_t get_clipboard(wchar_t *buffer, int32_t size) {
|
||||||
// Get handle of clipboard object for ANSI text
|
// Get handle of clipboard object for ANSI text
|
||||||
HANDLE hData = GetClipboardData(CF_UNICODETEXT);
|
HANDLE hData = GetClipboardData(CF_UNICODETEXT);
|
||||||
if (!hData) {
|
if (!hData) {
|
||||||
return -2;
|
result = -2;
|
||||||
|
}else{
|
||||||
|
HGLOBAL hMem = GlobalLock(hData);
|
||||||
|
if (!hMem) {
|
||||||
|
result = -3;
|
||||||
|
}else{
|
||||||
|
GlobalUnlock(hMem);
|
||||||
|
swprintf(buffer, size, L"%s", hMem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HGLOBAL hMem = GlobalLock(hData);
|
|
||||||
if (!hMem) {
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
GlobalUnlock(hMem);
|
|
||||||
|
|
||||||
swprintf(buffer, size, L"%s", hMem);
|
|
||||||
|
|
||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t set_clipboard_image(wchar_t *path) {
|
int32_t set_clipboard_image(wchar_t *path) {
|
||||||
|
|
|
@ -155,7 +155,7 @@ fn default_global_vars() -> Vec<MatchVariable> {
|
||||||
fn default_modulo_path() -> Option<String> {
|
fn default_modulo_path() -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn default_mac_post_inject_delay() -> u64 {
|
fn default_post_inject_delay() -> u64 {
|
||||||
100
|
100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,8 +245,8 @@ pub struct Configs {
|
||||||
#[serde(default = "default_secure_input_watcher_interval")]
|
#[serde(default = "default_secure_input_watcher_interval")]
|
||||||
pub secure_input_watcher_interval: i32,
|
pub secure_input_watcher_interval: i32,
|
||||||
|
|
||||||
#[serde(default = "default_mac_post_inject_delay")]
|
#[serde(default = "default_post_inject_delay")]
|
||||||
pub mac_post_inject_delay: u64,
|
pub post_inject_delay: u64,
|
||||||
|
|
||||||
#[serde(default = "default_secure_input_notification")]
|
#[serde(default = "default_secure_input_notification")]
|
||||||
pub secure_input_notification: bool,
|
pub secure_input_notification: bool,
|
||||||
|
|
14
src/guard.rs
14
src/guard.rs
|
@ -5,7 +5,7 @@ use std::sync::{atomic::AtomicBool, Arc};
|
||||||
|
|
||||||
pub struct InjectGuard {
|
pub struct InjectGuard {
|
||||||
is_injecting: Arc<AtomicBool>,
|
is_injecting: Arc<AtomicBool>,
|
||||||
mac_post_inject_delay: u64,
|
post_inject_delay: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InjectGuard {
|
impl InjectGuard {
|
||||||
|
@ -17,21 +17,19 @@ impl InjectGuard {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
is_injecting,
|
is_injecting,
|
||||||
mac_post_inject_delay: config.mac_post_inject_delay,
|
post_inject_delay: config.post_inject_delay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for InjectGuard {
|
impl Drop for InjectGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
debug!("releasing inject guard");
|
// Because the keyinjection is async, we need to wait a bit before
|
||||||
|
|
||||||
// On macOS, because the keyinjection is async, we need to wait a bit before
|
|
||||||
// giving back the control. Otherwise, the injected actions will be handled back
|
// giving back the control. Otherwise, the injected actions will be handled back
|
||||||
// by espanso itself.
|
// by espanso itself.
|
||||||
if cfg!(target_os = "macos") {
|
std::thread::sleep(std::time::Duration::from_millis(self.post_inject_delay));
|
||||||
std::thread::sleep(std::time::Duration::from_millis(self.mac_post_inject_delay));
|
|
||||||
}
|
debug!("releasing inject guard");
|
||||||
|
|
||||||
// Re-allow espanso to interpret actions
|
// Re-allow espanso to interpret actions
|
||||||
self.is_injecting.store(false, Release);
|
self.is_injecting.store(false, Release);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user