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