refactor: Allow requesting a specific mime type when peeking at the offer

This commit is contained in:
Ashley Wulber 2024-03-26 17:13:38 -04:00
parent 1b6efd066e
commit efe7a75e7b
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
2 changed files with 12 additions and 7 deletions

View file

@ -88,9 +88,9 @@ fn main() {
smithay_clipboard::dnd::DndEvent::Offer(id, OfferEvent::Motion { x, y }) => {
if id != state.offer_hover_id {
state.offer_hover_id = id;
if let Ok(data) = state.clipboard.peek_offer::<smithay_clipboard::text::Text>(
MimeType::Text(smithay_clipboard::mime::Text::TextPlain),
) {
if let Ok(data) =
state.clipboard.peek_offer::<smithay_clipboard::text::Text>(None)
{
println!("Peeked the data: {}", data.0);
}
}
@ -117,8 +117,9 @@ fn main() {
println!("Received DnD Enter for {id:?}");
state.offer_hover_id = id;
if let Some(mime) = mime_types.get(0) {
if let Ok(data) =
state.clipboard.peek_offer::<smithay_clipboard::text::Text>(mime.clone())
if let Ok(data) = state
.clipboard
.peek_offer::<smithay_clipboard::text::Text>(Some(mime.clone()))
{
println!("Peeked the data: {}", data.0);
}

View file

@ -203,7 +203,7 @@ impl<T: RawSurface> Clipboard<T> {
/// Register a surface for receiving DnD offers
/// Rectangles should be provided in order of decreasing priority.
/// This method can be called multiple time for a single surface if the
/// This method c~an be called multiple time for a single surface if the
/// rectangles change.
pub fn register_dnd_destination(&self, surface: T, rectangles: Vec<DndDestinationRectangle>) {
let s = DndSurface::new(surface, &self.connection).unwrap();
@ -223,8 +223,12 @@ impl<T: RawSurface> Clipboard<T> {
/// Peek at the contents of a DnD offer
pub fn peek_offer<D: AllowedMimeTypes + 'static>(
&self,
mime_type: MimeType,
mime_type: Option<MimeType>,
) -> std::io::Result<D> {
let Some(mime_type) = mime_type.or_else(|| D::allowed().first().cloned()) else {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "No mime type provided."));
};
self.request_sender
.send(crate::worker::Command::DndRequest(DndRequest::Peek(mime_type)))
.map_err(|_| {