Skip to content

Commit

Permalink
ipc: remove DynDataSource::offer_to_regular/wlr
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Oct 25, 2024
1 parent 487efaf commit 40f7bc2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 110 deletions.
22 changes: 9 additions & 13 deletions src/ifs/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub trait DataSource: DynDataSource {
pub trait DynDataSource: 'static {
fn source_data(&self) -> &SourceData;
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_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>);
fn detach_seat(&self, seat: &Rc<WlSeatGlobal>);
fn cancel_unprivileged_offers(&self);

Expand Down Expand Up @@ -315,8 +313,8 @@ pub fn detach_seat<S: DataSource>(src: &S, seat: &Rc<WlSeatGlobal>) {
// data.client.flush();
}

fn offer_source_to_device<T: IpcVtable, S: DynDataSource>(
src: &Rc<S>,
fn offer_source_to_device<T: IpcVtable>(
src: &Rc<dyn DynDataSource>,
dd: &Rc<T::Device>,
data: &SourceData,
shared: Rc<SharedState>,
Expand Down Expand Up @@ -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
T: IpcVtable<Device = XIpcDevice>,
S: DynDataSource,
{
let data = src.source_data();
src.cancel_unprivileged_offers();
let shared = data.shared.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
T: IpcVtable<Device = ZwlrDataControlDeviceV1>,
S: DynDataSource,
{
let data = src.source_data();
let shared = data.shared.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>(
src: &Rc<S>,
pub fn offer_source_to_regular_client<T: IterableIpcVtable>(
src: Rc<dyn DynDataSource>,
client: &Rc<Client>,
) {
let data = src.source_data();
Expand All @@ -390,7 +386,7 @@ fn offer_source_to_regular_client<T: IterableIpcVtable, S: DynDataSource>(
let shared = data.shared.get();
shared.role.set(data.role.get());
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());
});
}

Expand Down
14 changes: 2 additions & 12 deletions src/ifs/ipc/wl_data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use {
ifs::{
ipc::{
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,
offer_source_to_x,
detach_seat, offer_source_to_x,
wl_data_device::ClipboardIpc,
wl_data_device_manager::{DND_ALL, DND_NONE},
x_data_device::{XClipboardIpc, XIpcDevice},
zwlr_data_control_device_v1::{WlrClipboardIpc, ZwlrDataControlDeviceV1},
DataSource, DynDataOffer, DynDataSource, SharedState, SourceData,
OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, SOURCE_STATE_CANCELLED,
SOURCE_STATE_DROPPED,
Expand Down Expand Up @@ -55,16 +53,8 @@ impl DynDataSource for WlDataSource {
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>) {
offer_source_to_x::<XClipboardIpc, Self>(&self, dd);
}

fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
offer_source_to_wlr_device::<WlrClipboardIpc, Self>(&self, dd)
offer_source_to_x::<XClipboardIpc>(self, dd);
}

fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {
Expand Down
34 changes: 2 additions & 32 deletions src/ifs/ipc/x_data_source.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use {
crate::{
client::Client,
ifs::{
ipc::{
cancel_offers, detach_seat, offer_source_to_regular_client,
offer_source_to_wlr_device,
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,
cancel_offers, detach_seat, x_data_device::XIpcDevice, DataSource, DynDataSource,
IpcLocation, SourceData,
},
wl_seat::WlSeatGlobal,
},
Expand Down Expand Up @@ -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>) {
self.cancel_unprivileged_offers();
self.state.xwayland.queue.push(IpcSetSelection {
Expand All @@ -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>) {
detach_seat(self, seat);
}
Expand Down
10 changes: 7 additions & 3 deletions src/ifs/ipc/zwlr_data_control_manager_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use {
client::{Client, ClientCaps, ClientError, CAP_DATA_CONTROL_MANAGER},
globals::{Global, GlobalName},
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,
},
leaks::Tracker,
Expand Down Expand Up @@ -78,12 +82,12 @@ impl ZwlrDataControlManagerV1RequestHandler for ZwlrDataControlManagerV1 {
seat.global.add_wlr_device(&dev);
self.client.add_client_obj(&dev)?;
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),
}
if self.version >= PRIMARY_SELECTION_SINCE {
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),
}
}
Expand Down
37 changes: 4 additions & 33 deletions src/ifs/ipc/zwlr_data_control_source_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ use {
ifs::{
ipc::{
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,
offer_source_to_x,
wl_data_device::ClipboardIpc,
detach_seat, offer_source_to_x,
x_data_device::{XClipboardIpc, XIpcDevice, XPrimarySelectionIpc},
zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
},
zwp_primary_selection_device_v1::PrimarySelectionIpc,
zwlr_data_control_device_v1::{WlrClipboardIpc, WlrPrimarySelectionIpc},
DataSource, DynDataSource, IpcLocation, SourceData,
},
wl_seat::WlSeatGlobal,
Expand Down Expand Up @@ -49,34 +44,10 @@ impl DynDataSource for ZwlrDataControlSourceV1 {
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>) {
match self.location.get() {
IpcLocation::Clipboard => offer_source_to_x::<XClipboardIpc, Self>(&self, dd),
IpcLocation::PrimarySelection => {
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)
}
IpcLocation::Clipboard => offer_source_to_x::<XClipboardIpc>(self, dd),
IpcLocation::PrimarySelection => offer_source_to_x::<XPrimarySelectionIpc>(self, dd),
}
}

Expand Down
14 changes: 2 additions & 12 deletions src/ifs/ipc/zwp_primary_selection_source_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use {
ifs::{
ipc::{
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,
offer_source_to_x,
detach_seat, offer_source_to_x,
x_data_device::{XIpcDevice, XPrimarySelectionIpc},
zwlr_data_control_device_v1::{WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1},
zwp_primary_selection_device_v1::PrimarySelectionIpc,
DataSource, DynDataSource, SourceData,
},
Expand Down Expand Up @@ -44,16 +42,8 @@ impl DynDataSource for ZwpPrimarySelectionSourceV1 {
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>) {
offer_source_to_x::<XPrimarySelectionIpc, Self>(&self, dd);
}

fn offer_to_wlr_device(self: Rc<Self>, dd: &Rc<ZwlrDataControlDeviceV1>) {
offer_source_to_wlr_device::<WlrPrimarySelectionIpc, Self>(&self, dd)
offer_source_to_x::<XPrimarySelectionIpc>(self, dd);
}

fn detach_seat(&self, seat: &Rc<WlSeatGlobal>) {
Expand Down
6 changes: 3 additions & 3 deletions src/ifs/wl_seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use {
ifs::{
ext_idle_notification_v1::ExtIdleNotificationV1,
ipc::{
self,
self, offer_source_to_regular_client, offer_source_to_wlr_device,
wl_data_device::{ClipboardIpc, WlDataDevice},
wl_data_source::WlDataSource,
x_data_device::{XClipboardIpc, XIpcDevice, XIpcDeviceId, XPrimarySelectionIpc},
Expand Down Expand Up @@ -739,7 +739,7 @@ impl WlSeatGlobal {
// client.flush();
}
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),
});
Ok(())
Expand All @@ -763,7 +763,7 @@ impl WlSeatGlobal {
});
} else {
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::send_selection(device, None);
}),
Expand Down
4 changes: 2 additions & 2 deletions src/ifs/wl_seat/event_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use {
fixed::Fixed,
ifs::{
ipc::{
offer_source_to_regular_client,
wl_data_device::{ClipboardIpc, WlDataDevice},
x_data_device::{XClipboardIpc, XPrimarySelectionIpc},
zwlr_data_control_device_v1::ZwlrDataControlDeviceV1,
zwp_primary_selection_device_v1::{
PrimarySelectionIpc, ZwpPrimarySelectionDeviceV1,
},
DynDataSource,
},
wl_seat::{
tablet::{TabletPad, TabletPadId, TabletTool, TabletToolId},
Expand Down Expand Up @@ -1445,7 +1445,7 @@ impl WlSeatGlobal {
) {
if let Some(src) = &dnd.src {
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| {
offer.send_enter(surface.id, x, y, serial);
Expand Down

0 comments on commit 40f7bc2

Please sign in to comment.