From 42a888736be51bd8b234060d0a75503184ecad9f Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 27 Mar 2024 18:28:59 -0400 Subject: [PATCH] refactor: use icon type when starting dnd --- dnd/src/lib.rs | 12 ++++++++++++ dnd/src/platform/linux.rs | 24 +++++++++++++++++++++++- src/dnd/mod.rs | 6 +++--- src/platform/linux.rs | 4 ++-- wayland/src/lib.rs | 6 +++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/dnd/src/lib.rs b/dnd/src/lib.rs index 1a17bd8..c1b7ac3 100644 --- a/dnd/src/lib.rs +++ b/dnd/src/lib.rs @@ -119,6 +119,18 @@ pub struct DndDestinationRectangle { pub preferred: DndAction, } +#[derive(Clone)] +pub enum Icon { + Surface(DndSurface), + /// Xrgb8888 or Argb8888 image data with premultiplied alpha + Buffer { + data: Arc>, + width: u32, + height: u32, + transparent: bool, + }, +} + #[derive(Clone)] pub struct DndSurface(pub Arc>); diff --git a/dnd/src/platform/linux.rs b/dnd/src/platform/linux.rs index 9036dd0..5a5766e 100644 --- a/dnd/src/platform/linux.rs +++ b/dnd/src/platform/linux.rs @@ -1,6 +1,6 @@ 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}; impl< @@ -87,3 +87,25 @@ impl From a } } + +impl From for smithay_clipboard::dnd::Icon { + 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, + }, + } + } +} diff --git a/src/dnd/mod.rs b/src/dnd/mod.rs index f06f0d1..b145ca0 100644 --- a/src/dnd/mod.rs +++ b/src/dnd/mod.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use ::dnd::{DndAction, DndDestinationRectangle, Sender}; -use dnd::DndSurface; +use dnd::{DndSurface, Icon}; use mime::{AllowedMimeTypes, AsMimeTypes}; pub trait DndProvider { @@ -17,7 +17,7 @@ pub trait DndProvider { &self, _internal: bool, _source_surface: DndSurface, - _icon_surface: Option, + _icon_surface: Option, _content: D, _actions: DndAction, ) { @@ -64,7 +64,7 @@ impl DndProvider for crate::PlatformClipboard { &self, internal: bool, source_surface: DndSurface, - icon_surface: Option, + icon_surface: Option, content: D, actions: DndAction, ) { diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 9ea9b41..734f8f6 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -4,7 +4,7 @@ use crate::{ ClipboardProvider, }; -use dnd::{DndAction, DndDestinationRectangle, DndSurface}; +use dnd::{DndAction, DndDestinationRectangle, DndSurface, Icon}; use mime::{AllowedMimeTypes, AsMimeTypes}; use raw_window_handle::{HasDisplayHandle, RawDisplayHandle}; use std::{borrow::Cow, error::Error, sync::Arc}; @@ -144,7 +144,7 @@ impl DndProvider for Clipboard { &self, internal: bool, source_surface: DndSurface, - icon_surface: Option, + icon_surface: Option, content: D, actions: DndAction, ) { diff --git a/wayland/src/lib.rs b/wayland/src/lib.rs index ae94714..deb59d9 100644 --- a/wayland/src/lib.rs +++ b/wayland/src/lib.rs @@ -23,7 +23,7 @@ use dnd::{ DataWrapper, DndAction, DndDestinationRectangle, DndSurface, Sender, }; use mime::ClipboardData; -use smithay_clipboard::dnd::Rectangle; +use smithay_clipboard::dnd::{Icon, Rectangle}; pub use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType}; #[derive(Clone)] @@ -214,14 +214,14 @@ impl Clipboard { &self, internal: bool, source_surface: DndSurface, - icon_surface: Option, + icon_surface: Option, content: D, actions: DndAction, ) { _ = self.context.lock().unwrap().start_dnd( internal, source_surface, - icon_surface, + icon_surface.map(|i| Icon::::from(i)), DataWrapper(content), actions.into(), );