From 4155edab8d123b767ddad67e24ca2d4c50f31ece Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Wed, 7 Feb 2024 17:25:40 +0100 Subject: Add support for primary clipboard --- runtime/src/clipboard.rs | 14 ++++++++++++++ runtime/src/command/action.rs | 9 +++++++++ 2 files changed, 23 insertions(+) (limited to 'runtime') diff --git a/runtime/src/clipboard.rs b/runtime/src/clipboard.rs index bc450912..49044a0f 100644 --- a/runtime/src/clipboard.rs +++ b/runtime/src/clipboard.rs @@ -51,3 +51,17 @@ pub fn read( pub fn write(contents: String) -> Command { Command::single(command::Action::Clipboard(Action::Write(contents))) } + +/// Read the current contents of primary. +pub fn read_primary( + f: impl Fn(Option) -> Message + 'static, +) -> Command { + Command::single(command::Action::ClipboardPrimary(Action::Read(Box::new( + f, + )))) +} + +/// Write the given contents to primary. +pub fn write_primary(contents: String) -> Command { + Command::single(command::Action::ClipboardPrimary(Action::Write(contents))) +} diff --git a/runtime/src/command/action.rs b/runtime/src/command/action.rs index c9ffe801..f04c642c 100644 --- a/runtime/src/command/action.rs +++ b/runtime/src/command/action.rs @@ -26,6 +26,9 @@ pub enum Action { /// Run a clipboard action. Clipboard(clipboard::Action), + /// Run a clipboard action on primary. + ClipboardPrimary(clipboard::Action), + /// Run a window action. Window(window::Action), @@ -66,6 +69,9 @@ impl Action { Self::Future(future) => Action::Future(Box::pin(future.map(f))), Self::Stream(stream) => Action::Stream(Box::pin(stream.map(f))), Self::Clipboard(action) => Action::Clipboard(action.map(f)), + Self::ClipboardPrimary(action) => { + Action::ClipboardPrimary(action.map(f)) + } Self::Window(window) => Action::Window(window.map(f)), Self::System(system) => Action::System(system.map(f)), Self::Widget(operation) => { @@ -88,6 +94,9 @@ impl fmt::Debug for Action { Self::Clipboard(action) => { write!(f, "Action::Clipboard({action:?})") } + Self::ClipboardPrimary(action) => { + write!(f, "Action::ClipboardPrimary({action:?})") + } Self::Window(action) => { write!(f, "Action::Window({action:?})") } -- cgit