fix: win, clipboard image (#8561)

The window must belong to the current thread for clipboard-master.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessage#:~:text=The%20window%20must%20belong%20to%20the%20current%20thread.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-07-02 00:46:55 +08:00 committed by GitHub
parent a0dc38f749
commit 51db8e706d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -213,7 +213,6 @@ impl ClipboardData {
ClipboardData::Empty => true,
ClipboardData::Text(s) => s.is_empty(),
ClipboardData::Image(a, _) => a.bytes.is_empty(),
_ => false,
}
}
@ -347,22 +346,25 @@ impl ClipboardContext {
CallbackResult::Next
}
}
match Master::new(Handler(change_count.clone())) {
Ok(master) => {
let mut master = master;
shutdown = Some(master.shutdown_channel());
std::thread::spawn(move || {
let change_count_cloned = change_count.clone();
let (tx, rx) = std::sync::mpsc::channel();
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessage#:~:text=The%20window%20must%20belong%20to%20the%20current%20thread.
std::thread::spawn(move || match Master::new(Handler(change_count_cloned)) {
Ok(mut master) => {
tx.send(master.shutdown_channel()).ok();
log::debug!("Clipboard listener started");
if let Err(err) = master.run() {
log::error!("Failed to run clipboard listener: {}", err);
} else {
log::debug!("Clipboard listener stopped");
}
});
}
Err(err) => {
log::error!("Failed to create clipboard listener: {}", err);
}
});
if let Ok(st) = rx.recv() {
shutdown = Some(st);
}
}
Ok(ClipboardContext(board, (change_count, 0), shutdown))