From b013f154337ff6606bd86b86726f934004c21b24 Mon Sep 17 00:00:00 2001 From: Janjaap Bos Date: Tue, 2 Nov 2021 13:19:07 +0000 Subject: [PATCH] Linux support For clipboard usage: apt install xclip --- src/main.rs | 16 ++++++++++++++++ src/tray.rs | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main.rs b/src/main.rs index 3d118ae2..71a2311c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,6 +214,22 @@ fn tray_icon_name() -> String { /*******************************************************************************************************************/ /* Clipboard functions for different OSes */ +#[cfg(target_os = "linux")] +fn copy_to_clipboard(s: &str) { + let _ = Command::new("/usr/bin/xclip").stdin(Stdio::piped()).stdout(Stdio::inherit()).stderr(Stdio::inherit()).spawn().map(|mut c| { + c.stdin.take().map(|mut stdin| { + let _ = stdin.write_all(s.as_bytes()); + }); + let _ = c.wait(); + }); +} + +#[cfg(target_os = "linux")] +fn read_from_clipboard() -> String { + Command::new("/usr/bin/xclip").output().map_or_else(|_| String::new(), |out| String::from_utf8(out.stdout).map_or_else(|_| String::new(), |s| s)) +} + +#[cfg(windows)] #[cfg(target_os = "macos")] fn copy_to_clipboard(s: &str) { let _ = Command::new("/usr/bin/pbcopy").stdin(Stdio::piped()).stdout(Stdio::inherit()).stderr(Stdio::inherit()).spawn().map(|mut c| { diff --git a/src/tray.rs b/src/tray.rs index 246da975..bad418c6 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -76,6 +76,15 @@ pub struct Tray { tray_initialized: bool, } +#[cfg(target_os = "linux")] +extern "C" { + fn tray_init(tray: *const CTray) -> c_int; + fn tray_loop(blocking: c_int) -> c_int; + fn tray_update(tray: *const CTray); + fn tray_exit(); +} + + #[cfg(target_os = "macos")] #[link(name = "Cocoa", kind = "framework")] extern "C" {