From c6ed6bd6b0d29dfb3ef9d3afa914b11e2533e148 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 3 Nov 2024 18:51:50 +0100 Subject: [PATCH] wayland.selection: Remove TypeId in favor of DataDeviceKind --- src/wayland/selection/device.rs | 30 ++++++------------------------ src/wayland/selection/offer.rs | 12 ++++-------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/wayland/selection/device.rs b/src/wayland/selection/device.rs index 52e6e28a944a..2f5b65542515 100644 --- a/src/wayland/selection/device.rs +++ b/src/wayland/selection/device.rs @@ -1,6 +1,3 @@ -use std::any::Any; -use std::any::TypeId; - use wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1 as PrimaryDevice; use wayland_protocols_wlr::data_control::v1::server::zwlr_data_control_device_v1::ZwlrDataControlDeviceV1; use wayland_server::backend::ObjectId; @@ -18,7 +15,7 @@ use super::primary_selection::PrimaryDeviceUserData; use super::private::selection_dispatch; use super::wlr_data_control::DataControlDeviceUserData; -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub(super) enum DataDeviceKind { Core, Primary, @@ -26,20 +23,6 @@ pub(super) enum DataDeviceKind { ExtDataControl, } -impl DataDeviceKind { - pub(super) fn from_device_type_id(id: TypeId) -> Option { - let kind = match id { - _ if id == TypeId::of::() => Self::Core, - _ if id == TypeId::of::() => Self::Primary, - _ if id == TypeId::of::() => Self::WlrDataControl, - _ if id == TypeId::of::() => Self::ExtDataControl, - _ => return None, - }; - - Some(kind) - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum DataControlDevice { Wlr(ZwlrDataControlDeviceV1), @@ -123,13 +106,12 @@ impl SelectionDevice { selection_dispatch!(self; Self(device) => device.id()) } - /// Get the [`TypeId`] of the underlying data device provider. - pub fn inner_type_id(&self) -> TypeId { + pub fn device_kind(&self) -> DataDeviceKind { match self { - Self::DataDevice(device) => device.type_id(), - Self::Primary(device) => device.type_id(), - Self::DataControl(DataControlDevice::Wlr(device)) => device.type_id(), - Self::DataControl(DataControlDevice::Ext(device)) => device.type_id(), + Self::DataDevice(_) => DataDeviceKind::Core, + Self::Primary(_) => DataDeviceKind::Primary, + Self::DataControl(DataControlDevice::Wlr(_)) => DataDeviceKind::WlrDataControl, + Self::DataControl(DataControlDevice::Ext(_)) => DataDeviceKind::ExtDataControl, } } diff --git a/src/wayland/selection/offer.rs b/src/wayland/selection/offer.rs index d3360313b9a1..882262c7af70 100644 --- a/src/wayland/selection/offer.rs +++ b/src/wayland/selection/offer.rs @@ -1,4 +1,3 @@ -use std::any::TypeId; use std::os::unix::io::OwnedFd; use std::sync::Arc; @@ -95,16 +94,14 @@ impl SelectionOffer { // NOTE: the types are tied to the `SelectionDevice`, so every // RTTI like checking is safe and reliable. - let type_id = device.inner_type_id(); + let device_kind = device.device_kind(); let data = Arc::new(OfferReplyData { - type_id, + device_kind, seat: device.seat(), source: data, }); let backend = dh.backend_handle(); - let device_kind = DataDeviceKind::from_device_type_id(type_id).unwrap(); - let interface = match device_kind { DataDeviceKind::Core => WlDataOffer::interface(), DataDeviceKind::Primary => PrimaryOffer::interface(), @@ -134,7 +131,7 @@ impl SelectionOffer { } struct OfferReplyData { - type_id: TypeId, + device_kind: DataDeviceKind, source: OfferReplySource, seat: WlSeat, } @@ -151,12 +148,11 @@ where msg: Message, ) -> Option>> { let dh = DisplayHandle::from(dh.clone()); - let type_id = self.type_id; // NOTE: we can't parse message more than once, since it expects the `OwnedFd` which // we can't clone. To achieve that, we use RTTI passed along the selection data, to // make the parsing work only once. - let (mime_type, fd, object_name) = match DataDeviceKind::from_device_type_id(type_id)? { + let (mime_type, fd, object_name) = match self.device_kind { DataDeviceKind::Core => { if let Ok((_resource, DataOfferRequest::Receive { mime_type, fd })) = WlDataOffer::parse_request(&dh, msg)