1
0
Fork 0
forked from wry/wry

ipc: create separate offers/sources for X

This commit is contained in:
Julian Orth 2024-03-31 18:42:23 +02:00
parent 4e9dacce1a
commit 8bca8b0e86
19 changed files with 830 additions and 552 deletions

View file

@ -4,9 +4,10 @@ use {
ifs::{
ipc::{
add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source,
detach_seat, offer_source_to,
detach_seat, offer_source_to_regular_client, offer_source_to_x,
wl_data_device::ClipboardIpc,
wl_data_device_manager::{DND_ALL, DND_NONE},
x_data_device::{XClipboardIpc, XIpcDevice},
DataSource, DynDataOffer, DynDataSource, SharedState, SourceData,
OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, SOURCE_STATE_CANCELLED,
SOURCE_STATE_DROPPED,
@ -23,7 +24,6 @@ use {
clonecell::CloneCell,
},
wire::{wl_data_source::*, WlDataSourceId},
xwayland::XWaylandEvent,
},
std::rc::Rc,
thiserror::Error,
@ -44,7 +44,7 @@ pub struct WlDataSource {
}
impl DataSource for WlDataSource {
fn send_cancelled(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>) {
fn send_cancelled(&self, seat: &Rc<WlSeatGlobal>) {
WlDataSource::send_cancelled(self, seat);
}
}
@ -54,20 +54,24 @@ impl DynDataSource for WlDataSource {
&self.data
}
fn send_send(self: Rc<Self>, mime_type: &str, fd: Rc<OwnedFd>) {
WlDataSource::send_send(&self, mime_type, fd);
fn send_send(&self, mime_type: &str, fd: Rc<OwnedFd>) {
WlDataSource::send_send(self, mime_type, fd);
}
fn offer_to(self: Rc<Self>, client: &Rc<Client>) {
offer_source_to::<ClipboardIpc, Self>(&self, client);
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>) {
offer_source_to_regular_client::<ClipboardIpc, Self>(&self, client);
}
fn detach_seat(self: Rc<Self>, seat: &Rc<WlSeatGlobal>) {
detach_seat::<ClipboardIpc>(&self, seat);
fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) {
offer_source_to_x::<XClipboardIpc, Self>(&self, dd);
}
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {
detach_seat(self, seat);
}
fn cancel_offers(&self) {
cancel_offers::<ClipboardIpc>(self);
cancel_offers(self);
}
fn send_target(&self, mime_type: Option<&str>) {
@ -84,11 +88,11 @@ impl DynDataSource for WlDataSource {
}
impl WlDataSource {
pub fn new(id: WlDataSourceId, client: &Rc<Client>, is_xwm: bool, version: u32) -> Self {
pub fn new(id: WlDataSourceId, client: &Rc<Client>, version: u32) -> Self {
Self {
id,
tracker: Default::default(),
data: SourceData::new(client, is_xwm),
data: SourceData::new(client),
version,
toplevel_drag: Default::default(),
}
@ -108,7 +112,7 @@ impl WlDataSource {
self.data.shared.set(Rc::new(SharedState::default()));
self.send_target(None);
self.send_action(DND_NONE);
cancel_offers::<ClipboardIpc>(self);
cancel_offers(self);
}
pub fn update_selected_action(&self) {
@ -159,74 +163,44 @@ impl WlDataSource {
shared.state.or_assign(OFFER_STATE_DROPPED);
}
pub fn send_cancelled(self: &Rc<Self>, seat: &Rc<WlSeatGlobal>) {
if self.data.is_xwm {
self.data
.client
.state
.xwayland
.queue
.push(XWaylandEvent::ClipboardCancelSource(self.clone()));
} else {
self.data.state.or_assign(SOURCE_STATE_CANCELLED);
if let Some(drag) = self.toplevel_drag.take() {
drag.finish_drag(seat);
}
self.data.client.event(Cancelled { self_id: self.id })
pub fn send_cancelled(&self, seat: &Rc<WlSeatGlobal>) {
self.data.state.or_assign(SOURCE_STATE_CANCELLED);
if let Some(drag) = self.toplevel_drag.take() {
drag.finish_drag(seat);
}
self.data.client.event(Cancelled { self_id: self.id })
}
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::ClipboardSendSource(
self.clone(),
mime_type.to_string(),
fd,
));
} else {
self.data.client.event(Send {
self_id: self.id,
mime_type,
fd,
})
}
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_target(&self, mime_type: Option<&str>) {
if !self.data.is_xwm {
self.data.client.event(Target {
self_id: self.id,
mime_type,
})
}
self.data.client.event(Target {
self_id: self.id,
mime_type,
})
}
pub fn send_dnd_finished(&self) {
if !self.data.is_xwm {
self.data.client.event(DndFinished { self_id: self.id })
}
self.data.client.event(DndFinished { self_id: self.id })
}
pub fn send_action(&self, dnd_action: u32) {
if !self.data.is_xwm {
self.data.client.event(Action {
self_id: self.id,
dnd_action,
})
}
self.data.client.event(Action {
self_id: self.id,
dnd_action,
})
}
pub fn send_dnd_drop_performed(&self) {
if !self.data.is_xwm {
self.data
.client
.event(DndDropPerformed { self_id: self.id })
}
self.data
.client
.event(DndDropPerformed { self_id: self.id })
}
fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), WlDataSourceError> {