1
0
Fork 0
forked from wry/wry

ipc: make source/offer ids type safe

This commit is contained in:
Julian Orth 2024-03-30 20:51:25 +01:00
parent 00efe7b51b
commit 7cbe5720c6
8 changed files with 27 additions and 27 deletions

View file

@ -200,6 +200,7 @@ fn start_compositor2(
config_file_id: NumCell::new(1),
tracker: Default::default(),
data_offer_ids: Default::default(),
data_source_ids: Default::default(),
drm_dev_ids: Default::default(),
ring: ring.clone(),
lock: ScreenlockState {

View file

@ -26,6 +26,9 @@ pub mod zwp_primary_selection_device_v1;
pub mod zwp_primary_selection_offer_v1;
pub mod zwp_primary_selection_source_v1;
linear_ids!(DataSourceIds, DataSourceId, u64);
linear_ids!(DataOfferIds, DataOfferId, u64);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Role {
Selection,
@ -57,14 +60,13 @@ pub trait IpcVtable: Sized {
) -> Result<Rc<Self::Offer>, ClientError>;
fn send_selection(dd: &Self::Device, offer: Option<&Rc<Self::Offer>>);
fn send_cancelled(source: &Rc<Self::Source>, seat: &Rc<WlSeatGlobal>);
fn get_offer_id(offer: &Self::Offer) -> u64;
fn get_offer_id(offer: &Self::Offer) -> DataOfferId;
fn send_offer(dd: &Self::Device, offer: &Rc<Self::Offer>);
fn send_mime_type(offer: &Rc<Self::Offer>, mime_type: &str);
fn unset(seat: &Rc<WlSeatGlobal>, role: Role);
fn send_send(src: &Rc<Self::Source>, mime_type: &str, fd: Rc<OwnedFd>);
fn remove_from_seat(device: &Self::Device);
fn get_offer_seat(offer: &Self::Offer) -> Rc<WlSeatGlobal>;
fn source_eq(left: &Self::Source, right: &Self::Source) -> bool;
}
pub struct DeviceData<T: IpcVtable> {
@ -108,7 +110,8 @@ const SOURCE_STATE_DROPPED_OR_CANCELLED: u32 = SOURCE_STATE_DROPPED | SOURCE_STA
pub struct SourceData<T: IpcVtable> {
pub seat: CloneCell<Option<Rc<WlSeatGlobal>>>,
offers: SmallMap<u64, Rc<T::Offer>, 1>,
pub id: DataSourceId,
offers: SmallMap<DataOfferId, Rc<T::Offer>, 1>,
offer_client: Cell<ClientId>,
mime_types: RefCell<AHashSet<String>>,
pub client: Rc<Client>,
@ -143,6 +146,7 @@ impl<T: IpcVtable> SourceData<T> {
fn new(client: &Rc<Client>, is_xwm: bool) -> Self {
Self {
seat: Default::default(),
id: client.state.data_source_ids.next(),
offers: Default::default(),
offer_client: Cell::new(client.id),
mime_types: Default::default(),

View file

@ -5,7 +5,8 @@ use {
ifs::{
ipc::{
break_device_loops, destroy_data_device, wl_data_offer::WlDataOffer,
wl_data_source::WlDataSource, DeviceData, IpcVtable, OfferData, Role, SourceData,
wl_data_source::WlDataSource, DataOfferId, DeviceData, IpcVtable, OfferData, Role,
SourceData,
},
wl_seat::{WlSeatError, WlSeatGlobal},
wl_surface::{SurfaceRole, WlSurfaceError},
@ -232,7 +233,7 @@ impl IpcVtable for ClipboardIpc {
) -> Result<Rc<Self::Offer>, ClientError> {
let rc = Rc::new(WlDataOffer {
id: client.new_id()?,
u64_id: client.state.data_offer_ids.fetch_add(1),
offer_id: client.state.data_offer_ids.next(),
client: client.clone(),
device: device.clone(),
data: offer_data,
@ -250,8 +251,8 @@ impl IpcVtable for ClipboardIpc {
source.send_cancelled(seat);
}
fn get_offer_id(offer: &Self::Offer) -> u64 {
offer.u64_id
fn get_offer_id(offer: &Self::Offer) -> DataOfferId {
offer.offer_id
}
fn send_offer(dd: &Self::Device, offer: &Rc<Self::Offer>) {
@ -280,10 +281,6 @@ impl IpcVtable for ClipboardIpc {
fn get_offer_seat(offer: &Self::Offer) -> Rc<WlSeatGlobal> {
offer.device.seat.clone()
}
fn source_eq(left: &Self::Source, right: &Self::Source) -> bool {
left as *const _ == right as *const _
}
}
object_base! {

View file

@ -5,8 +5,8 @@ use {
break_offer_loops, destroy_data_offer, receive_data_offer,
wl_data_device::{ClipboardIpc, WlDataDevice},
wl_data_device_manager::DND_ALL,
OfferData, Role, OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, OFFER_STATE_FINISHED,
SOURCE_STATE_FINISHED,
DataOfferId, OfferData, Role, OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED,
OFFER_STATE_FINISHED, SOURCE_STATE_FINISHED,
},
leaks::Tracker,
object::Object,
@ -32,7 +32,7 @@ const INVALID_OFFER: u32 = 3;
pub struct WlDataOffer {
pub id: WlDataOfferId,
pub u64_id: u64,
pub offer_id: DataOfferId,
pub client: Rc<Client>,
pub device: Rc<WlDataDevice>,
pub data: OfferData<ClipboardIpc>,

View file

@ -5,8 +5,8 @@ use {
ipc::{
break_device_loops, destroy_data_device,
zwp_primary_selection_offer_v1::ZwpPrimarySelectionOfferV1,
zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1, DeviceData,
IpcVtable, OfferData, Role, SourceData,
zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1, DataOfferId,
DeviceData, IpcVtable, OfferData, Role, SourceData,
},
wl_seat::{WlSeatError, WlSeatGlobal},
},
@ -179,7 +179,7 @@ impl IpcVtable for PrimarySelectionIpc {
};
let rc = Rc::new(ZwpPrimarySelectionOfferV1 {
id,
u64_id: client.state.data_offer_ids.fetch_add(1),
offer_id: client.state.data_offer_ids.next(),
seat: device.seat.clone(),
client: client.clone(),
data: offer_data,
@ -197,8 +197,8 @@ impl IpcVtable for PrimarySelectionIpc {
source.send_cancelled();
}
fn get_offer_id(offer: &Self::Offer) -> u64 {
offer.u64_id
fn get_offer_id(offer: &Self::Offer) -> DataOfferId {
offer.offer_id
}
fn send_offer(dd: &Self::Device, offer: &Rc<Self::Offer>) {
@ -224,10 +224,6 @@ impl IpcVtable for PrimarySelectionIpc {
fn get_offer_seat(offer: &Self::Offer) -> Rc<WlSeatGlobal> {
offer.seat.clone()
}
fn source_eq(left: &Self::Source, right: &Self::Source) -> bool {
left as *const _ == right as *const _
}
}
object_base! {

View file

@ -4,7 +4,7 @@ use {
ifs::{
ipc::{
break_offer_loops, destroy_data_offer, receive_data_offer,
zwp_primary_selection_device_v1::PrimarySelectionIpc, OfferData,
zwp_primary_selection_device_v1::PrimarySelectionIpc, DataOfferId, OfferData,
},
wl_seat::WlSeatGlobal,
},
@ -20,7 +20,7 @@ use {
pub struct ZwpPrimarySelectionOfferV1 {
pub id: ZwpPrimarySelectionOfferV1Id,
pub u64_id: u64,
pub offer_id: DataOfferId,
pub seat: Rc<WlSeatGlobal>,
pub client: Rc<Client>,
pub data: OfferData<PrimarySelectionIpc>,

View file

@ -715,7 +715,7 @@ impl WlSeatGlobal {
src: Option<Rc<T::Source>>,
) -> Result<(), WlSeatError> {
if let (Some(new), Some(old)) = (&src, &field.get()) {
if T::source_eq(old, new) {
if T::get_source_data(new).id == T::get_source_data(old).id {
return Ok(());
}
}

View file

@ -26,6 +26,7 @@ use {
ifs::{
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
ext_session_lock_v1::ExtSessionLockV1,
ipc::{DataOfferIds, DataSourceIds},
jay_render_ctx::JayRenderCtx,
jay_seat_events::JaySeatEvents,
jay_workspace_watcher::JayWorkspaceWatcher,
@ -149,7 +150,8 @@ pub struct State {
pub config_dir: Option<String>,
pub config_file_id: NumCell<u64>,
pub tracker: Tracker<Self>,
pub data_offer_ids: NumCell<u64>,
pub data_offer_ids: DataOfferIds,
pub data_source_ids: DataSourceIds,
pub ring: Rc<IoUring>,
pub lock: ScreenlockState,
pub scales: RefCounted<Scale>,