mirror of
https://github.com/wez/wezterm.git
synced 2024-08-17 02:00:25 +03:00
Drop old primary selection code
This commit is contained in:
parent
004bfd3d9e
commit
b1069576b7
@ -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<PrimaryInner>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct PrimaryInner {
|
||||
pending_offer: Option<ZwpPrimarySelectionOfferV1>,
|
||||
offer: Option<ZwpPrimarySelectionOfferV1>,
|
||||
valid_mime: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct PrimarySelectionManagerData {}
|
||||
|
||||
impl PrimarySelectionManagerState {
|
||||
pub(super) fn bind(
|
||||
globals: &GlobalList,
|
||||
queue_handle: &wayland_client::QueueHandle<WaylandState>,
|
||||
) -> Result<Self, BindError> {
|
||||
let manager = globals.bind(queue_handle, 1..=1, GlobalData)?;
|
||||
Ok(Self {
|
||||
manager,
|
||||
inner: Mutex::new(PrimaryInner::default()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpPrimarySelectionDeviceManagerV1, GlobalData, WaylandState>
|
||||
for PrimarySelectionManagerState
|
||||
{
|
||||
fn event(
|
||||
_state: &mut WaylandState,
|
||||
_proxy: &ZwpPrimarySelectionDeviceManagerV1,
|
||||
_event: <ZwpPrimarySelectionDeviceManagerV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &wayland_client::Connection,
|
||||
_qhandle: &wayland_client::QueueHandle<WaylandState>,
|
||||
) {
|
||||
unreachable!("primary selection manager has no events");
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpPrimarySelectionSourceV1, PrimarySelectionManagerData, WaylandState>
|
||||
for PrimarySelectionManagerState
|
||||
{
|
||||
fn event(
|
||||
state: &mut WaylandState,
|
||||
source: &ZwpPrimarySelectionSourceV1,
|
||||
event: <ZwpPrimarySelectionSourceV1 as wayland_client::Proxy>::Event,
|
||||
_data: &PrimarySelectionManagerData,
|
||||
_conn: &wayland_client::Connection,
|
||||
_qhandle: &wayland_client::QueueHandle<WaylandState>,
|
||||
) {
|
||||
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<ZwpPrimarySelectionOfferV1, PrimarySelectionManagerData, WaylandState>
|
||||
for PrimarySelectionManagerState
|
||||
{
|
||||
fn event(
|
||||
state: &mut WaylandState,
|
||||
_proxy: &ZwpPrimarySelectionOfferV1,
|
||||
event: <ZwpPrimarySelectionOfferV1 as wayland_client::Proxy>::Event,
|
||||
_data: &PrimarySelectionManagerData,
|
||||
_conn: &wayland_client::Connection,
|
||||
_qhandle: &wayland_client::QueueHandle<WaylandState>,
|
||||
) {
|
||||
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<ZwpPrimarySelectionDeviceV1, PrimarySelectionManagerData, WaylandState>
|
||||
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: <ZwpPrimarySelectionDeviceV1 as wayland_client::Proxy>::Event,
|
||||
_data: &PrimarySelectionManagerData,
|
||||
_conn: &wayland_client::Connection,
|
||||
_qhandle: &wayland_client::QueueHandle<WaylandState>,
|
||||
) {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user