refactor: use icon type when starting dnd
This commit is contained in:
parent
5bfbaae180
commit
42a888736b
5 changed files with 43 additions and 9 deletions
|
|
@ -119,6 +119,18 @@ pub struct DndDestinationRectangle {
|
||||||
pub preferred: DndAction,
|
pub preferred: DndAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum Icon {
|
||||||
|
Surface(DndSurface),
|
||||||
|
/// Xrgb8888 or Argb8888 image data with premultiplied alpha
|
||||||
|
Buffer {
|
||||||
|
data: Arc<Vec<u8>>,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
transparent: bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DndSurface(pub Arc<Box<dyn RawSurface + 'static + Send + Sync>>);
|
pub struct DndSurface(pub Arc<Box<dyn RawSurface + 'static + Send + Sync>>);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::Cow, ffi::c_void, sync::Arc};
|
use std::{borrow::Cow, ffi::c_void, sync::Arc};
|
||||||
|
|
||||||
use crate::{DataWrapper, DndAction, DndSurface};
|
use crate::{DataWrapper, DndAction, DndSurface, Icon};
|
||||||
use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
|
use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
|
|
@ -87,3 +87,25 @@ impl From<DndAction>
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Icon> for smithay_clipboard::dnd::Icon<DndSurface> {
|
||||||
|
fn from(icon: Icon) -> Self {
|
||||||
|
match icon {
|
||||||
|
Icon::Surface(surface) => {
|
||||||
|
smithay_clipboard::dnd::Icon::Surface(surface)
|
||||||
|
}
|
||||||
|
Icon::Buffer {
|
||||||
|
data,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
transparent,
|
||||||
|
} => smithay_clipboard::dnd::Icon::Buf {
|
||||||
|
data: Arc::try_unwrap(data)
|
||||||
|
.unwrap_or_else(|d| d.as_ref().clone()),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
transparent,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use ::dnd::{DndAction, DndDestinationRectangle, Sender};
|
use ::dnd::{DndAction, DndDestinationRectangle, Sender};
|
||||||
use dnd::DndSurface;
|
use dnd::{DndSurface, Icon};
|
||||||
use mime::{AllowedMimeTypes, AsMimeTypes};
|
use mime::{AllowedMimeTypes, AsMimeTypes};
|
||||||
|
|
||||||
pub trait DndProvider {
|
pub trait DndProvider {
|
||||||
|
|
@ -17,7 +17,7 @@ pub trait DndProvider {
|
||||||
&self,
|
&self,
|
||||||
_internal: bool,
|
_internal: bool,
|
||||||
_source_surface: DndSurface,
|
_source_surface: DndSurface,
|
||||||
_icon_surface: Option<DndSurface>,
|
_icon_surface: Option<Icon>,
|
||||||
_content: D,
|
_content: D,
|
||||||
_actions: DndAction,
|
_actions: DndAction,
|
||||||
) {
|
) {
|
||||||
|
|
@ -64,7 +64,7 @@ impl<C: DndProvider> DndProvider for crate::PlatformClipboard<C> {
|
||||||
&self,
|
&self,
|
||||||
internal: bool,
|
internal: bool,
|
||||||
source_surface: DndSurface,
|
source_surface: DndSurface,
|
||||||
icon_surface: Option<DndSurface>,
|
icon_surface: Option<Icon>,
|
||||||
content: D,
|
content: D,
|
||||||
actions: DndAction,
|
actions: DndAction,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
ClipboardProvider,
|
ClipboardProvider,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dnd::{DndAction, DndDestinationRectangle, DndSurface};
|
use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon};
|
||||||
use mime::{AllowedMimeTypes, AsMimeTypes};
|
use mime::{AllowedMimeTypes, AsMimeTypes};
|
||||||
use raw_window_handle::{HasDisplayHandle, RawDisplayHandle};
|
use raw_window_handle::{HasDisplayHandle, RawDisplayHandle};
|
||||||
use std::{borrow::Cow, error::Error, sync::Arc};
|
use std::{borrow::Cow, error::Error, sync::Arc};
|
||||||
|
|
@ -144,7 +144,7 @@ impl DndProvider for Clipboard {
|
||||||
&self,
|
&self,
|
||||||
internal: bool,
|
internal: bool,
|
||||||
source_surface: DndSurface,
|
source_surface: DndSurface,
|
||||||
icon_surface: Option<DndSurface>,
|
icon_surface: Option<Icon>,
|
||||||
content: D,
|
content: D,
|
||||||
actions: DndAction,
|
actions: DndAction,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ use dnd::{
|
||||||
DataWrapper, DndAction, DndDestinationRectangle, DndSurface, Sender,
|
DataWrapper, DndAction, DndDestinationRectangle, DndSurface, Sender,
|
||||||
};
|
};
|
||||||
use mime::ClipboardData;
|
use mime::ClipboardData;
|
||||||
use smithay_clipboard::dnd::Rectangle;
|
use smithay_clipboard::dnd::{Icon, Rectangle};
|
||||||
pub use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
|
pub use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -214,14 +214,14 @@ impl Clipboard {
|
||||||
&self,
|
&self,
|
||||||
internal: bool,
|
internal: bool,
|
||||||
source_surface: DndSurface,
|
source_surface: DndSurface,
|
||||||
icon_surface: Option<DndSurface>,
|
icon_surface: Option<dnd::Icon>,
|
||||||
content: D,
|
content: D,
|
||||||
actions: DndAction,
|
actions: DndAction,
|
||||||
) {
|
) {
|
||||||
_ = self.context.lock().unwrap().start_dnd(
|
_ = self.context.lock().unwrap().start_dnd(
|
||||||
internal,
|
internal,
|
||||||
source_surface,
|
source_surface,
|
||||||
icon_surface,
|
icon_surface.map(|i| Icon::<DndSurface>::from(i)),
|
||||||
DataWrapper(content),
|
DataWrapper(content),
|
||||||
actions.into(),
|
actions.into(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue