Skip to content

Commit

Permalink
[Fix] Use SetExtLinux trait on linux platform (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzaaft authored Apr 8, 2024
1 parent 0217f58 commit d625c42
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions generator/src/copy.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,14 +20,25 @@ pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<()> {
})
.flatten()
.collect::<Vec<u8>>();
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(())
}

0 comments on commit d625c42

Please sign in to comment.