From 909b7f6ff370ef41167f5b770462082f981c7031 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Tue, 10 Oct 2023 21:07:27 +0400 Subject: [PATCH] mime: use text/plain as a fallback --- CHANGELOG.md | 1 + src/mime.rs | 13 +++++++++++-- src/state.rs | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15bd276..1759f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Update SCTK to 0.18 - Fix active polling of the clipboard each 50ms - Fix freeze when copying data larger than the pipe buffer size +- Accept text/plain mime type as a fallback ## 0.6.6 -- 2022-06-20 diff --git a/src/mime.rs b/src/mime.rs index f3fc9a7..7761d6c 100644 --- a/src/mime.rs +++ b/src/mime.rs @@ -1,5 +1,6 @@ /// List of allowed mimes. -pub static ALLOWED_MIME_TYPES: [&str; 2] = ["text/plain;charset=utf-8", "UTF8_STRING"]; +pub static ALLOWED_MIME_TYPES: [&str; 3] = + ["text/plain;charset=utf-8", "UTF8_STRING", "text/plain"]; /// Mime type supported by clipboard. #[derive(Clone, Copy, Eq, PartialEq, Debug)] @@ -13,6 +14,10 @@ pub enum MimeType { /// Some X11 clients are using only this mime type, so we /// should have it as a fallback just in case. Utf8String = 1, + /// text/plain mime type. + /// + /// Fallback without charset parameter. + TextPlain = 2, } impl MimeType { @@ -21,15 +26,19 @@ impl MimeType { /// `find_allowed()` searches for mime type clipboard supports, if we have a /// match, returns `Some(MimeType)`, otherwise `None`. pub fn find_allowed(offered_mime_types: &[String]) -> Option { + let mut fallback = None; for offered_mime_type in offered_mime_types.iter() { if offered_mime_type == ALLOWED_MIME_TYPES[Self::TextPlainUtf8 as usize] { return Some(Self::TextPlainUtf8); } else if offered_mime_type == ALLOWED_MIME_TYPES[Self::Utf8String as usize] { return Some(Self::Utf8String); + } else if offered_mime_type == ALLOWED_MIME_TYPES[Self::TextPlain as usize] { + // Only use this mime type as a fallback. + fallback = Some(Self::TextPlain); } } - None + fallback } } diff --git a/src/state.rs b/src/state.rs index adf5fcb..69921e9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -217,7 +217,9 @@ impl State { // Post-process the content according to mime type. let content = match mime_type { - MimeType::TextPlainUtf8 => normalize_to_lf(content), + MimeType::TextPlainUtf8 | MimeType::TextPlain => { + normalize_to_lf(content) + }, MimeType::Utf8String => content, };