api: make OwnedDisplayHandle wrap an opaque type
This will help in case we want to linger the event loop during drop to prevent use after free in the consumers code.
This commit is contained in:
parent
f781e13166
commit
59b1eb5410
19 changed files with 149 additions and 177 deletions
|
|
@ -396,58 +396,6 @@ impl AsRawFd for EventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) enum OwnedDisplayHandle {
|
||||
#[cfg(x11_platform)]
|
||||
X(Arc<XConnection>),
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland_client::Connection),
|
||||
}
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
#[inline]
|
||||
pub fn raw_display_handle_rwh_06(
|
||||
&self,
|
||||
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
|
||||
use std::ptr::NonNull;
|
||||
|
||||
match self {
|
||||
#[cfg(x11_platform)]
|
||||
Self::X(xconn) => Ok(rwh_06::XlibDisplayHandle::new(
|
||||
NonNull::new(xconn.display.cast()),
|
||||
xconn.default_screen_index() as _,
|
||||
)
|
||||
.into()),
|
||||
|
||||
#[cfg(wayland_platform)]
|
||||
Self::Wayland(conn) => {
|
||||
use sctk::reexports::client::Proxy;
|
||||
|
||||
Ok(rwh_06::WaylandDisplayHandle::new(
|
||||
NonNull::new(conn.display().id().as_ptr().cast()).unwrap(),
|
||||
)
|
||||
.into())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for OwnedDisplayHandle {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
#[cfg(x11_platform)]
|
||||
(Self::X(this), Self::X(other)) => Arc::as_ptr(this).eq(&Arc::as_ptr(other)),
|
||||
#[cfg(wayland_platform)]
|
||||
(Self::Wayland(this), Self::Wayland(other)) => this.eq(other),
|
||||
#[cfg(all(x11_platform, wayland_platform))]
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for OwnedDisplayHandle {}
|
||||
|
||||
/// Returns the minimum `Option<Duration>`, taking into account that `None`
|
||||
/// equates to an infinite timeout, not a zero timeout (so can't just use
|
||||
/// `Option::min`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue