Window handle: Return an error when not on main thread on macOS and iOS (#3288)

This commit is contained in:
Mads Marquart 2023-12-22 23:18:35 +01:00 committed by GitHub
parent 8cd3aaa8a2
commit 4aeeb24745
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View file

@ -20,6 +20,7 @@ Unreleased` header.
- **Breaking:** On Web, remove queuing fullscreen request in absence of transient activation. - **Breaking:** On Web, remove queuing fullscreen request in absence of transient activation.
- On Web, fix setting cursor icon overriding cursor visibility. - On Web, fix setting cursor icon overriding cursor visibility.
- **Breaking:** On Web, return `RawWindowHandle::WebCanvas` instead of `RawWindowHandle::Web`. - **Breaking:** On Web, return `RawWindowHandle::WebCanvas` instead of `RawWindowHandle::Web`.
- **Breaking:** On Web, macOS and iOS, return `HandleError::Unavailable` when a window handle is not available.
# 0.29.5 # 0.29.5

View file

@ -529,9 +529,11 @@ impl Window {
pub(crate) fn raw_window_handle_rwh_06( pub(crate) fn raw_window_handle_rwh_06(
&self, &self,
) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> { ) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
Ok(self if let Some(mtm) = MainThreadMarker::new() {
.maybe_wait_on_main(|w| crate::SendSyncWrapper(w.raw_window_handle_rwh_06())) Ok(self.inner.get(mtm).raw_window_handle_rwh_06())
.0) } else {
Err(rwh_06::HandleError::Unavailable)
}
} }
} }

View file

@ -95,9 +95,11 @@ impl Window {
pub(crate) fn raw_window_handle_rwh_06( pub(crate) fn raw_window_handle_rwh_06(
&self, &self,
) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> { ) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
Ok(self if let Some(mtm) = MainThreadMarker::new() {
.maybe_wait_on_main(|w| crate::SendSyncWrapper(w.raw_window_handle_rwh_06())) Ok(self.window.get(mtm).raw_window_handle_rwh_06())
.0) } else {
Err(rwh_06::HandleError::Unavailable)
}
} }
} }

View file

@ -1532,7 +1532,8 @@ impl rwh_06::HasWindowHandle for Window {
fn window_handle(&self) -> Result<rwh_06::WindowHandle<'_>, rwh_06::HandleError> { fn window_handle(&self) -> Result<rwh_06::WindowHandle<'_>, rwh_06::HandleError> {
let raw = self.window.raw_window_handle_rwh_06()?; let raw = self.window.raw_window_handle_rwh_06()?;
// SAFETY: The window handle will never be deallocated while the window is alive. // SAFETY: The window handle will never be deallocated while the window is alive,
// and the main thread safety requirements are upheld internally by each platform.
Ok(unsafe { rwh_06::WindowHandle::borrow_raw(raw) }) Ok(unsafe { rwh_06::WindowHandle::borrow_raw(raw) })
} }
} }