[Fix] Use SetExtLinux trait on linux platform (#79)

pull/86/head
Uzair Aftab 2024-04-08 14:59:54 +02:00 committed by GitHub
parent 0217f58e7c
commit d625c422e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,6 @@
use crate::{config::TakeSnapshotParams, snapshot::take_snapshot}; use crate::{config::TakeSnapshotParams, snapshot::take_snapshot};
#[cfg(target_os = "linux")]
use arboard::SetExtLinux;
use arboard::{Clipboard, ImageData}; use arboard::{Clipboard, ImageData};
use nvim_oxi::Result; use nvim_oxi::Result;
@ -18,14 +20,25 @@ pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<()> {
}) })
.flatten() .flatten()
.collect::<Vec<u8>>(); .collect::<Vec<u8>>();
let mut ctx = Clipboard::new().unwrap();
let img_data = ImageData { let img_data = ImageData {
width: pixmap.width() as usize, width: pixmap.width() as usize,
height: pixmap.height() as usize, height: pixmap.height() as usize,
bytes: colors.into(), 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(()) Ok(())
} }