Skip to content

Commit

Permalink
data-control: remove wlr-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Oct 25, 2024
1 parent 40f7bc2 commit dfc0a11
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 99 deletions.
3 changes: 2 additions & 1 deletion src/client/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use {
ext_image_capture_source_v1::ExtImageCaptureSourceV1,
ext_image_copy::ext_image_copy_capture_session_v1::ExtImageCopyCaptureSessionV1,
ipc::{
wl_data_source::WlDataSource, zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
data_control::zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
wl_data_source::WlDataSource,
zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1,
},
jay_output::JayOutput,
Expand Down
1 change: 1 addition & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ fn start_compositor2(
toplevels: Default::default(),
const_40hz_latch: Default::default(),
tray_item_ids: Default::default(),
data_control_device_ids: Default::default(),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);
Expand Down
2 changes: 1 addition & 1 deletion src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use {
ext_output_image_capture_source_manager_v1::ExtOutputImageCaptureSourceManagerV1Global,
ext_session_lock_manager_v1::ExtSessionLockManagerV1Global,
ipc::{
data_control::zwlr_data_control_manager_v1::ZwlrDataControlManagerV1Global,
wl_data_device_manager::WlDataDeviceManagerGlobal,
zwlr_data_control_manager_v1::ZwlrDataControlManagerV1Global,
zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1Global,
},
jay_compositor::JayCompositorGlobal,
Expand Down
22 changes: 4 additions & 18 deletions src/ifs/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ use {
crate::{
client::{Client, ClientError, ClientId},
fixed::Fixed,
ifs::{
ipc::{
x_data_device::XIpcDevice, zwlr_data_control_device_v1::ZwlrDataControlDeviceV1,
},
wl_seat::WlSeatGlobal,
},
ifs::{ipc::x_data_device::XIpcDevice, wl_seat::WlSeatGlobal},
utils::{
bitflags::BitflagsExt, cell_ext::CellExt, clonecell::CloneCell, numcell::NumCell,
smallmap::SmallMap,
Expand All @@ -26,17 +21,14 @@ use {
uapi::OwnedFd,
};

pub mod data_control;
pub mod wl_data_device;
pub mod wl_data_device_manager;
pub mod wl_data_offer;
pub mod wl_data_source;
pub mod x_data_device;
pub mod x_data_offer;
pub mod x_data_source;
pub mod zwlr_data_control_device_v1;
pub mod zwlr_data_control_manager_v1;
pub mod zwlr_data_control_offer_v1;
pub mod zwlr_data_control_source_v1;
pub mod zwp_primary_selection_device_manager_v1;
pub mod zwp_primary_selection_device_v1;
pub mod zwp_primary_selection_offer_v1;
Expand Down Expand Up @@ -137,12 +129,6 @@ pub trait IterableIpcVtable: IpcVtable {
C: FnMut(&Rc<Self::Device>);
}

pub trait WlrIpcVtable: IpcVtable<Device = ZwlrDataControlDeviceV1> {
fn for_each_device<C>(seat: &WlSeatGlobal, f: C)
where
C: FnMut(&Rc<Self::Device>);
}

pub trait IpcVtable: Sized {
type Device;
type Source: DataSource;
Expand Down Expand Up @@ -360,9 +346,9 @@ where
offer_source_to_device::<T>(&src, dd, data, shared);
}

pub fn offer_source_to_wlr_device<T>(src: Rc<dyn DynDataSource>, dd: &Rc<T::Device>)
pub fn offer_source_to_data_control_device<T>(src: Rc<dyn DynDataSource>, dd: &Rc<T::Device>)
where
T: IpcVtable<Device = ZwlrDataControlDeviceV1>,
T: IpcVtable,
{
let data = src.source_data();
let shared = data.shared.get();
Expand Down
21 changes: 21 additions & 0 deletions src/ifs/ipc/data_control.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use {
crate::ifs::ipc::{DynDataSource, IpcLocation},
std::rc::Rc,
};

pub mod zwlr_data_control_device_v1;
pub mod zwlr_data_control_manager_v1;
pub mod zwlr_data_control_offer_v1;
pub mod zwlr_data_control_source_v1;

linear_ids!(DataControlDeviceIds, DataControlDeviceId, u64);

pub trait DynDataControlDevice {
fn id(&self) -> DataControlDeviceId;

fn handle_new_source(
self: Rc<Self>,
location: IpcLocation,
source: Option<Rc<dyn DynDataSource>>,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ use {
client::{Client, ClientError},
ifs::{
ipc::{
break_device_loops, destroy_data_device,
zwlr_data_control_device_v1::private::{
WlrClipboardIpcCore, WlrIpcImpl, WlrPrimarySelectionIpcCore,
break_device_loops,
data_control::{
zwlr_data_control_device_v1::private::{
WlrClipboardIpcCore, WlrIpcImpl, WlrPrimarySelectionIpcCore,
},
zwlr_data_control_offer_v1::ZwlrDataControlOfferV1,
zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
DataControlDeviceId, DynDataControlDevice,
},
zwlr_data_control_offer_v1::ZwlrDataControlOfferV1,
zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
DeviceData, IpcLocation, IpcVtable, OfferData, Role, WlrIpcVtable,
destroy_data_device, offer_source_to_data_control_device, DeviceData,
DynDataSource, IpcLocation, IpcVtable, OfferData, Role,
},
wl_seat::{WlSeatError, WlSeatGlobal},
},
Expand All @@ -28,6 +32,7 @@ pub const PRIMARY_SELECTION_SINCE: Version = Version(2);

pub struct ZwlrDataControlDeviceV1 {
pub id: ZwlrDataControlDeviceV1Id,
pub data_control_device_id: DataControlDeviceId,
pub client: Rc<Client>,
pub version: Version,
pub seat: Rc<WlSeatGlobal>,
Expand All @@ -45,6 +50,7 @@ impl ZwlrDataControlDeviceV1 {
) -> Self {
Self {
id,
data_control_device_id: client.state.data_control_device_ids.next(),
client: client.clone(),
version,
seat: seat.clone(),
Expand Down Expand Up @@ -111,7 +117,7 @@ impl ZwlrDataControlDeviceV1RequestHandler for ZwlrDataControlDeviceV1 {
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
destroy_data_device::<WlrClipboardIpc>(self);
destroy_data_device::<WlrPrimarySelectionIpc>(self);
self.seat.remove_wlr_device(self);
self.seat.remove_data_control_device(self);
self.client.remove_obj(self)?;
Ok(())
}
Expand All @@ -138,7 +144,6 @@ pub type WlrClipboardIpc = WlrIpcImpl<WlrClipboardIpcCore>;
pub type WlrPrimarySelectionIpc = WlrIpcImpl<WlrPrimarySelectionIpcCore>;

trait WlrIpc {
const MIN_VERSION: Version;
const LOCATION: IpcLocation;

fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData<ZwlrDataControlOfferV1>;
Expand All @@ -149,7 +154,6 @@ trait WlrIpc {
}

impl WlrIpc for WlrClipboardIpcCore {
const MIN_VERSION: Version = Version::ALL;
const LOCATION: IpcLocation = IpcLocation::Clipboard;

fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData<ZwlrDataControlOfferV1> {
Expand All @@ -169,7 +173,6 @@ impl WlrIpc for WlrClipboardIpcCore {
}

impl WlrIpc for WlrPrimarySelectionIpcCore {
const MIN_VERSION: Version = PRIMARY_SELECTION_SINCE;
const LOCATION: IpcLocation = IpcLocation::PrimarySelection;

fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData<ZwlrDataControlOfferV1> {
Expand All @@ -188,15 +191,6 @@ impl WlrIpc for WlrPrimarySelectionIpcCore {
}
}

impl<T: WlrIpc> WlrIpcVtable for WlrIpcImpl<T> {
fn for_each_device<C>(seat: &WlSeatGlobal, f: C)
where
C: FnMut(&Rc<Self::Device>),
{
seat.for_each_wlr_data_device(T::MIN_VERSION, f)
}
}

impl<T: WlrIpc> IpcVtable for WlrIpcImpl<T> {
type Device = ZwlrDataControlDeviceV1;
type Source = ZwlrDataControlSourceV1;
Expand Down Expand Up @@ -245,6 +239,35 @@ impl<T: WlrIpc> IpcVtable for WlrIpcImpl<T> {
}
}

impl DynDataControlDevice for ZwlrDataControlDeviceV1 {
fn id(&self) -> DataControlDeviceId {
self.data_control_device_id
}

fn handle_new_source(
self: Rc<Self>,
location: IpcLocation,
source: Option<Rc<dyn DynDataSource>>,
) {
match location {
IpcLocation::Clipboard => match source {
Some(src) => offer_source_to_data_control_device::<WlrClipboardIpc>(src, &self),
_ => self.send_selection(None),
},
IpcLocation::PrimarySelection => {
if self.version >= PRIMARY_SELECTION_SINCE {
match source {
Some(src) => offer_source_to_data_control_device::<WlrPrimarySelectionIpc>(
src, &self,
),
_ => self.send_primary_selection(None),
}
}
}
}
}
}

object_base! {
self = ZwlrDataControlDeviceV1;
version = self.version;
Expand All @@ -254,7 +277,7 @@ impl Object for ZwlrDataControlDeviceV1 {
fn break_loops(&self) {
break_device_loops::<WlrClipboardIpc>(self);
break_device_loops::<WlrPrimarySelectionIpc>(self);
self.seat.remove_wlr_device(self);
self.seat.remove_data_control_device(self);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use {
client::{Client, ClientCaps, ClientError, CAP_DATA_CONTROL_MANAGER},
globals::{Global, GlobalName},
ifs::ipc::{
offer_source_to_wlr_device,
zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
PRIMARY_SELECTION_SINCE,
data_control::{
zwlr_data_control_device_v1::ZwlrDataControlDeviceV1,
zwlr_data_control_source_v1::ZwlrDataControlSourceV1, DynDataControlDevice,
},
zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
IpcLocation,
},
leaks::Tracker,
object::{Object, Version},
Expand Down Expand Up @@ -79,18 +78,14 @@ impl ZwlrDataControlManagerV1RequestHandler for ZwlrDataControlManagerV1 {
&seat.global,
));
track!(self.client, dev);
seat.global.add_wlr_device(&dev);
seat.global.add_data_control_device(dev.clone());
self.client.add_client_obj(&dev)?;
match seat.global.get_selection() {
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) => offer_source_to_wlr_device::<WlrPrimarySelectionIpc>(s, &dev),
_ => dev.send_primary_selection(None),
}
}
dev.clone()
.handle_new_source(IpcLocation::Clipboard, seat.global.get_selection());
dev.clone().handle_new_source(
IpcLocation::PrimarySelection,
seat.global.get_primary_selection(),
);
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use {
client::{Client, ClientError, ClientId},
ifs::{
ipc::{
break_offer_loops, cancel_offer, destroy_data_offer, receive_data_offer,
zwlr_data_control_device_v1::{
break_offer_loops, cancel_offer,
data_control::zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc, ZwlrDataControlDeviceV1,
},
DataOffer, DataOfferId, DynDataOffer, IpcLocation, OfferData,
destroy_data_offer, receive_data_offer, DataOffer, DataOfferId, DynDataOffer,
IpcLocation, OfferData,
},
wl_seat::WlSeatGlobal,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use {
client::{Client, ClientError},
ifs::{
ipc::{
add_data_source_mime_type, break_source_loops, cancel_offers, destroy_data_source,
detach_seat, offer_source_to_x,
add_data_source_mime_type, break_source_loops, cancel_offers,
data_control::zwlr_data_control_device_v1::{
WlrClipboardIpc, WlrPrimarySelectionIpc,
},
destroy_data_source, detach_seat, offer_source_to_x,
x_data_device::{XClipboardIpc, XIpcDevice, XPrimarySelectionIpc},
zwlr_data_control_device_v1::{WlrClipboardIpc, WlrPrimarySelectionIpc},
DataSource, DynDataSource, IpcLocation, SourceData,
},
wl_seat::WlSeatGlobal,
Expand Down
Loading

0 comments on commit dfc0a11

Please sign in to comment.