Skip to main content

wingy_core/event_loop/
primary_selection.rs

1use crate::data_transfer::{DataTransferId, DataTransferSend};
2use crate::error::TransferError;
3
4/// Platform extension allowing access to the primary selection, where available.
5///
6/// The primary selection is a separate clipboard on Wayland and X11, usually holding the most
7/// recently selected text and pasted with a middle click.
8///
9/// Access via [`ActiveEventLoop::primary_selection_ext`].
10///
11/// # Example
12///
13/// ```ignore
14/// if let Some(ext) = event_loop.primary_selection_ext() {
15///     if let Some(data_transfer_id) = ext.primary_selection()? {
16///         event_loop.fetch_data_transfer(data_transfer_id, &TypeHint::Plaintext)?;
17///     }
18/// }
19/// ```
20///
21/// [`ActiveEventLoop::primary_selection_ext`]: crate::event_loop::ActiveEventLoop::primary_selection_ext
22pub trait PrimarySelectionExt: std::fmt::Debug {
23    /// Get the current primary selection contents as a [data transfer](crate::data_transfer), or
24    /// `None` if the primary selection is empty.
25    ///
26    /// See [`ActiveEventLoop::clipboard`] for more details.
27    ///
28    /// [`ActiveEventLoop::clipboard`]: crate::event_loop::ActiveEventLoop::clipboard
29    fn primary_selection(&self) -> Result<Option<DataTransferId>, TransferError>;
30
31    /// Set the primary selection contents.
32    ///
33    /// See [`ActiveEventLoop::set_clipboard`] for more details.
34    ///
35    /// [`ActiveEventLoop::set_clipboard`]: crate::event_loop::ActiveEventLoop::set_clipboard
36    fn set_primary_selection(
37        &self,
38        send_data: Box<dyn DataTransferSend>,
39    ) -> Result<(), TransferError>;
40}