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:
committed by
Henrik Friedrichsen
parent
3ab32a7c51
commit
02b66b6cdd
@@ -53,6 +53,7 @@ default-features = false
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
share_clipboard = ["clipboard"]
|
share_clipboard = ["clipboard"]
|
||||||
|
share_selection = ["clipboard"] # Use the primary selection for sharing - linux only
|
||||||
alsa_backend = ["librespot-playback/alsa-backend"]
|
alsa_backend = ["librespot-playback/alsa-backend"]
|
||||||
pulseaudio_backend = ["librespot-playback/pulseaudio-backend"]
|
pulseaudio_backend = ["librespot-playback/pulseaudio-backend"]
|
||||||
rodio_backend = ["librespot-playback/rodio-backend"]
|
rodio_backend = ["librespot-playback/rodio-backend"]
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ mod library;
|
|||||||
mod playable;
|
mod playable;
|
||||||
mod playlist;
|
mod playlist;
|
||||||
mod queue;
|
mod queue;
|
||||||
|
mod sharing;
|
||||||
mod show;
|
mod show;
|
||||||
mod spotify;
|
mod spotify;
|
||||||
mod theme;
|
mod theme;
|
||||||
|
|||||||
35
src/sharing.rs
Normal file
35
src/sharing.rs
Normal 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()
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ use crate::commands::CommandResult;
|
|||||||
use crate::library::Library;
|
use crate::library::Library;
|
||||||
use crate::playable::Playable;
|
use crate::playable::Playable;
|
||||||
use crate::queue::Queue;
|
use crate::queue::Queue;
|
||||||
|
#[cfg(feature = "share_clipboard")]
|
||||||
|
use crate::sharing::write_share;
|
||||||
use crate::track::Track;
|
use crate::track::Track;
|
||||||
use crate::traits::{ListItem, ViewExt};
|
use crate::traits::{ListItem, ViewExt};
|
||||||
use crate::ui::layout::Layout;
|
use crate::ui::layout::Layout;
|
||||||
@@ -17,8 +19,6 @@ use crate::{
|
|||||||
playlist::Playlist,
|
playlist::Playlist,
|
||||||
spotify::Spotify,
|
spotify::Spotify,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "share_clipboard")]
|
|
||||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
|
||||||
use cursive::traits::{Finder, Nameable};
|
use cursive::traits::{Finder, Nameable};
|
||||||
|
|
||||||
pub struct ContextMenu {
|
pub struct ContextMenu {
|
||||||
@@ -145,9 +145,7 @@ impl ContextMenu {
|
|||||||
}
|
}
|
||||||
ContextMenuAction::ShareUrl(url) => {
|
ContextMenuAction::ShareUrl(url) => {
|
||||||
#[cfg(feature = "share_clipboard")]
|
#[cfg(feature = "share_clipboard")]
|
||||||
ClipboardProvider::new()
|
write_share(url.to_string());
|
||||||
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url.to_string()))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
ContextMenuAction::AddToPlaylist(track) => {
|
ContextMenuAction::AddToPlaylist(track) => {
|
||||||
let dialog =
|
let dialog =
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ use crate::library::Library;
|
|||||||
use crate::playable::Playable;
|
use crate::playable::Playable;
|
||||||
use crate::playlist::Playlist;
|
use crate::playlist::Playlist;
|
||||||
use crate::queue::Queue;
|
use crate::queue::Queue;
|
||||||
|
#[cfg(feature = "share_clipboard")]
|
||||||
|
use crate::sharing::{read_share, write_share};
|
||||||
use crate::show::Show;
|
use crate::show::Show;
|
||||||
use crate::track::Track;
|
use crate::track::Track;
|
||||||
use crate::traits::{IntoBoxedViewExt, ListItem, ViewExt};
|
use crate::traits::{IntoBoxedViewExt, ListItem, ViewExt};
|
||||||
use crate::ui::album::AlbumView;
|
use crate::ui::album::AlbumView;
|
||||||
use crate::ui::artist::ArtistView;
|
use crate::ui::artist::ArtistView;
|
||||||
use crate::ui::contextmenu::ContextMenu;
|
use crate::ui::contextmenu::ContextMenu;
|
||||||
#[cfg(feature = "share_clipboard")]
|
|
||||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
pub type Paginator<I> = Box<dyn Fn(Arc<RwLock<Vec<I>>>) + Send + Sync>;
|
pub type Paginator<I> = Box<dyn Fn(Arc<RwLock<Vec<I>>>) + Send + Sync>;
|
||||||
@@ -497,9 +497,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
|||||||
|
|
||||||
if let Some(url) = url {
|
if let Some(url) = url {
|
||||||
#[cfg(feature = "share_clipboard")]
|
#[cfg(feature = "share_clipboard")]
|
||||||
ClipboardProvider::new()
|
write_share(url);
|
||||||
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(CommandResult::Consumed(None));
|
return Ok(CommandResult::Consumed(None));
|
||||||
@@ -620,10 +618,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
|||||||
Command::Insert(url) => {
|
Command::Insert(url) => {
|
||||||
let url = match url.as_ref().map(String::as_str) {
|
let url = match url.as_ref().map(String::as_str) {
|
||||||
#[cfg(feature = "share_clipboard")]
|
#[cfg(feature = "share_clipboard")]
|
||||||
Some("") | None => ClipboardProvider::new()
|
Some("") | None => read_share().unwrap(),
|
||||||
.and_then(|mut ctx: ClipboardContext| ctx.get_contents())
|
|
||||||
.ok()
|
|
||||||
.unwrap(),
|
|
||||||
Some(url) => url.to_owned(),
|
Some(url) => url.to_owned(),
|
||||||
// do nothing if clipboard feature is disabled and there is no url provided
|
// do nothing if clipboard feature is disabled and there is no url provided
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
|
|||||||
Reference in New Issue
Block a user