diff --git a/window/src/os/wayland/copy_and_paste.rs b/window/src/os/wayland/copy_and_paste.rs index 23f07fb18..fce9b75e7 100644 --- a/window/src/os/wayland/copy_and_paste.rs +++ b/window/src/os/wayland/copy_and_paste.rs @@ -154,157 +154,6 @@ fn write_pipe_with_timeout(mut file: WritePipe, data: &[u8]) -> anyhow::Result<( Ok(()) } -/* - -// Smithay has their own primary selection handler in 0.18 -// Some code borrowed from https://github.com/Smithay/client-toolkit/commit/4a5c4f59f640bc588a55277261bbed1bd2abea98 -pub(super) struct PrimarySelectionManagerState { - pub(super) manager: ZwpPrimarySelectionDeviceManagerV1, - inner: Mutex, -} - -#[derive(Default, Debug)] -struct PrimaryInner { - pending_offer: Option, - offer: Option, - valid_mime: bool, -} - -#[derive(Default)] -pub(super) struct PrimarySelectionManagerData {} - -impl PrimarySelectionManagerState { - pub(super) fn bind( - globals: &GlobalList, - queue_handle: &wayland_client::QueueHandle, - ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; - Ok(Self { - manager, - inner: Mutex::new(PrimaryInner::default()), - }) - } -} - -impl Dispatch - for PrimarySelectionManagerState -{ - fn event( - _state: &mut WaylandState, - _proxy: &ZwpPrimarySelectionDeviceManagerV1, - _event: ::Event, - _data: &GlobalData, - _conn: &wayland_client::Connection, - _qhandle: &wayland_client::QueueHandle, - ) { - unreachable!("primary selection manager has no events"); - } -} - -impl Dispatch - for PrimarySelectionManagerState -{ - fn event( - state: &mut WaylandState, - source: &ZwpPrimarySelectionSourceV1, - event: ::Event, - _data: &PrimarySelectionManagerData, - _conn: &wayland_client::Connection, - _qhandle: &wayland_client::QueueHandle, - ) { - match event { - PrimarySelectionSourceEvent::Send { mime_type, fd } => { - if mime_type != TEXT_MIME_TYPE { - return; - }; - - if let Some((ps_source, data)) = &state.primary_selection_source { - if ps_source != source { - return; - } - let fd = unsafe { FileDescriptor::from_raw_fd(fd.into_raw_fd()) }; - write_selection_to_pipe(fd, data); - } - } - PrimarySelectionSourceEvent::Cancelled => { - state.primary_selection_source.take(); - source.destroy(); - } - _ => unreachable!(), - } - } -} - -impl Dispatch - for PrimarySelectionManagerState -{ - fn event( - state: &mut WaylandState, - _proxy: &ZwpPrimarySelectionOfferV1, - event: ::Event, - _data: &PrimarySelectionManagerData, - _conn: &wayland_client::Connection, - _qhandle: &wayland_client::QueueHandle, - ) { - match event { - PrimarySelectionOfferEvent::Offer { mime_type } => { - if mime_type == TEXT_MIME_TYPE { - let mgr = state.primary_selection_manager.as_ref().unwrap(); - let mut inner = mgr.inner.lock().unwrap(); - inner.valid_mime = true; - } - } - _ => unreachable!(), - } - } -} - -impl Dispatch - for PrimarySelectionManagerState -{ - event_created_child!(WaylandState, ZwpPrimarySelectionDeviceV1, [ - zwp_primary_selection_device_v1::EVT_DATA_OFFER_OPCODE => (ZwpPrimarySelectionOfferV1, PrimarySelectionManagerData::default()) - ]); - - fn event( - state: &mut WaylandState, - _primary_selection_device: &ZwpPrimarySelectionDeviceV1, - event: ::Event, - _data: &PrimarySelectionManagerData, - _conn: &wayland_client::Connection, - _qhandle: &wayland_client::QueueHandle, - ) { - let psm = state.primary_selection_manager.as_ref().unwrap(); - let mut inner = psm.inner.lock().unwrap(); - match event { - PrimarySelectionDeviceEvent::DataOffer { offer } => { - inner.pending_offer = Some(offer); - } - PrimarySelectionDeviceEvent::Selection { id } => { - if !inner.valid_mime { - return; - } - - if let Some(offer) = inner.offer.take() { - offer.destroy(); - } - if id == inner.pending_offer { - inner.offer = inner.pending_offer.take(); - } else { - // Remove the pending offer, assign the new delivered one. - if let Some(offer) = inner.pending_offer.take() { - offer.destroy() - } - - inner.offer = id; - } - } - _ => unreachable!(), - } - } -} -*/ - impl PrimarySelectionDeviceHandler for WaylandState { fn selection( &mut self,