Compare commits

..

No commits in common. "yoda-x11-optional" and "master" have entirely different histories.

25 changed files with 123 additions and 1419 deletions

View file

@ -11,21 +11,9 @@ readme = "README.md"
keywords = ["clipboard", "window", "ui", "gui", "raw-window-handle"]
categories = ["gui"]
[features]
# Yoda: put the unix clipboard backends behind opt-in features. Upstream
# pulled both X11 + Wayland unconditionally on unix — pure bloat for
# Wayland-only builds (clipboard_x11 pulls x11rb + its protocol machinery).
# Default keeps both enabled to preserve upstream behaviour; yoda consumers
# pass default-features=false + "wayland" at the dep declaration.
default = ["x11", "wayland"]
x11 = ["dep:clipboard_x11"]
wayland = ["dep:clipboard_wayland"]
[dependencies]
raw-window-handle = { version = "0.6", features = ["std"] }
thiserror = "1.0"
mime = { path = "./mime" }
dnd = { path = "./dnd" }
[target.'cfg(windows)'.dependencies]
clipboard-win = { version = "5.0", features = ["std"] }
@ -34,12 +22,16 @@ clipboard-win = { version = "5.0", features = ["std"] }
clipboard_macos = { version = "0.1", path = "./macos" }
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten", target_os="ios", target_os="redox"))))'.dependencies]
clipboard_x11 = { version = "0.4.2", path = "./x11", optional = true }
clipboard_wayland = { version = "0.2.2", path = "./wayland", optional = true }
clipboard_x11 = { version = "0.4.2", path = "./x11" }
clipboard_wayland = { version = "0.2.2", path = "./wayland" }
[dev-dependencies]
rand = "0.8"
winit = "0.29"
[workspace]
members = ["dnd", "macos", "mime", "dnd", "wayland", "x11"]
members = [
"macos",
"wayland",
"x11",
]

View file

@ -1,17 +0,0 @@
[package]
name = "dnd"
version = "0.1.0"
edition = "2021"
[dependencies]
mime = { path = "../mime" }
bitflags = "2.5.0"
raw-window-handle = "0.6"
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten", target_os="ios", target_os="redox"))))'.dependencies]
smithay-clipboard = { path = "../../smithay-clipboard", features = [
"dnd",
] }
sctk = { package = "smithay-client-toolkit", version = "0.20", default-features = false, features = [
"calloop",
] }

View file

@ -1,201 +0,0 @@
use std::{
borrow::Cow,
fmt::Debug,
sync::{mpsc::SendError, Arc},
};
use bitflags::bitflags;
use raw_window_handle::HasWindowHandle;
#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten",
target_os = "redox"
))
))]
#[path = "platform/linux.rs"]
pub mod platform;
bitflags! {
// Attributes can be applied to flags types
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DndAction: u32 {
const Copy = 0b00000001;
const Move = 0b00000010;
const Ask = 0b00000100;
}
}
#[derive(Debug, Clone)]
pub enum DndEvent<T> {
/// Dnd Offer event with the corresponding destination rectangle ID.
Offer(Option<u128>, OfferEvent<T>),
/// Dnd Source event.
Source(SourceEvent),
}
impl<T> PartialEq for DndEvent<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(DndEvent::Offer(a, b), DndEvent::Offer(a2, b2)) => {
a == a2 && b == b2
}
(DndEvent::Source(a), DndEvent::Source(b)) => a == b,
_ => false,
}
}
}
#[derive(Debug, Clone)]
pub enum SourceEvent {
/// DnD operation ended.
Finished,
/// DnD Cancelled.
Cancelled,
/// DnD action chosen by the compositor.
Action(DndAction),
/// Mime accepted by destination.
/// If [`None`], no mime types are accepted.
Mime(Option<String>),
/// DnD Dropped. The operation is still ongoing until receiving a
/// [`SourceEvent::Finished`] event.
Dropped,
}
impl PartialEq for SourceEvent {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(SourceEvent::Finished, SourceEvent::Finished)
| (SourceEvent::Cancelled, SourceEvent::Cancelled)
| (SourceEvent::Dropped, SourceEvent::Dropped) => true,
(SourceEvent::Action(a), SourceEvent::Action(b)) => a == b,
(SourceEvent::Mime(a), SourceEvent::Mime(b)) => a == b,
_ => false,
}
}
}
#[derive(Debug, Clone)]
pub enum OfferEvent<T> {
Enter {
x: f64,
y: f64,
mime_types: Vec<String>,
surface: T,
},
Motion {
x: f64,
y: f64,
},
/// The offer is no longer on a DnD destination.
LeaveDestination,
/// The offer has left the surface.
Leave,
/// An offer was dropped
Drop,
/// If the selected action is ASK, the user must be presented with a
/// choice. [`Clipboard::set_action`] should then be called before data
/// can be requested and th DnD operation can be finished.
SelectedAction(DndAction),
Data {
data: Vec<u8>,
mime_type: String,
},
}
impl<T> PartialEq for OfferEvent<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
OfferEvent::Enter {
x,
y,
mime_types,
surface: _,
},
OfferEvent::Enter {
x: x2,
y: y2,
mime_types: mime_types2,
surface: _,
},
) => x == x2 && y == y2 && mime_types == mime_types2,
(
OfferEvent::Motion { x, y },
OfferEvent::Motion { x: x2, y: y2 },
) => x == x2 && y == y2,
(OfferEvent::LeaveDestination, OfferEvent::LeaveDestination)
| (OfferEvent::Leave, OfferEvent::Leave)
| (OfferEvent::Drop, OfferEvent::Drop) => true,
(OfferEvent::SelectedAction(a), OfferEvent::SelectedAction(b)) => {
a == b
}
(
OfferEvent::Data { data, mime_type },
OfferEvent::Data {
data: data2,
mime_type: mime_type2,
},
) => data == data2 && mime_type == mime_type2,
_ => false,
}
}
}
/// A rectangle with a logical location and size relative to a [`DndSurface`]
#[derive(Debug, Default, Clone)]
pub struct Rectangle {
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
}
pub trait Sender<T> {
/// Send an event in the channel
fn send(&self, t: DndEvent<T>) -> Result<(), SendError<DndEvent<T>>>;
}
/// A rectangle with a logical location and size relative to a [`DndSurface`]
#[derive(Debug, Clone)]
pub struct DndDestinationRectangle {
/// A unique ID
pub id: u128,
/// The rectangle representing this destination.
pub rectangle: Rectangle,
/// Accepted mime types in this rectangle
pub mime_types: Vec<Cow<'static, str>>,
/// Accepted actions in this rectangle
pub actions: DndAction,
/// Prefered action in this rectangle
pub preferred: DndAction,
}
#[derive(Clone)]
pub enum Icon {
Surface(DndSurface),
/// Xrgb8888 or Argb8888 image data with premultiplied alpha
Buffer {
data: Arc<Vec<u8>>,
width: u32,
height: u32,
transparent: bool,
},
}
#[derive(Clone)]
pub struct DndSurface(pub Arc<dyn HasWindowHandle + 'static + Send + Sync>);
impl Debug for DndSurface {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DndSurface").finish()
}
}
#[derive(Clone)]
pub struct DataWrapper<T>(pub T);

View file

@ -1,110 +0,0 @@
use std::{borrow::Cow, ffi::c_void, sync::Arc};
use crate::{DataWrapper, DndAction, DndSurface, Icon};
use raw_window_handle::HasWindowHandle;
use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
impl<
T: mime::AllowedMimeTypes
+ std::convert::TryFrom<(std::vec::Vec<u8>, String)>,
> AllowedMimeTypes for DataWrapper<T>
{
fn allowed() -> Cow<'static, [MimeType]> {
T::allowed()
.into_iter()
.map(|s| MimeType::from(Cow::Owned(s.to_string())))
.collect()
}
}
impl<T: TryFrom<(Vec<u8>, String)>> TryFrom<(Vec<u8>, MimeType)>
for DataWrapper<T>
{
type Error = T::Error;
fn try_from(
(data, mime): (Vec<u8>, MimeType),
) -> Result<Self, Self::Error> {
T::try_from((data, mime.to_string())).map(|d| DataWrapper(d))
}
}
impl<T: mime::AsMimeTypes> AsMimeTypes for DataWrapper<T> {
fn available(&self) -> Cow<'static, [MimeType]> {
self.0
.available()
.into_iter()
.map(|m| MimeType::from(Cow::Owned(m.to_string())))
.collect()
}
fn as_bytes(&self, mime_type: &MimeType) -> Option<Cow<'static, [u8]>> {
self.0.as_bytes(mime_type.as_ref())
}
}
impl smithay_clipboard::dnd::RawSurface for DndSurface {
unsafe fn get_ptr(&mut self) -> *mut c_void {
self.0.window_handle().unwrap().get_ptr()
}
}
impl From<sctk::reexports::client::protocol::wl_data_device_manager::DndAction>
for DndAction
{
fn from(
action: sctk::reexports::client::protocol::wl_data_device_manager::DndAction,
) -> Self {
let mut a = DndAction::empty();
if action.contains(sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Copy) {
a |= DndAction::Copy;
}
if action.contains(sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Move) {
a |= DndAction::Move;
}
if action.contains(sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Ask) {
a |= DndAction::Ask;
}
a
}
}
impl From<DndAction>
for sctk::reexports::client::protocol::wl_data_device_manager::DndAction
{
fn from(action: DndAction) -> Self {
let mut a = sctk::reexports::client::protocol::wl_data_device_manager::DndAction::empty();
if action.contains(DndAction::Copy) {
a |= sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Copy;
}
if action.contains(DndAction::Move) {
a |= sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Move;
}
if action.contains(DndAction::Ask) {
a |= sctk::reexports::client::protocol::wl_data_device_manager::DndAction::Ask;
}
a
}
}
impl From<Icon> for smithay_clipboard::dnd::Icon<DndSurface> {
fn from(icon: Icon) -> Self {
match icon {
Icon::Surface(surface) => {
smithay_clipboard::dnd::Icon::Surface(surface)
}
Icon::Buffer {
data,
width,
height,
transparent,
} => smithay_clipboard::dnd::Icon::Buf {
data: Arc::try_unwrap(data)
.unwrap_or_else(|d| d.as_ref().clone()),
width,
height,
transparent,
},
}
}
}

View file

@ -1,5 +1,5 @@
use rand::distributions::{Alphanumeric, Distribution};
use window_clipboard::PlatformClipboard;
use window_clipboard::Clipboard;
use winit::{
error::EventLoopError,
event::{ElementState, Event, KeyEvent, WindowEvent},
@ -24,8 +24,8 @@ fn main() -> Result<(), EventLoopError> {
.build(&event_loop)
.unwrap();
let mut clipboard = unsafe { PlatformClipboard::connect(&window) }
.expect("Connect to clipboard");
let mut clipboard =
unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard");
clipboard.write(data.clone()).unwrap();

View file

@ -1,4 +1,4 @@
use window_clipboard::PlatformClipboard;
use window_clipboard::Clipboard;
use winit::{
error::EventLoopError,
event::{Event, WindowEvent},
@ -14,8 +14,8 @@ fn main() -> Result<(), EventLoopError> {
.build(&event_loop)
.unwrap();
let clipboard = unsafe { PlatformClipboard::connect(&window) }
.expect("Connect to clipboard");
let clipboard =
unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard");
event_loop.run(move |event, elwt| match event {
Event::AboutToWait => {

View file

@ -1,4 +1,4 @@
use window_clipboard::PlatformClipboard;
use window_clipboard::Clipboard;
use winit::{
error::EventLoopError,
event::{Event, WindowEvent},
@ -14,8 +14,8 @@ fn main() -> Result<(), EventLoopError> {
.build(&event_loop)
.unwrap();
let mut clipboard = unsafe { PlatformClipboard::connect(&window) }
.expect("Connect to clipboard");
let mut clipboard =
unsafe { Clipboard::connect(&window) }.expect("Connect to clipboard");
clipboard
.write(String::from("Hello, world!"))

View file

@ -15,11 +15,11 @@
extern crate objc;
use objc::runtime::{Class, Object};
use objc_foundation::{
INSArray, INSObject, INSString, NSArray, NSDictionary, NSObject, NSString,
};
use objc_foundation::{INSArray, INSObject, INSString};
use objc_foundation::{NSArray, NSDictionary, NSObject, NSString};
use objc_id::{Id, Owned};
use std::{error::Error, mem::transmute};
use std::error::Error;
use std::mem::transmute;
pub struct Clipboard {
pasteboard: Id<Object>,

View file

@ -1,9 +0,0 @@
[package]
name = "mime"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten", target_os="ios", target_os="redox"))))'.dependencies]
smithay-clipboard = { path = "../../smithay-clipboard" }

View file

@ -1,69 +0,0 @@
pub mod platform;
// need a type that can implement traits for storing custom data
use std::{borrow::Cow, error, fmt};
/// Raw data from the clipboard
pub struct ClipboardData(pub Vec<u8>, pub String);
impl AllowedMimeTypes for ClipboardData {
fn allowed() -> Cow<'static, [String]> {
Cow::Owned(vec![])
}
}
impl TryFrom<(Vec<u8>, String)> for ClipboardData {
type Error = Error;
fn try_from((data, mime): (Vec<u8>, String)) -> Result<Self, Self::Error> {
Ok(ClipboardData(data, mime))
}
}
/// Data that can be loaded from the clipboard.
pub struct ClipboardLoadData<T>(pub T);
/// Describes the mime types which are accepted.
pub trait AllowedMimeTypes:
TryFrom<(Vec<u8>, String)> + Send + Sync + 'static
{
/// List allowed mime types for the type to convert from a byte slice.
///
/// Allowed mime types should be listed in order of decreasing preference,
/// most preferred first.
fn allowed() -> Cow<'static, [String]>;
}
/// Can be converted to data with the available mime types.
pub trait AsMimeTypes {
/// List available mime types for this data to convert to a byte slice.
fn available(&self) -> Cow<'static, [String]>;
/// Converts a type to a byte slice for the given mime type if possible.
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>>;
}
impl<T: AsMimeTypes + ?Sized> AsMimeTypes for Box<T> {
fn available(&self) -> Cow<'static, [String]> {
self.as_ref().available()
}
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>> {
self.as_ref().as_bytes(mime_type)
}
}
/// Data that can be stored to the clipboard.
pub struct ClipboardStoreData<T>(pub T);
#[derive(Debug, Clone, Copy)]
pub struct Error;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Unsupported mime type")
}
}
impl error::Error for Error {}

View file

@ -1,47 +0,0 @@
use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
use crate::{ClipboardLoadData, ClipboardStoreData};
impl<T: crate::AsMimeTypes> AsMimeTypes for ClipboardStoreData<T> {
fn available(&self) -> std::borrow::Cow<'static, [MimeType]> {
self.0
.available()
.into_iter()
.map(|m| MimeType::Other(m.clone().into()))
.collect()
}
fn as_bytes(
&self,
mime_type: &MimeType,
) -> Option<std::borrow::Cow<'static, [u8]>> {
self.0.as_bytes(mime_type.as_ref())
}
}
impl<T: crate::AllowedMimeTypes> AllowedMimeTypes for ClipboardLoadData<T> {
// TODO select text variants if string matches...
fn allowed() -> std::borrow::Cow<'static, [MimeType]> {
T::allowed()
.into_iter()
.map(|s| MimeType::Other(s.clone().into()))
.collect()
}
}
impl<T> TryFrom<(Vec<u8>, MimeType)> for ClipboardLoadData<T>
where
T: for<'b> TryFrom<(Vec<u8>, String)>,
T: 'static,
{
type Error = crate::Error;
fn try_from(
(value, mime): (Vec<u8>, MimeType),
) -> Result<Self, Self::Error> {
let mime = mime.to_string();
Ok(ClipboardLoadData(
T::try_from((value, mime)).map_err(|_| crate::Error)?,
))
}
}

View file

@ -1,11 +0,0 @@
#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten",
target_os = "redox"
))
))]
pub mod linux;

View file

@ -1,102 +0,0 @@
use std::borrow::Cow;
use ::dnd::{DndAction, DndDestinationRectangle, Sender};
use dnd::{DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
pub trait DndProvider {
/// Set up DnD operations for the Clipboard
fn init_dnd(
&self,
_tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
}
/// Start a DnD operation on the given surface with some data
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
_internal: bool,
_source_surface: DndSurface,
_icon_surface: Option<Icon>,
_content: D,
_actions: DndAction,
) {
}
/// End the current DnD operation, if there is one
fn end_dnd(&self) {}
/// Register a surface for receiving DnD offers
/// Rectangles should be provided in order of decreasing priority.
/// This method can be called multiple time for a single surface if the
/// rectangles change.
fn register_dnd_destination(
&self,
_surface: DndSurface,
_rectangles: Vec<DndDestinationRectangle>,
) {
}
/// Set the final action after presenting the user with a choice
fn set_action(&self, _action: DndAction) {}
/// Peek at the contents of a DnD offer
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
_mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
))
}
}
impl<C: DndProvider> DndProvider for crate::PlatformClipboard<C> {
fn init_dnd(
&self,
tx: Box<dyn Sender<DndSurface> + Send + Sync + 'static>,
) {
self.raw.init_dnd(tx);
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
internal: bool,
source_surface: DndSurface,
icon_surface: Option<Icon>,
content: D,
actions: DndAction,
) {
self.raw.start_dnd(
internal,
source_surface,
icon_surface,
content,
actions,
);
}
fn end_dnd(&self) {
self.raw.end_dnd();
}
fn register_dnd_destination(
&self,
surface: DndSurface,
rectangles: Vec<DndDestinationRectangle>,
) {
self.raw.register_dnd_destination(surface, rectangles);
}
fn set_action(&self, action: DndAction) {
self.raw.set_action(action);
}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
self.raw.peek_offer::<D>(mime_type)
}
}

View file

@ -1,5 +1,3 @@
pub use mime;
#[cfg(all(
unix,
not(any(
@ -48,26 +46,21 @@ mod platform;
#[path = "platform/dummy.rs"]
mod platform;
pub mod dnd;
use mime::ClipboardStoreData;
use raw_window_handle::HasDisplayHandle;
use std::error::Error;
pub type Clipboard = PlatformClipboard<platform::Clipboard>;
pub struct PlatformClipboard<C> {
raw: C,
pub struct Clipboard {
raw: Box<dyn ClipboardProvider>,
}
impl PlatformClipboard<platform::Clipboard> {
impl Clipboard {
/// Safety: the display handle must be valid for the lifetime of `Clipboard`
pub unsafe fn connect<W: HasDisplayHandle + ?Sized>(
pub unsafe fn connect<W: HasDisplayHandle>(
window: &W,
) -> Result<Self, Box<dyn Error>> {
Ok(PlatformClipboard {
raw: platform::connect(window)?,
})
let raw = platform::connect(window)?;
Ok(Clipboard { raw })
}
pub fn read(&self) -> Result<String, Box<dyn Error>> {
@ -79,67 +72,14 @@ impl PlatformClipboard<platform::Clipboard> {
}
}
impl<C: ClipboardProvider> PlatformClipboard<C> {
impl Clipboard {
pub fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
self.raw.read_primary()
}
pub fn write_primary(
&mut self,
contents: String,
) -> Option<Result<(), Box<dyn Error>>> {
pub fn write_primary(&mut self, contents: String) -> Option<Result<(), Box<dyn Error>>> {
self.raw.write_primary(contents)
}
pub fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
self.raw.read_data()
}
pub fn write_data<T: Send + Sync + 'static>(
&mut self,
contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
self.raw.write_data(contents)
}
pub fn read_primary_data<T: 'static>(
&self,
) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
self.raw.read_primary_data()
}
pub fn read_primary_raw(
&self,
allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
self.raw.read_primary_raw(allowed)
}
pub fn read_raw(
&self,
allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
self.raw.read_raw(allowed)
}
pub fn write_primary_data<T: Send + Sync + 'static>(
&mut self,
contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
self.raw.write_primary_data(contents)
}
}
pub trait ClipboardProvider {
@ -151,58 +91,7 @@ pub trait ClipboardProvider {
None
}
fn write_primary(
&mut self,
_contents: String,
) -> Option<Result<(), Box<dyn Error>>> {
None
}
fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
None
}
fn write_data<T: Send + Sync + 'static>(
&mut self,
_contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
None
}
fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
None
}
fn read_primary_raw(
&self,
_allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
None
}
fn read_raw(
&self,
_allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
None
}
fn write_primary_data<T: Send + Sync + 'static>(
&mut self,
_contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
fn write_primary(&mut self, _contents: String) -> Option<Result<(), Box<dyn Error>>> {
None
}
}

View file

@ -1,15 +1,12 @@
use crate::ClipboardProvider;
use crate::dnd::DndProvider;
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
use raw_window_handle::HasDisplayHandle;
use std::{borrow::Cow, error::Error};
use std::error::Error;
pub fn connect<W: HasDisplayHandle>(
_window: &W,
) -> Result<Clipboard, Box<dyn Error>> {
Clipboard::new()
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
Ok(Box::new(Clipboard::new()?))
}
pub struct Clipboard;
@ -39,46 +36,7 @@ impl ClipboardProvider for Clipboard {
Err(Box::new(AndroidClipboardError::Unimplemented))
}
fn write(&mut self, _contents: String) -> Result<(), Box<dyn Error>> {
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
Err(Box::new(AndroidClipboardError::Unimplemented))
}
}
impl DndProvider for Clipboard {
fn init_dnd(
&self,
_tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
_internal: bool,
_source_surface: DndSurface,
_icon_surface: Option<Icon>,
_content: D,
_actions: DndAction,
) {
}
fn end_dnd(&self) {}
fn register_dnd_destination(
&self,
_surface: DndSurface,
_rectangles: Vec<DndDestinationRectangle>,
) {
}
fn set_action(&self, _action: DndAction) {}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
_mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
))
}
}

View file

@ -1,19 +1,16 @@
use crate::{dnd::DndProvider, ClipboardProvider};
use crate::ClipboardProvider;
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
use raw_window_handle::HasDisplayHandle;
use std::borrow::Cow;
pub struct Clipboard;
struct Dummy;
pub fn connect<W: HasDisplayHandle + ?Sized>(
pub fn connect<W: HasDisplayHandle>(
_window: &W,
) -> Result<Clipboard, Box<dyn std::error::Error>> {
Ok(Clipboard)
) -> Result<Box<dyn ClipboardProvider>, Box<dyn std::error::Error>> {
Ok(Box::new(Dummy))
}
impl ClipboardProvider for Clipboard {
impl ClipboardProvider for Dummy {
fn read(&self) -> Result<String, Box<dyn std::error::Error>> {
Err(Box::new(Error::Unimplemented))
}
@ -26,45 +23,6 @@ impl ClipboardProvider for Clipboard {
}
}
impl DndProvider for Clipboard {
fn init_dnd(
&self,
_tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
_internal: bool,
_source_surface: DndSurface,
_icon_surface: Option<Icon>,
_content: D,
_actions: DndAction,
) {
}
fn end_dnd(&self) {}
fn register_dnd_destination(
&self,
_surface: DndSurface,
_rectangles: Vec<DndDestinationRectangle>,
) {
}
fn set_action(&self, _action: DndAction) {}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
_mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
))
}
}
#[derive(Debug, Clone, Copy, thiserror::Error)]
enum Error {
#[error("unimplemented")]

View file

@ -3,10 +3,10 @@ use crate::ClipboardProvider;
use raw_window_handle::HasDisplayHandle;
use std::error::Error;
pub fn connect<W: HasDisplayHandle + ?Sized>(
pub fn connect<W: HasDisplayHandle>(
_window: &W,
) -> Result<Clipboard, Box<dyn Error>> {
Clipboard::new()
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
Ok(Box::new(Clipboard::new()?))
}
pub struct Clipboard;

View file

@ -1,241 +1,56 @@
use crate::{
dnd::DndProvider,
mime::{ClipboardLoadData, ClipboardStoreData},
ClipboardProvider,
};
use crate::ClipboardProvider;
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
use raw_window_handle::{HasDisplayHandle, RawDisplayHandle};
use std::{borrow::Cow, error::Error, sync::Arc};
use wayland::DndSender;
use std::error::Error;
pub use clipboard_wayland as wayland;
#[cfg(feature = "x11")]
pub use clipboard_x11 as x11;
pub enum Clipboard {
Wayland(wayland::Clipboard),
#[cfg(feature = "x11")]
X11(x11::Clipboard),
}
impl ClipboardProvider for Clipboard {
fn read(&self) -> Result<String, Box<dyn Error>> {
match self {
Clipboard::Wayland(c) => c.read(),
#[cfg(feature = "x11")]
Clipboard::X11(c) => c.read().map_err(Box::from),
}
}
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
match self {
Clipboard::Wayland(c) => c.write(contents),
#[cfg(feature = "x11")]
Clipboard::X11(c) => c.write(contents).map_err(Box::from),
}
}
fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
match self {
Clipboard::Wayland(c) => Some(c.read_primary()),
#[cfg(feature = "x11")]
Clipboard::X11(c) => Some(c.read_primary().map_err(Box::from)),
}
}
fn write_primary(
&mut self,
contents: String,
) -> Option<Result<(), Box<dyn Error>>> {
match self {
Clipboard::Wayland(c) => Some(c.write_primary(contents)),
#[cfg(feature = "x11")]
Clipboard::X11(c) => {
Some(c.write_primary(contents).map_err(Box::from))
}
}
}
fn read_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
match self {
Clipboard::Wayland(c) => {
let ret = c.read_data::<ClipboardLoadData<T>>();
Some(ret.map(|ret| ret.0))
}
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
fn write_data<T: Send + Sync + 'static>(
&mut self,
contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
match self {
Clipboard::Wayland(c) => {
Some(c.write_data::<ClipboardStoreData<T>>(contents))
}
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
fn read_primary_data<T: 'static>(&self) -> Option<Result<T, Box<dyn Error>>>
where
T: mime::AllowedMimeTypes,
{
match self {
Clipboard::Wayland(c) => {
let ret = c.read_primary_data::<ClipboardLoadData<T>>();
Some(ret.map(|ret| ret.0))
}
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
fn read_primary_raw(
&self,
allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
match self {
Clipboard::Wayland(c) => Some(c.read_primary_raw(allowed)),
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
fn read_raw(
&self,
allowed: Vec<String>,
) -> Option<Result<(Vec<u8>, String), Box<dyn Error>>> {
match self {
Clipboard::Wayland(c) => Some(c.read_raw(allowed)),
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
fn write_primary_data<T: Send + Sync + 'static>(
&mut self,
contents: ClipboardStoreData<T>,
) -> Option<Result<(), Box<dyn Error>>>
where
T: mime::AsMimeTypes,
{
match self {
Clipboard::Wayland(c) => {
Some(c.write_primary_data::<ClipboardStoreData<T>>(contents))
}
#[cfg(feature = "x11")]
Clipboard::X11(_) => None,
}
}
}
impl DndProvider for Clipboard {
fn init_dnd(
&self,
tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
match self {
Clipboard::Wayland(c) => c.init_dnd(DndSender(Arc::from(tx))),
#[cfg(feature = "x11")]
Clipboard::X11(_) => {}
}
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
internal: bool,
source_surface: DndSurface,
icon_surface: Option<Icon>,
content: D,
actions: DndAction,
) {
match self {
Clipboard::Wayland(c) => c.start_dnd(
internal,
source_surface,
icon_surface,
content,
actions,
),
#[cfg(feature = "x11")]
Clipboard::X11(_) => {}
}
}
fn end_dnd(&self) {
match self {
Clipboard::Wayland(c) => c.end_dnd(),
#[cfg(feature = "x11")]
Clipboard::X11(_) => {}
}
}
fn register_dnd_destination(
&self,
surface: DndSurface,
rectangles: Vec<DndDestinationRectangle>,
) {
match self {
Clipboard::Wayland(c) => {
c.register_dnd_destination(surface, rectangles)
}
#[cfg(feature = "x11")]
Clipboard::X11(_) => {}
}
}
fn set_action(&self, action: DndAction) {
match self {
Clipboard::Wayland(c) => c.set_action(action),
#[cfg(feature = "x11")]
Clipboard::X11(_) => {}
}
}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
match self {
Clipboard::Wayland(c) => c.peek_offer::<D>(mime_type),
#[cfg(feature = "x11")]
Clipboard::X11(_) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
)),
}
}
}
pub unsafe fn connect<W: HasDisplayHandle + ?Sized>(
pub unsafe fn connect<W: HasDisplayHandle>(
window: &W,
) -> Result<Clipboard, Box<dyn Error>> {
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
let clipboard = match window.display_handle()?.as_raw() {
RawDisplayHandle::Wayland(handle) => Clipboard::Wayland(
wayland::Clipboard::connect(handle.display.as_ptr()),
) as _,
#[cfg(feature = "x11")]
_ => Clipboard::X11(x11::Clipboard::connect()?) as _,
#[cfg(not(feature = "x11"))]
_ => {
return Err(Box::from(
"Yoda window_clipboard: X11 feature disabled; \
non-Wayland display handles are not supported",
))
RawDisplayHandle::Wayland(handle) => {
Box::new(wayland::Clipboard::connect(handle.display.as_ptr())) as _
}
_ => Box::new(x11::Clipboard::connect()?) as _,
};
Ok(clipboard)
}
impl ClipboardProvider for wayland::Clipboard {
fn read(&self) -> Result<String, Box<dyn Error>> {
self.read()
}
fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
Some(self.read_primary())
}
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
self.write(contents)
}
fn write_primary(&mut self, contents: String) -> Option<Result<(), Box<dyn Error>>> {
Some(self.write_primary(contents))
}
}
impl ClipboardProvider for x11::Clipboard {
fn read(&self) -> Result<String, Box<dyn Error>> {
self.read().map_err(Box::from)
}
fn read_primary(&self) -> Option<Result<String, Box<dyn Error>>> {
Some(self.read_primary().map_err(Box::from))
}
fn write(&mut self, contents: String) -> Result<(), Box<dyn Error>> {
self.write(contents).map_err(Box::from)
}
fn write_primary(&mut self, contents: String) -> Option<Result<(), Box<dyn Error>>> {
Some(self.write_primary(contents).map_err(Box::from))
}
}

View file

@ -1,58 +1,15 @@
use crate::ClipboardProvider;
use crate::dnd::DndProvider;
pub(crate) use clipboard_macos::Clipboard;
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
use raw_window_handle::HasDisplayHandle;
use std::{borrow::Cow, error::Error};
use std::error::Error;
pub fn connect<W: HasDisplayHandle + ?Sized>(
pub fn connect<W: HasDisplayHandle>(
_window: &W,
) -> Result<Clipboard, Box<dyn Error>> {
Clipboard::new()
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
Ok(Box::new(clipboard_macos::Clipboard::new()?))
}
impl DndProvider for Clipboard {
fn init_dnd(
&self,
_tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
_internal: bool,
_source_surface: DndSurface,
_icon_surface: Option<Icon>,
_content: D,
_actions: DndAction,
) {
}
fn end_dnd(&self) {}
fn register_dnd_destination(
&self,
_surface: DndSurface,
_rectangles: Vec<DndDestinationRectangle>,
) {
}
fn set_action(&self, _action: DndAction) {}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
_mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
))
}
}
impl ClipboardProvider for Clipboard {
impl ClipboardProvider for clipboard_macos::Clipboard {
fn read(&self) -> Result<String, Box<dyn Error>> {
self.read()
}

View file

@ -1,54 +1,14 @@
use crate::ClipboardProvider;
use crate::dnd::DndProvider;
use clipboard_win::{get_clipboard_string, set_clipboard_string};
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
use mime::{AllowedMimeTypes, AsMimeTypes};
use raw_window_handle::HasDisplayHandle;
use std::{borrow::Cow, error::Error};
pub fn connect<W: HasDisplayHandle + ?Sized>(
use std::error::Error;
pub fn connect<W: HasDisplayHandle>(
_window: &W,
) -> Result<Clipboard, Box<dyn Error>> {
Ok(Clipboard)
}
impl DndProvider for Clipboard {
fn init_dnd(
&self,
_tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
) {
}
fn start_dnd<D: AsMimeTypes + Send + 'static>(
&self,
_internal: bool,
_source_surface: DndSurface,
_icon_surface: Option<Icon>,
_content: D,
_actions: DndAction,
) {
}
fn end_dnd(&self) {}
fn register_dnd_destination(
&self,
_surface: DndSurface,
_rectangles: Vec<DndDestinationRectangle>,
) {
}
fn set_action(&self, _action: DndAction) {}
fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
_mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"DnD not supported",
))
}
) -> Result<Box<dyn ClipboardProvider>, Box<dyn Error>> {
Ok(Box::new(Clipboard))
}
pub struct Clipboard;

View file

@ -10,9 +10,4 @@ documentation = "https://docs.rs/clipboard_wayland"
keywords = ["clipboard", "wayland"]
[dependencies]
smithay-clipboard = { path = "../../smithay-clipboard", features = [
"dnd",
] }
mime = { path = "../mime" }
dnd = { path = "../dnd" }
smithay-clipboard = "0.7"

View file

@ -12,99 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{
borrow::Cow,
error::Error,
ffi::c_void,
sync::{mpsc::SendError, Arc, Mutex},
};
use dnd::{
DataWrapper, DndAction, DndDestinationRectangle, DndSurface, Sender,
};
use mime::ClipboardData;
use smithay_clipboard::dnd::{Icon, Rectangle};
pub use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
#[derive(Clone)]
pub struct DndSender(pub Arc<dyn Sender<DndSurface> + 'static + Send + Sync>);
impl smithay_clipboard::dnd::Sender<DndSurface> for DndSender {
fn send(
&self,
event: smithay_clipboard::dnd::DndEvent<DndSurface>,
) -> Result<(), SendError<smithay_clipboard::dnd::DndEvent<DndSurface>>>
{
_ = self.0.send(match event {
smithay_clipboard::dnd::DndEvent::Offer(id, e) => dnd::DndEvent::Offer(
id,
match e {
smithay_clipboard::dnd::OfferEvent::Enter {
x,
y,
mime_types,
surface,
} => dnd::OfferEvent::Enter {
x,
y,
mime_types: mime_types
.into_iter()
.map(|m| m.to_string())
.collect(),
surface,
},
smithay_clipboard::dnd::OfferEvent::Motion { x, y } => {
dnd::OfferEvent::Motion { x, y }
}
smithay_clipboard::dnd::OfferEvent::LeaveDestination => {
dnd::OfferEvent::LeaveDestination
}
smithay_clipboard::dnd::OfferEvent::Leave => {
dnd::OfferEvent::Leave
}
smithay_clipboard::dnd::OfferEvent::Drop => {
dnd::OfferEvent::Drop
}
smithay_clipboard::dnd::OfferEvent::SelectedAction(
action,
) => dnd::OfferEvent::SelectedAction(action.into()),
smithay_clipboard::dnd::OfferEvent::Data {
data,
mime_type,
} => dnd::OfferEvent::Data {
data,
mime_type: mime_type.to_string(),
},
},
),
smithay_clipboard::dnd::DndEvent::Source(e) => match e {
smithay_clipboard::dnd::SourceEvent::Finished => {
dnd::DndEvent::Source(dnd::SourceEvent::Finished)
}
smithay_clipboard::dnd::SourceEvent::Cancelled => {
dnd::DndEvent::Source(dnd::SourceEvent::Cancelled)
}
smithay_clipboard::dnd::SourceEvent::Action(action) => {
dnd::DndEvent::Source(dnd::SourceEvent::Action(
action.into(),
))
}
smithay_clipboard::dnd::SourceEvent::Mime(mime) => {
dnd::DndEvent::Source(dnd::SourceEvent::Mime(
mime.map(|m| m.to_string()),
))
}
smithay_clipboard::dnd::SourceEvent::Dropped => {
dnd::DndEvent::Source(dnd::SourceEvent::Dropped)
}
},
});
Ok(())
}
}
use std::error::Error;
use std::ffi::c_void;
use std::sync::{Arc, Mutex};
pub struct Clipboard {
context: Arc<Mutex<smithay_clipboard::Clipboard<DndSurface>>>,
context: Arc<Mutex<smithay_clipboard::Clipboard>>,
}
impl Clipboard {
@ -117,173 +30,22 @@ impl Clipboard {
}
pub fn read(&self) -> Result<String, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_text()?)
Ok(self.context.lock().unwrap().load()?)
}
pub fn read_primary(&self) -> Result<String, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary_text()?)
Ok(self.context.lock().unwrap().load_primary()?)
}
pub fn write(&mut self, data: String) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store_text(data);
Ok(())
}
pub fn write_primary(
&mut self,
data: String,
) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store_primary_text(data);
Ok(())
}
pub fn write_data<T: AsMimeTypes + Send + Sync + 'static>(
&mut self,
data: T,
) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store(data);
Ok(())
}
pub fn write_primary_data<T: AsMimeTypes + Send + Sync + 'static>(
&mut self,
data: T,
) -> Result<(), Box<dyn Error>> {
pub fn write_primary(&mut self, data: String) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store_primary(data);
Ok(())
}
pub fn read_data<T: AllowedMimeTypes + 'static>(
&self,
) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load()?)
}
pub fn read_primary_data<T: AllowedMimeTypes + 'static>(
&self,
) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary()?)
}
pub fn read_primary_raw(
&self,
allowed: Vec<String>,
) -> Result<(Vec<u8>, String), Box<dyn Error>> {
Ok(self
.context
.lock()
.unwrap()
.load_primary_mime::<DataWrapper<ClipboardData>>(
allowed
.into_iter()
.map(|s| MimeType::from(Cow::Owned(s)))
.collect::<Vec<_>>(),
)
.map(|d| (d.0 .0, d.0 .1.to_string()))?)
}
pub fn read_raw(
&self,
allowed: Vec<String>,
) -> Result<(Vec<u8>, String), Box<dyn Error>> {
Ok(self
.context
.lock()
.unwrap()
.load_mime::<DataWrapper<ClipboardData>>(
allowed
.into_iter()
.map(|s| MimeType::from(Cow::Owned(s)))
.collect::<Vec<_>>(),
)
.map(|d| (d.0 .0, d.0 .1))?)
}
pub fn init_dnd(&self, tx: DndSender) {
_ = self.context.lock().unwrap().init_dnd(Box::new(tx));
}
/// Start a DnD operation on the given surface with some data
pub fn start_dnd<D: mime::AsMimeTypes + Send + 'static>(
&self,
internal: bool,
source_surface: DndSurface,
icon_surface: Option<dnd::Icon>,
content: D,
actions: DndAction,
) {
_ = self.context.lock().unwrap().start_dnd(
internal,
source_surface,
icon_surface.map(|i| Icon::<DndSurface>::from(i)),
DataWrapper(content),
actions.into(),
);
}
/// End the current DnD operation, if there is one
pub fn end_dnd(&self) {
_ = self.context.lock().unwrap().end_dnd();
}
/// Register a surface for receiving DnD offers
/// Rectangles should be provided in order of decreasing priority.
/// This method can be called multiple time for a single surface if the
/// rectangles change.
pub fn register_dnd_destination(
&self,
surface: DndSurface,
rectangles: Vec<DndDestinationRectangle>,
) {
_ = self.context.lock().unwrap().register_dnd_destination(
surface,
rectangles
.into_iter()
.map(|r| RectangleWrapper(r).into())
.collect(),
);
}
/// Set the final action after presenting the user with a choice
pub fn set_action(&self, action: DndAction) {
self.context.lock().unwrap().set_action(action.into());
}
/// Peek at the contents of a DnD offer
pub fn peek_offer<D: mime::AllowedMimeTypes + 'static>(
&self,
mime_type: Option<Cow<'static, str>>,
) -> std::io::Result<D> {
let d = self
.context
.lock()
.unwrap()
.peek_offer::<DataWrapper<D>>(mime_type.map(MimeType::from));
d.map(|d| d.0)
}
}
pub struct RectangleWrapper(pub DndDestinationRectangle);
impl From<RectangleWrapper>
for smithay_clipboard::dnd::DndDestinationRectangle
{
fn from(RectangleWrapper(d): RectangleWrapper) -> Self {
smithay_clipboard::dnd::DndDestinationRectangle {
id: d.id,
rectangle: Rectangle {
x: d.rectangle.x,
y: d.rectangle.y,
width: d.rectangle.width,
height: d.rectangle.height,
},
mime_types: d.mime_types.into_iter().map(MimeType::from).collect(),
actions: d.actions.into(),
preferred: d.preferred.into(),
}
}
}

View file

@ -1,7 +1,5 @@
use x11rb::{
errors::{ConnectError, ConnectionError, ReplyError},
protocol::xproto::Atom,
};
use x11rb::errors::{ConnectError, ConnectionError, ReplyError};
use x11rb::protocol::xproto::Atom;
use std::sync::mpsc;

View file

@ -3,23 +3,17 @@ mod error;
pub use error::Error;
use x11rb::{
connection::Connection as _,
errors::ConnectError,
protocol::{
xproto::{self, Atom, AtomEnum, EventMask, Window},
Event,
},
rust_connection::RustConnection as Connection,
wrapper::ConnectionExt,
};
use x11rb::connection::Connection as _;
use x11rb::errors::ConnectError;
use x11rb::protocol::xproto::{self, Atom, AtomEnum, EventMask, Window};
use x11rb::protocol::Event;
use x11rb::rust_connection::RustConnection as Connection;
use x11rb::wrapper::ConnectionExt;
use std::{
collections::HashMap,
sync::{Arc, RwLock},
thread,
time::{Duration, Instant},
};
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use std::thread;
use std::time::{Duration, Instant};
const POLL_DURATION: std::time::Duration = Duration::from_micros(50);
@ -66,16 +60,13 @@ impl Clipboard {
self.read_selection(self.reader.atoms.clipboard)
}
/// Read the current PRIMARY [`Clipboard`] value.
pub fn read_primary(&self) -> Result<String, Error> {
self.read_selection(self.reader.atoms.primary)
}
fn write_selection(
&mut self,
selection: Atom,
contents: String,
) -> Result<(), Error> {
fn write_selection(&mut self, selection: Atom, contents: String) -> Result<(), Error> {
let target = self.writer.atoms.utf8_string;
self.selections
@ -133,13 +124,9 @@ impl Clipboard {
selection,
target,
property,
x11rb::CURRENT_TIME, /* FIXME ^
* Clients should not use CurrentTime for
* the time argument of a ConvertSelection
* request.
* Instead, they should use the timestamp
* of the event that caused the request to
* be made. */
x11rb::CURRENT_TIME, // FIXME ^
// Clients should not use CurrentTime for the time argument of a ConvertSelection request.
// Instead, they should use the timestamp of the event that caused the request to be made.
)?;
let _ = self.reader.connection.flush()?;
@ -199,9 +186,8 @@ impl Clipboard {
continue;
};
// Note that setting the property argument to None indicates
// that the conversion requested could
// not be made.
// Note that setting the property argument to None indicates that the
// conversion requested could not be made.
if event.property == AtomEnum::NONE.into() {
break;
}