From 40f7bc2542a9f4b6ee591340eed82da41225cecd Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Tue, 8 Oct 2024 14:51:37 +0200 Subject: [PATCH] ipc: remove DynDataSource::offer_to_regular/wlr --- src/ifs/ipc.rs | 22 +++++------ src/ifs/ipc/wl_data_source.rs | 14 +------ src/ifs/ipc/x_data_source.rs | 34 +---------------- src/ifs/ipc/zwlr_data_control_manager_v1.rs | 10 +++-- src/ifs/ipc/zwlr_data_control_source_v1.rs | 37 ++----------------- .../ipc/zwp_primary_selection_source_v1.rs | 14 +------ src/ifs/wl_seat.rs | 6 +-- src/ifs/wl_seat/event_handling.rs | 4 +- 8 files changed, 31 insertions(+), 110 deletions(-) diff --git a/src/ifs/ipc.rs b/src/ifs/ipc.rs index 35f9f8b4..3bb77ed8 100644 --- a/src/ifs/ipc.rs +++ b/src/ifs/ipc.rs @@ -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); - fn offer_to_regular_client(self: Rc, client: &Rc); fn offer_to_x(self: Rc, dd: &Rc); - fn offer_to_wlr_device(self: Rc, dd: &Rc); fn detach_seat(&self, seat: &Rc); fn cancel_unprivileged_offers(&self); @@ -315,8 +313,8 @@ pub fn detach_seat(src: &S, seat: &Rc) { // data.client.flush(); } -fn offer_source_to_device( - src: &Rc, +fn offer_source_to_device( + src: &Rc, dd: &Rc, data: &SourceData, shared: Rc, @@ -351,31 +349,29 @@ fn offer_source_to_device( } } -fn offer_source_to_x(src: &Rc, dd: &Rc) +fn offer_source_to_x(src: Rc, dd: &Rc) where T: IpcVtable, - 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::(src, dd, data, shared); + offer_source_to_device::(&src, dd, data, shared); } -pub fn offer_source_to_wlr_device(src: &Rc, dd: &Rc) +pub fn offer_source_to_wlr_device(src: Rc, dd: &Rc) where T: IpcVtable, - S: DynDataSource, { let data = src.source_data(); let shared = data.shared.get(); shared.role.set(data.role.get()); - offer_source_to_device::(src, dd, data, shared); + offer_source_to_device::(&src, dd, data, shared); } -fn offer_source_to_regular_client( - src: &Rc, +pub fn offer_source_to_regular_client( + src: Rc, client: &Rc, ) { let data = src.source_data(); @@ -390,7 +386,7 @@ fn offer_source_to_regular_client( let shared = data.shared.get(); shared.role.set(data.role.get()); T::for_each_device(&seat, client.id, |dd| { - offer_source_to_device::(src, dd, data, shared.clone()); + offer_source_to_device::(&src, dd, data, shared.clone()); }); } diff --git a/src/ifs/ipc/wl_data_source.rs b/src/ifs/ipc/wl_data_source.rs index a21feed0..a7d0728a 100644 --- a/src/ifs/ipc/wl_data_source.rs +++ b/src/ifs/ipc/wl_data_source.rs @@ -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, @@ -55,16 +53,8 @@ impl DynDataSource for WlDataSource { WlDataSource::send_send(self, mime_type, fd); } - fn offer_to_regular_client(self: Rc, client: &Rc) { - offer_source_to_regular_client::(&self, client); - } - fn offer_to_x(self: Rc, dd: &Rc) { - offer_source_to_x::(&self, dd); - } - - fn offer_to_wlr_device(self: Rc, dd: &Rc) { - offer_source_to_wlr_device::(&self, dd) + offer_source_to_x::(self, dd); } fn detach_seat(&self, seat: &Rc) { diff --git a/src/ifs/ipc/x_data_source.rs b/src/ifs/ipc/x_data_source.rs index c071b592..e7c03342 100644 --- a/src/ifs/ipc/x_data_source.rs +++ b/src/ifs/ipc/x_data_source.rs @@ -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, }, @@ -54,17 +46,6 @@ impl DynDataSource for XDataSource { }); } - fn offer_to_regular_client(self: Rc, client: &Rc) { - match self.location { - IpcLocation::Clipboard => { - offer_source_to_regular_client::(&self, client) - } - IpcLocation::PrimarySelection => { - offer_source_to_regular_client::(&self, client) - } - } - } - fn offer_to_x(self: Rc, _dd: &Rc) { self.cancel_unprivileged_offers(); self.state.xwayland.queue.push(IpcSetSelection { @@ -74,17 +55,6 @@ impl DynDataSource for XDataSource { }); } - fn offer_to_wlr_device(self: Rc, dd: &Rc) { - match self.location { - IpcLocation::Clipboard => { - offer_source_to_wlr_device::(&self, dd) - } - IpcLocation::PrimarySelection => { - offer_source_to_wlr_device::(&self, dd) - } - } - } - fn detach_seat(&self, seat: &Rc) { detach_seat(self, seat); } diff --git a/src/ifs/ipc/zwlr_data_control_manager_v1.rs b/src/ifs/ipc/zwlr_data_control_manager_v1.rs index ad5ce34f..4959548e 100644 --- a/src/ifs/ipc/zwlr_data_control_manager_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_manager_v1.rs @@ -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, @@ -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::(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::(s, &dev), _ => dev.send_primary_selection(None), } } diff --git a/src/ifs/ipc/zwlr_data_control_source_v1.rs b/src/ifs/ipc/zwlr_data_control_source_v1.rs index 16fadf5e..0cfef704 100644 --- a/src/ifs/ipc/zwlr_data_control_source_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_source_v1.rs @@ -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, @@ -49,34 +44,10 @@ impl DynDataSource for ZwlrDataControlSourceV1 { ZwlrDataControlSourceV1::send_send(&self, mime_type, fd); } - fn offer_to_regular_client(self: Rc, client: &Rc) { - match self.location.get() { - IpcLocation::Clipboard => { - offer_source_to_regular_client::(&self, client) - } - IpcLocation::PrimarySelection => { - offer_source_to_regular_client::(&self, client) - } - } - } - fn offer_to_x(self: Rc, dd: &Rc) { match self.location.get() { - IpcLocation::Clipboard => offer_source_to_x::(&self, dd), - IpcLocation::PrimarySelection => { - offer_source_to_x::(&self, dd) - } - } - } - - fn offer_to_wlr_device(self: Rc, dd: &Rc) { - match self.location.get() { - IpcLocation::Clipboard => { - offer_source_to_wlr_device::(&self, dd) - } - IpcLocation::PrimarySelection => { - offer_source_to_wlr_device::(&self, dd) - } + IpcLocation::Clipboard => offer_source_to_x::(self, dd), + IpcLocation::PrimarySelection => offer_source_to_x::(self, dd), } } diff --git a/src/ifs/ipc/zwp_primary_selection_source_v1.rs b/src/ifs/ipc/zwp_primary_selection_source_v1.rs index 9cf1f735..27414003 100644 --- a/src/ifs/ipc/zwp_primary_selection_source_v1.rs +++ b/src/ifs/ipc/zwp_primary_selection_source_v1.rs @@ -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, }, @@ -44,16 +42,8 @@ impl DynDataSource for ZwpPrimarySelectionSourceV1 { ZwpPrimarySelectionSourceV1::send_send(self, mime_type, fd) } - fn offer_to_regular_client(self: Rc, client: &Rc) { - offer_source_to_regular_client::(&self, client); - } - fn offer_to_x(self: Rc, dd: &Rc) { - offer_source_to_x::(&self, dd); - } - - fn offer_to_wlr_device(self: Rc, dd: &Rc) { - offer_source_to_wlr_device::(&self, dd) + offer_source_to_x::(self, dd); } fn detach_seat(&self, seat: &Rc) { diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 86b5bd2c..0b88f732 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -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}, @@ -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::(src.clone(), device), _ => W::send_selection(device, None), }); Ok(()) @@ -763,7 +763,7 @@ impl WlSeatGlobal { }); } else { match selection { - Some(src) => src.offer_to_regular_client(client), + Some(src) => offer_source_to_regular_client::(src, client), _ => T::for_each_device(self, client.id, |device| { T::send_selection(device, None); }), diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 0a8ded1d..54a7407e 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -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}, @@ -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::(src.clone(), &surface.client); } src.for_each_data_offer(|offer| { offer.send_enter(surface.id, x, y, serial);