chore: refactor dnd offer mimes
This commit is contained in:
parent
1063256706
commit
f5384a32c0
3 changed files with 11 additions and 15 deletions
|
|
@ -78,7 +78,10 @@ fn main() {
|
|||
DndDestinationRectangle {
|
||||
id: 0,
|
||||
rectangle: Rectangle { x: 0., y: 0., width: 256., height: 256. },
|
||||
mime_types: ALLOWED_TEXT_MIME_TYPES.iter().map(|m| Cow::from(m.to_string())).collect(),
|
||||
mime_types: ALLOWED_TEXT_MIME_TYPES
|
||||
.iter()
|
||||
.map(|m| MimeType::from(Cow::from(m.to_string())))
|
||||
.collect(),
|
||||
actions: DndAction::all(),
|
||||
preferred: DndAction::Copy,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::borrow::Cow;
|
||||
use std::ffi::c_void;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::mpsc::SendError;
|
||||
|
|
@ -9,7 +8,7 @@ use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
|||
use sctk::reexports::client::{Connection, Proxy};
|
||||
use wayland_backend::client::{InvalidId, ObjectId};
|
||||
|
||||
use crate::mime::AsMimeTypes;
|
||||
use crate::mime::{AsMimeTypes, MimeType};
|
||||
use crate::Clipboard;
|
||||
|
||||
pub mod state;
|
||||
|
|
@ -118,7 +117,7 @@ pub struct DndDestinationRectangle {
|
|||
/// The rectangle representing this destination.
|
||||
pub rectangle: Rectangle,
|
||||
/// Accepted mime types in this rectangle
|
||||
pub mime_types: Vec<Cow<'static, str>>,
|
||||
pub mime_types: Vec<MimeType>,
|
||||
/// Accepted actions in this rectangle
|
||||
pub actions: DndAction,
|
||||
/// Prefered action in this rectangle
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub(crate) struct DndState<T> {
|
|||
active_surface: Option<(DndSurface<T>, Option<DndDestinationRectangle>)>,
|
||||
source_actions: DndAction,
|
||||
selected_action: DndAction,
|
||||
selected_mime: Option<String>,
|
||||
selected_mime: Option<MimeType>,
|
||||
pub(crate) source_content: Box<dyn AsMimeTypes>,
|
||||
pub(crate) source_mime_types: Rc<Cow<'static, [MimeType]>>,
|
||||
}
|
||||
|
|
@ -82,13 +82,10 @@ where
|
|||
});
|
||||
let mime = dnd_state.as_ref().and_then(|dnd_state| {
|
||||
r.mime_types.iter().find(|m| {
|
||||
dnd_state.with_mime_types(|mimes| mimes.iter().any(|a| &a == m))
|
||||
dnd_state.with_mime_types(|mimes| mimes.iter().any(|a| a == m.as_ref()))
|
||||
})
|
||||
});
|
||||
|
||||
dbg!(actions);
|
||||
dbg!(mime);
|
||||
|
||||
(r.rectangle.contains(x, y)
|
||||
&& (r.mime_types.is_empty() || mime.is_some())
|
||||
&& (r.actions.is_all()
|
||||
|
|
@ -118,7 +115,7 @@ where
|
|||
(actions, mime, dnd_state.as_ref())
|
||||
{
|
||||
dnd_state.set_actions(action, preferred_action);
|
||||
self.dnd_state.selected_mime = Some(mime_type.to_string());
|
||||
self.dnd_state.selected_mime = Some(mime_type.clone());
|
||||
dnd_state.accept_mime_type(dnd_state.serial, Some(mime_type.to_string()))
|
||||
}
|
||||
(s.clone(), Some(dest))
|
||||
|
|
@ -162,9 +159,9 @@ where
|
|||
};
|
||||
|
||||
dnd_state.set_actions(self.dnd_state.selected_action, self.dnd_state.selected_action);
|
||||
dnd_state.accept_mime_type(dnd_state.serial, Some(mime.clone()));
|
||||
dnd_state.accept_mime_type(dnd_state.serial, Some(mime.to_string()));
|
||||
|
||||
_ = self.load_dnd(MimeType::Other(mime.into()));
|
||||
_ = self.load_dnd(mime);
|
||||
}
|
||||
|
||||
pub(crate) fn offer_enter(
|
||||
|
|
@ -267,9 +264,6 @@ where
|
|||
.get_mut(latest)
|
||||
.ok_or_else(|| Error::new(ErrorKind::Other, "active seat lost"))?;
|
||||
|
||||
if !seat.has_focus {
|
||||
return Err(Error::new(ErrorKind::Other, "client doesn't have focus"));
|
||||
}
|
||||
let offer = seat
|
||||
.data_device
|
||||
.as_ref()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue