Allow primary selection for sharing

Adds a feature flag to use the primary selection instead of the
clipboard. Only works on Linux.
This commit is contained in:
Felix Van der Jeugt
2020-12-14 23:42:56 +01:00
committed by Henrik Friedrichsen
parent 3ab32a7c51
commit 02b66b6cdd
5 changed files with 44 additions and 14 deletions

35
src/sharing.rs Normal file
View File

@@ -0,0 +1,35 @@
#![cfg(feature = "share_clipboard")]
#[cfg(not(feature = "share_selection"))]
use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;
#[cfg(feature = "share_selection")]
use clipboard::x11_clipboard::{X11ClipboardContext, Primary};
#[cfg(not(feature = "share_selection"))]
pub fn read_share() -> Option<String> {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.get_contents())
.ok()
}
#[cfg(feature = "share_selection")]
pub fn read_share() -> Option<String> {
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<Primary>| ctx.get_contents())
.ok()
}
#[cfg(not(feature = "share_selection"))]
pub fn write_share(url: String) -> Option<()> {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.ok()
}
#[cfg(feature = "share_selection")]
pub fn write_share(url: String) -> Option<()> {
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<Primary>| ctx.set_contents(url))
.ok()
}