diff options
author | 2024-02-13 03:35:35 +0100 | |
---|---|---|
committer | 2024-02-13 03:35:35 +0100 | |
commit | dc2cba92646392fa78a14f768d98ad5f15b9f182 (patch) | |
tree | 84c48ea5c45516953b009e768fd6a9241ea80950 /winit/src/clipboard.rs | |
parent | 7615b2240c360fea21ef041bfd5b1deb73fc03d1 (diff) | |
parent | 3ac2902f689fce8feaf86703b25535a93aa95209 (diff) | |
download | iced-dc2cba92646392fa78a14f768d98ad5f15b9f182.tar.gz iced-dc2cba92646392fa78a14f768d98ad5f15b9f182.tar.bz2 iced-dc2cba92646392fa78a14f768d98ad5f15b9f182.zip |
Merge pull request #2240 from snaggen/primary
Add support for primary clipboard
Diffstat (limited to '')
-rw-r--r-- | winit/src/clipboard.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 8f5c5e63..5237ca01 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -1,5 +1,7 @@ //! Access the clipboard. +use crate::core::clipboard::Kind; + /// A buffer for short-term storage and transfer within and between /// applications. #[allow(missing_debug_implementations)] @@ -33,33 +35,45 @@ impl Clipboard { } /// Reads the current content of the [`Clipboard`] as text. - pub fn read(&self) -> Option<String> { + pub fn read(&self, kind: Kind) -> Option<String> { match &self.state { - State::Connected(clipboard) => clipboard.read().ok(), + State::Connected(clipboard) => match kind { + Kind::Standard => clipboard.read().ok(), + Kind::Primary => clipboard.read_primary().and_then(Result::ok), + }, State::Unavailable => None, } } /// Writes the given text contents to the [`Clipboard`]. - pub fn write(&mut self, contents: String) { + pub fn write(&mut self, kind: Kind, contents: String) { match &mut self.state { - State::Connected(clipboard) => match clipboard.write(contents) { - Ok(()) => {} - Err(error) => { - log::warn!("error writing to clipboard: {error}"); + State::Connected(clipboard) => { + let result = match kind { + Kind::Standard => clipboard.write(contents), + Kind::Primary => { + clipboard.write_primary(contents).unwrap_or(Ok(())) + } + }; + + match result { + Ok(()) => {} + Err(error) => { + log::warn!("error writing to clipboard: {error}"); + } } - }, + } State::Unavailable => {} } } } impl crate::core::Clipboard for Clipboard { - fn read(&self) -> Option<String> { - self.read() + fn read(&self, kind: Kind) -> Option<String> { + self.read(kind) } - fn write(&mut self, contents: String) { - self.write(contents); + fn write(&mut self, kind: Kind, contents: String) { + self.write(kind, contents); } } |