1
0
Fork 0
forked from wry/wry

xwayland: implement copy/paste

This commit is contained in:
Julian Orth 2022-05-10 01:47:10 +02:00
parent c8068ee2e7
commit d6fabcb2b5
22 changed files with 1565 additions and 380 deletions

View file

@ -2,13 +2,14 @@ use {
crate::{
client::{Client, ClientError},
ifs::ipc::{
add_mime_type, break_source_loops, destroy_source,
zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1, SourceData,
add_data_source_mime_type, break_source_loops, destroy_data_source,
zwp_primary_selection_device_v1::PrimarySelectionIpc, SourceData,
},
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
wire::{zwp_primary_selection_source_v1::*, ZwpPrimarySelectionSourceV1Id},
xwayland::XWaylandEvent,
},
std::rc::Rc,
thiserror::Error,
@ -17,40 +18,62 @@ use {
pub struct ZwpPrimarySelectionSourceV1 {
pub id: ZwpPrimarySelectionSourceV1Id,
pub data: SourceData<ZwpPrimarySelectionDeviceV1>,
pub data: SourceData<PrimarySelectionIpc>,
pub tracker: Tracker<Self>,
}
impl ZwpPrimarySelectionSourceV1 {
pub fn new(id: ZwpPrimarySelectionSourceV1Id, client: &Rc<Client>) -> Self {
pub fn new(id: ZwpPrimarySelectionSourceV1Id, client: &Rc<Client>, is_xwm: bool) -> Self {
Self {
id,
data: SourceData::new(client),
data: SourceData::new(client, is_xwm),
tracker: Default::default(),
}
}
pub fn send_cancelled(&self) {
self.data.client.event(Cancelled { self_id: self.id })
pub fn send_cancelled(self: &Rc<Self>) {
if self.data.is_xwm {
self.data
.client
.state
.xwayland
.queue
.push(XWaylandEvent::PrimarySelectionCancelSource(self.clone()));
} else {
self.data.client.event(Cancelled { self_id: self.id });
}
}
pub fn send_send(&self, mime_type: &str, fd: Rc<OwnedFd>) {
self.data.client.event(Send {
self_id: self.id,
mime_type,
fd,
})
pub fn send_send(self: &Rc<Self>, mime_type: &str, fd: Rc<OwnedFd>) {
if self.data.is_xwm {
self.data
.client
.state
.xwayland
.queue
.push(XWaylandEvent::PrimarySelectionSendSource(
self.clone(),
mime_type.to_string(),
fd,
));
} else {
self.data.client.event(Send {
self_id: self.id,
mime_type,
fd,
})
}
}
fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionSourceV1Error> {
let req: Offer = self.data.client.parse(self, parser)?;
add_mime_type::<ZwpPrimarySelectionDeviceV1>(self, req.mime_type);
add_data_source_mime_type::<PrimarySelectionIpc>(self, req.mime_type);
Ok(())
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpPrimarySelectionSourceV1Error> {
let _req: Destroy = self.data.client.parse(self, parser)?;
destroy_source::<ZwpPrimarySelectionDeviceV1>(self);
destroy_data_source::<PrimarySelectionIpc>(self);
self.data.client.remove_obj(self)?;
Ok(())
}
@ -69,7 +92,7 @@ impl Object for ZwpPrimarySelectionSourceV1 {
}
fn break_loops(&self) {
break_source_loops::<ZwpPrimarySelectionDeviceV1>(self);
break_source_loops::<PrimarySelectionIpc>(self);
}
}