Skip to content

Commit

Permalink
Merge pull request #5 from capitar/linux-changes
Browse files Browse the repository at this point in the history
Linux changes
  • Loading branch information
adamierymenko authored Nov 3, 2021
2 parents c23932c + aaf1ccf commit e5338f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
9 changes: 9 additions & 0 deletions src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit e5338f6

Please sign in to comment.