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
|
|
@ -16,7 +16,10 @@ use crate::cursor::OnlyCursorImage;
|
|||
use crate::dpi::LogicalSize;
|
||||
use crate::error::{EventLoopError, OsError, RequestError};
|
||||
use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
|
||||
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents};
|
||||
use crate::event_loop::{
|
||||
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
|
||||
OwnedDisplayHandle as CoreOwnedDisplayHandle,
|
||||
};
|
||||
use crate::platform::pump_events::PumpStatus;
|
||||
use crate::platform_impl::platform::min_timeout;
|
||||
use crate::platform_impl::PlatformCustomCursor;
|
||||
|
|
@ -49,7 +52,7 @@ pub struct EventLoop {
|
|||
wayland_dispatcher: WaylandDispatcher,
|
||||
|
||||
/// Connection to the wayland server.
|
||||
connection: Connection,
|
||||
handle: Arc<OwnedDisplayHandle>,
|
||||
|
||||
/// Event loop window target.
|
||||
active_event_loop: ActiveEventLoop,
|
||||
|
|
@ -117,8 +120,9 @@ impl EventLoop {
|
|||
})
|
||||
.map_err(|err| os_error!(err))?;
|
||||
|
||||
let handle = Arc::new(OwnedDisplayHandle::new(connection));
|
||||
let active_event_loop = ActiveEventLoop {
|
||||
connection: connection.clone(),
|
||||
handle: handle.clone(),
|
||||
wayland_dispatcher: wayland_dispatcher.clone(),
|
||||
event_loop_awakener,
|
||||
event_loop_proxy: EventLoopProxy::new(ping).into(),
|
||||
|
|
@ -133,7 +137,7 @@ impl EventLoop {
|
|||
compositor_updates: Vec::new(),
|
||||
buffer_sink: EventSink::default(),
|
||||
window_ids: Vec::new(),
|
||||
connection,
|
||||
handle,
|
||||
wayland_dispatcher,
|
||||
event_loop,
|
||||
active_event_loop,
|
||||
|
|
@ -227,7 +231,7 @@ impl EventLoop {
|
|||
//
|
||||
// Checking for flush error is essential to perform an exit with error, since
|
||||
// once we have a protocol error, we could get stuck retrying...
|
||||
if self.connection.flush().is_err() {
|
||||
if self.handle.connection.flush().is_err() {
|
||||
self.set_exit_code(1);
|
||||
return;
|
||||
}
|
||||
|
|
@ -561,8 +565,8 @@ pub struct ActiveEventLoop {
|
|||
/// Dispatcher of Wayland events.
|
||||
pub wayland_dispatcher: WaylandDispatcher,
|
||||
|
||||
/// Connection to the wayland server.
|
||||
pub connection: Connection,
|
||||
/// Handle for the underlying event loop.
|
||||
pub handle: Arc<OwnedDisplayHandle>,
|
||||
}
|
||||
|
||||
impl RootActiveEventLoop for ActiveEventLoop {
|
||||
|
|
@ -628,10 +632,8 @@ impl RootActiveEventLoop for ActiveEventLoop {
|
|||
None
|
||||
}
|
||||
|
||||
fn owned_display_handle(&self) -> crate::event_loop::OwnedDisplayHandle {
|
||||
crate::event_loop::OwnedDisplayHandle {
|
||||
platform: crate::platform_impl::OwnedDisplayHandle::Wayland(self.connection.clone()),
|
||||
}
|
||||
fn owned_display_handle(&self) -> CoreOwnedDisplayHandle {
|
||||
CoreOwnedDisplayHandle::new(self.handle.clone())
|
||||
}
|
||||
|
||||
fn rwh_06_handle(&self) -> &dyn rwh_06::HasDisplayHandle {
|
||||
|
|
@ -654,6 +656,22 @@ impl ActiveEventLoop {
|
|||
}
|
||||
|
||||
impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
||||
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
|
||||
self.handle.display_handle()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OwnedDisplayHandle {
|
||||
pub(crate) connection: Connection,
|
||||
}
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
fn new(connection: Connection) -> Self {
|
||||
Self { connection }
|
||||
}
|
||||
}
|
||||
|
||||
impl rwh_06::HasDisplayHandle for OwnedDisplayHandle {
|
||||
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
|
||||
use sctk::reexports::client::Proxy;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue