From f884ade3ffed30a274bad19e9c3e8ad415b06e2f Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 29 Nov 2019 21:38:29 +0100 Subject: [PATCH] Add image clipboard backend on Linux --- src/clipboard/linux.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/clipboard/linux.rs b/src/clipboard/linux.rs index 7e14a07..8fb76e1 100644 --- a/src/clipboard/linux.rs +++ b/src/clipboard/linux.rs @@ -19,7 +19,8 @@ use std::process::{Command, Stdio}; use std::io::{Write}; -use log::error; +use log::{error, warn}; +use std::path::Path; pub struct LinuxClipboardManager {} @@ -63,6 +64,29 @@ impl super::ClipboardManager for LinuxClipboardManager { } } } + + fn set_clipboard_image(&self, image_path: &Path) { + let extension = image_path.extension(); + let mime = match extension { + Some(ext) => { + let ext = ext.to_string_lossy().to_lowercase(); + match ext.as_ref() { + "png" => {"image/png"}, + "jpg" | "jpeg" => {"image/jpeg"}, + "gif" => {"image/gif"}, + "svg" => {"image/svg"}, + _ => {"image/png"}, + } + }, + None => {"image/png"}, + }; + + let image_path = image_path.to_string_lossy().into_owned(); + + let res = Command::new("xclip") + .args(&["-selection", "clipboard", "-t", mime, "-i", &image_path]) + .spawn(); + } } impl LinuxClipboardManager {