1
0
Fork 0
forked from wry/wry

ipc: remove DynDataSource::offer_to_regular/wlr

This commit is contained in:
Julian Orth 2024-10-08 14:51:37 +02:00
parent 487efafdf5
commit 40f7bc2542
8 changed files with 31 additions and 110 deletions

View file

@ -64,9 +64,7 @@ pub trait DataSource: DynDataSource {
pub trait DynDataSource: 'static { pub trait DynDataSource: 'static {
fn source_data(&self) -> &SourceData; fn source_data(&self) -> &SourceData;
fn send_send(&self, mime_type: &str, fd: Rc<OwnedFd>); fn send_send(&self, mime_type: &str, fd: Rc<OwnedFd>);
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>);
fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>); fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>);
fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>);
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>); fn detach_seat(&self, seat: &Rc<WlSeatGlobal>);
fn cancel_unprivileged_offers(&self); fn cancel_unprivileged_offers(&self);
@ -315,8 +313,8 @@ pub fn detach_seat<S: DataSource>(src: &S, seat: &Rc<WlSeatGlobal>) {
// data.client.flush(); // data.client.flush();
} }
fn offer_source_to_device<T: IpcVtable, S: DynDataSource>( fn offer_source_to_device<T: IpcVtable>(
src: &Rc<S>, src: &Rc<dyn DynDataSource>,
dd: &Rc<T::Device>, dd: &Rc<T::Device>,
data: &SourceData, data: &SourceData,
shared: Rc<SharedState>, shared: Rc<SharedState>,
@ -351,31 +349,29 @@ fn offer_source_to_device<T: IpcVtable, S: DynDataSource>(
} }
} }
fn offer_source_to_x<T, S>(src: &Rc<S>, dd: &Rc<XIpcDevice>) fn offer_source_to_x<T>(src: Rc<dyn DynDataSource>, dd: &Rc<XIpcDevice>)
where where
T: IpcVtable<Device = XIpcDevice>, T: IpcVtable<Device = XIpcDevice>,
S: DynDataSource,
{ {
let data = src.source_data(); let data = src.source_data();
src.cancel_unprivileged_offers(); src.cancel_unprivileged_offers();
let shared = data.shared.get(); let shared = data.shared.get();
shared.role.set(data.role.get()); shared.role.set(data.role.get());
offer_source_to_device::<T, S>(src, dd, data, shared); offer_source_to_device::<T>(&src, dd, data, shared);
} }
pub fn offer_source_to_wlr_device<T, S>(src: &Rc<S>, dd: &Rc<T::Device>) pub fn offer_source_to_wlr_device<T>(src: Rc<dyn DynDataSource>, dd: &Rc<T::Device>)
where where
T: IpcVtable<Device = ZwlrDataControlDeviceV1>, T: IpcVtable<Device = ZwlrDataControlDeviceV1>,
S: DynDataSource,
{ {
let data = src.source_data(); let data = src.source_data();
let shared = data.shared.get(); let shared = data.shared.get();
shared.role.set(data.role.get()); shared.role.set(data.role.get());
offer_source_to_device::<T, _>(src, dd, data, shared); offer_source_to_device::<T>(&src, dd, data, shared);
} }
fn offer_source_to_regular_client<T: IterableIpcVtable, S: DynDataSource>( pub fn offer_source_to_regular_client<T: IterableIpcVtable>(
src: &Rc<S>, src: Rc<dyn DynDataSource>,
client: &Rc<Client>, client: &Rc<Client>,
) { ) {
let data = src.source_data(); let data = src.source_data();
@ -390,7 +386,7 @@ fn offer_source_to_regular_client<T: IterableIpcVtable, S: DynDataSource>(
let shared = data.shared.get(); let shared = data.shared.get();
shared.role.set(data.role.get()); shared.role.set(data.role.get());
T::for_each_device(&seat, client.id, |dd| { T::for_each_device(&seat, client.id, |dd| {
offer_source_to_device::<T, S>(src, dd, data, shared.clone()); offer_source_to_device::<T>(&src, dd, data, shared.clone());
}); });
} }

View file

@ -4,12 +4,10 @@ use {
ifs::{ ifs::{
ipc::{ ipc::{
add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source, add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source,
detach_seat, offer_source_to_regular_client, offer_source_to_wlr_device, detach_seat, offer_source_to_x,
offer_source_to_x,
wl_data_device::ClipboardIpc, wl_data_device::ClipboardIpc,
wl_data_device_manager::{DND_ALL, DND_NONE}, wl_data_device_manager::{DND_ALL, DND_NONE},
x_data_device::{XClipboardIpc, XIpcDevice}, x_data_device::{XClipboardIpc, XIpcDevice},
zwlr_data_control_device_v1::{WlrClipboardIpc, ZwlrDataControlDeviceV1},
DataSource, DynDataOffer, DynDataSource, SharedState, SourceData, DataSource, DynDataOffer, DynDataSource, SharedState, SourceData,
OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, SOURCE_STATE_CANCELLED, OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, SOURCE_STATE_CANCELLED,
SOURCE_STATE_DROPPED, SOURCE_STATE_DROPPED,
@ -55,16 +53,8 @@ impl DynDataSource for WlDataSource {
WlDataSource::send_send(self, mime_type, fd); WlDataSource::send_send(self, mime_type, fd);
} }
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>) {
offer_source_to_regular_client::<ClipboardIpc, Self>(&self, client);
}
fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) { fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) {
offer_source_to_x::<XClipboardIpc, Self>(&self, dd); offer_source_to_x::<XClipboardIpc>(self, dd);
}
fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
offer_source_to_wlr_device::<WlrClipboardIpc, Self>(&self, dd)
} }
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) { fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {

View file

@ -1,17 +1,9 @@
use { use {
crate::{ crate::{
client::Client,
ifs::{ ifs::{
ipc::{ ipc::{
cancel_offers, detach_seat, offer_source_to_regular_client, cancel_offers, detach_seat, x_data_device::XIpcDevice, DataSource, DynDataSource,
offer_source_to_wlr_device, IpcLocation, SourceData,
wl_data_device::ClipboardIpc,
x_data_device::XIpcDevice,
zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
},
zwp_primary_selection_device_v1::PrimarySelectionIpc,
DataSource, DynDataSource, IpcLocation, SourceData,
}, },
wl_seat::WlSeatGlobal, wl_seat::WlSeatGlobal,
}, },
@ -54,17 +46,6 @@ impl DynDataSource for XDataSource {
}); });
} }
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>) {
match self.location {
IpcLocation::Clipboard => {
offer_source_to_regular_client::<ClipboardIpc, Self>(&self, client)
}
IpcLocation::PrimarySelection => {
offer_source_to_regular_client::<PrimarySelectionIpc, Self>(&self, client)
}
}
}
fn offer_to_x(self: Rc<Self>, _dd: &Rc<XIpcDevice>) { fn offer_to_x(self: Rc<Self>, _dd: &Rc<XIpcDevice>) {
self.cancel_unprivileged_offers(); self.cancel_unprivileged_offers();
self.state.xwayland.queue.push(IpcSetSelection { self.state.xwayland.queue.push(IpcSetSelection {
@ -74,17 +55,6 @@ impl DynDataSource for XDataSource {
}); });
} }
fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
match self.location {
IpcLocation::Clipboard => {
offer_source_to_wlr_device::<WlrClipboardIpc, Self>(&self, dd)
}
IpcLocation::PrimarySelection => {
offer_source_to_wlr_device::<WlrPrimarySelectionIpc, Self>(&self, dd)
}
}
}
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) { fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {
detach_seat(self, seat); detach_seat(self, seat);
} }

View file

@ -3,7 +3,11 @@ use {
client::{Client, ClientCaps, ClientError, CAP_DATA_CONTROL_MANAGER}, client::{Client, ClientCaps, ClientError, CAP_DATA_CONTROL_MANAGER},
globals::{Global, GlobalName}, globals::{Global, GlobalName},
ifs::ipc::{ ifs::ipc::{
zwlr_data_control_device_v1::{ZwlrDataControlDeviceV1, PRIMARY_SELECTION_SINCE}, offer_source_to_wlr_device,
zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
PRIMARY_SELECTION_SINCE,
},
zwlr_data_control_source_v1::ZwlrDataControlSourceV1, zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
}, },
leaks::Tracker, leaks::Tracker,
@ -78,12 +82,12 @@ impl ZwlrDataControlManagerV1RequestHandler for ZwlrDataControlManagerV1 {
seat.global.add_wlr_device(&dev); seat.global.add_wlr_device(&dev);
self.client.add_client_obj(&dev)?; self.client.add_client_obj(&dev)?;
match seat.global.get_selection() { match seat.global.get_selection() {
Some(s) => s.offer_to_wlr_device(&dev), Some(s) => offer_source_to_wlr_device::<WlrClipboardIpc>(s, &dev),
_ => dev.send_selection(None), _ => dev.send_selection(None),
} }
if self.version >= PRIMARY_SELECTION_SINCE { if self.version >= PRIMARY_SELECTION_SINCE {
match seat.global.get_primary_selection() { match seat.global.get_primary_selection() {
Some(s) => s.offer_to_wlr_device(&dev), Some(s) => offer_source_to_wlr_device::<WlrPrimarySelectionIpc>(s, &dev),
_ => dev.send_primary_selection(None), _ => dev.send_primary_selection(None),
} }
} }

View file

@ -4,14 +4,9 @@ use {
ifs::{ ifs::{
ipc::{ ipc::{
add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source, add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source,
detach_seat, offer_source_to_regular_client, offer_source_to_wlr_device, detach_seat, offer_source_to_x,
offer_source_to_x,
wl_data_device::ClipboardIpc,
x_data_device::{XClipboardIpc, XIpcDevice, XPrimarySelectionIpc}, x_data_device::{XClipboardIpc, XIpcDevice, XPrimarySelectionIpc},
zwlr_data_control_device_v1::{ zwlr_data_control_device_v1::{WlrClipboardIpc, WlrPrimarySelectionIpc},
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
},
zwp_primary_selection_device_v1::PrimarySelectionIpc,
DataSource, DynDataSource, IpcLocation, SourceData, DataSource, DynDataSource, IpcLocation, SourceData,
}, },
wl_seat::WlSeatGlobal, wl_seat::WlSeatGlobal,
@ -49,34 +44,10 @@ impl DynDataSource for ZwlrDataControlSourceV1 {
ZwlrDataControlSourceV1::send_send(&self, mime_type, fd); ZwlrDataControlSourceV1::send_send(&self, mime_type, fd);
} }
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>) {
match self.location.get() {
IpcLocation::Clipboard => {
offer_source_to_regular_client::<ClipboardIpc, Self>(&self, client)
}
IpcLocation::PrimarySelection => {
offer_source_to_regular_client::<PrimarySelectionIpc, Self>(&self, client)
}
}
}
fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) { fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) {
match self.location.get() { match self.location.get() {
IpcLocation::Clipboard => offer_source_to_x::<XClipboardIpc, Self>(&self, dd), IpcLocation::Clipboard => offer_source_to_x::<XClipboardIpc>(self, dd),
IpcLocation::PrimarySelection => { IpcLocation::PrimarySelection => offer_source_to_x::<XPrimarySelectionIpc>(self, dd),
offer_source_to_x::<XPrimarySelectionIpc, Self>(&self, dd)
}
}
}
fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
match self.location.get() {
IpcLocation::Clipboard => {
offer_source_to_wlr_device::<WlrClipboardIpc, Self>(&self, dd)
}
IpcLocation::PrimarySelection => {
offer_source_to_wlr_device::<WlrPrimarySelectionIpc, Self>(&self, dd)
}
} }
} }

View file

@ -4,10 +4,8 @@ use {
ifs::{ ifs::{
ipc::{ ipc::{
add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source, add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source,
detach_seat, offer_source_to_regular_client, offer_source_to_wlr_device, detach_seat, offer_source_to_x,
offer_source_to_x,
x_data_device::{XIpcDevice, XPrimarySelectionIpc}, x_data_device::{XIpcDevice, XPrimarySelectionIpc},
zwlr_data_control_device_v1::{WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1},
zwp_primary_selection_device_v1::PrimarySelectionIpc, zwp_primary_selection_device_v1::PrimarySelectionIpc,
DataSource, DynDataSource, SourceData, DataSource, DynDataSource, SourceData,
}, },
@ -44,16 +42,8 @@ impl DynDataSource for ZwpPrimarySelectionSourceV1 {
ZwpPrimarySelectionSourceV1::send_send(self, mime_type, fd) ZwpPrimarySelectionSourceV1::send_send(self, mime_type, fd)
} }
fn offer_to_regular_client(self: Rc<Self>, client: &Rc<Client>) {
offer_source_to_regular_client::<PrimarySelectionIpc, Self>(&self, client);
}
fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) { fn offer_to_x(self: Rc<Self>, dd: &Rc<XIpcDevice>) {
offer_source_to_x::<XPrimarySelectionIpc, Self>(&self, dd); offer_source_to_x::<XPrimarySelectionIpc>(self, dd);
}
fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
offer_source_to_wlr_device::<WlrPrimarySelectionIpc, Self>(&self, dd)
} }
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) { fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {

View file

@ -32,7 +32,7 @@ use {
ifs::{ ifs::{
ext_idle_notification_v1::ExtIdleNotificationV1, ext_idle_notification_v1::ExtIdleNotificationV1,
ipc::{ ipc::{
self, self, offer_source_to_regular_client, offer_source_to_wlr_device,
wl_data_device::{ClipboardIpc, WlDataDevice}, wl_data_device::{ClipboardIpc, WlDataDevice},
wl_data_source::WlDataSource, wl_data_source::WlDataSource,
x_data_device::{XClipboardIpc, XIpcDevice, XIpcDeviceId, XPrimarySelectionIpc}, x_data_device::{XClipboardIpc, XIpcDevice, XIpcDeviceId, XPrimarySelectionIpc},
@ -739,7 +739,7 @@ impl WlSeatGlobal {
// client.flush(); // client.flush();
} }
W::for_each_device(self, |device| match &src { W::for_each_device(self, |device| match &src {
Some(src) => src.clone().offer_to_wlr_device(device), Some(src) => offer_source_to_wlr_device::<W>(src.clone(), device),
_ => W::send_selection(device, None), _ => W::send_selection(device, None),
}); });
Ok(()) Ok(())
@ -763,7 +763,7 @@ impl WlSeatGlobal {
}); });
} else { } else {
match selection { match selection {
Some(src) => src.offer_to_regular_client(client), Some(src) => offer_source_to_regular_client::<T>(src, client),
_ => T::for_each_device(self, client.id, |device| { _ => T::for_each_device(self, client.id, |device| {
T::send_selection(device, None); T::send_selection(device, None);
}), }),

View file

@ -9,13 +9,13 @@ use {
fixed::Fixed, fixed::Fixed,
ifs::{ ifs::{
ipc::{ ipc::{
offer_source_to_regular_client,
wl_data_device::{ClipboardIpc, WlDataDevice}, wl_data_device::{ClipboardIpc, WlDataDevice},
x_data_device::{XClipboardIpc, XPrimarySelectionIpc}, x_data_device::{XClipboardIpc, XPrimarySelectionIpc},
zwlr_data_control_device_v1::ZwlrDataControlDeviceV1, zwlr_data_control_device_v1::ZwlrDataControlDeviceV1,
zwp_primary_selection_device_v1::{ zwp_primary_selection_device_v1::{
PrimarySelectionIpc, ZwpPrimarySelectionDeviceV1, PrimarySelectionIpc, ZwpPrimarySelectionDeviceV1,
}, },
DynDataSource,
}, },
wl_seat::{ wl_seat::{
tablet::{TabletPad, TabletPadId, TabletTool, TabletToolId}, tablet::{TabletPad, TabletPadId, TabletTool, TabletToolId},
@ -1445,7 +1445,7 @@ impl WlSeatGlobal {
) { ) {
if let Some(src) = &dnd.src { if let Some(src) = &dnd.src {
if !surface.client.is_xwayland { if !surface.client.is_xwayland {
src.clone().offer_to_regular_client(&surface.client); offer_source_to_regular_client::<ClipboardIpc>(src.clone(), &surface.client);
} }
src.for_each_data_offer(|offer| { src.for_each_data_offer(|offer| {
offer.send_enter(surface.id, x, y, serial); offer.send_enter(surface.id, x, y, serial);