refactor: Allow requesting a specific mime type when peeking at the offer
This commit is contained in:
parent
1b6efd066e
commit
efe7a75e7b
2 changed files with 12 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(|_| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue