From d625c422e7172b8ca0ddea519adb8e60c1d67baa Mon Sep 17 00:00:00 2001 From: Uzair Aftab <48220549+Uzaaft@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:59:54 +0200 Subject: [PATCH] [Fix] Use SetExtLinux trait on linux platform (#79) --- generator/src/copy.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/generator/src/copy.rs b/generator/src/copy.rs index 132a50b..6f5a388 100644 --- a/generator/src/copy.rs +++ b/generator/src/copy.rs @@ -1,4 +1,6 @@ use crate::{config::TakeSnapshotParams, snapshot::take_snapshot}; +#[cfg(target_os = "linux")] +use arboard::SetExtLinux; use arboard::{Clipboard, ImageData}; use nvim_oxi::Result; @@ -18,14 +20,25 @@ pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<()> { }) .flatten() .collect::>(); - let mut ctx = Clipboard::new().unwrap(); let img_data = ImageData { width: pixmap.width() as usize, height: pixmap.height() as usize, bytes: colors.into(), }; - ctx.set_image(img_data).unwrap(); + + #[cfg(target_os = "linux")] + std::thread::spawn(move || { + Clipboard::new() + .unwrap() + .set() + .wait() + .image(img_data) + .unwrap(); + }); + + #[cfg(not(target_os = "linux"))] + Clipboard::new().unwrap().set_image(img_data).unwrap(); Ok(()) }