Skip to content

Commit

Permalink
cleanup wayland code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gae24 committed Oct 13, 2024
1 parent aea5012 commit 326ede7
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/platform/linux/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ impl Clipboard {
Ok(Self {})
}

pub(crate) fn get_text(&mut self, selection: LinuxClipboardKind) -> Result<String, Error> {
use wl_clipboard_rs::paste::MimeType;

let result = get_contents(selection.try_into()?, Seat::Unspecified, MimeType::Text);
fn string_for_mime(&mut self, selection: LinuxClipboardKind, mime: paste::MimeType) -> Result<String, Error> {
let result = get_contents(selection.try_into()?, Seat::Unspecified, mime);
match result {
Ok((mut pipe, _)) => {
let mut contents = vec![];
Expand All @@ -74,6 +72,10 @@ impl Clipboard {
}
}

pub(crate) fn get_text(&mut self, selection: LinuxClipboardKind) -> Result<String, Error> {
self.string_for_mime(selection, paste::MimeType::Text)
}

pub(crate) fn set_text(
&self,
text: Cow<'_, str>,
Expand All @@ -92,24 +94,7 @@ impl Clipboard {
}

pub(crate) fn get_html(&mut self, selection: LinuxClipboardKind) -> Result<String, Error> {
use wl_clipboard_rs::paste::MimeType;

let result = get_contents(selection.try_into()?, Seat::Unspecified, MimeType::Specific("text/html"));
match result {
Ok((mut pipe, _)) => {
let mut contents = vec![];
pipe.read_to_end(&mut contents).map_err(into_unknown)?;
String::from_utf8(contents).map_err(|_| Error::ConversionFailure)
}

Err(PasteError::ClipboardEmpty) | Err(PasteError::NoMimeType) => {
Err(Error::ContentNotAvailable)
}

Err(PasteError::PrimarySelectionUnsupported) => Err(Error::ClipboardNotSupported),

Err(err) => Err(Error::Unknown { description: err.to_string() }),
}
self.string_for_mime(selection, paste::MimeType::Specific("text/html"))
}

pub(crate) fn set_html(
Expand Down

0 comments on commit 326ede7

Please sign in to comment.