|
11 | 11 | html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png" |
12 | 12 | )] |
13 | 13 |
|
14 | | -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle}; |
| 14 | +use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle}; |
15 | 15 | use tauri_runtime::{ |
16 | 16 | monitor::Monitor, |
17 | 17 | webview::{DetachedWebview, DownloadEvent, PendingWebview, WebviewIpcHandler}, |
@@ -1077,8 +1077,8 @@ pub struct GtkBox(pub gtk::Box); |
1077 | 1077 | #[allow(clippy::non_send_fields_in_send_ty)] |
1078 | 1078 | unsafe impl Send for GtkBox {} |
1079 | 1079 |
|
1080 | | -pub struct RawWindowHandle(pub raw_window_handle::RawWindowHandle); |
1081 | | -unsafe impl Send for RawWindowHandle {} |
| 1080 | +pub struct SendRawWindowHandle(pub raw_window_handle::RawWindowHandle); |
| 1081 | +unsafe impl Send for SendRawWindowHandle {} |
1082 | 1082 |
|
1083 | 1083 | #[cfg(target_os = "macos")] |
1084 | 1084 | #[derive(Debug, Clone)] |
@@ -1125,7 +1125,7 @@ pub enum WindowMessage { |
1125 | 1125 | target_os = "openbsd" |
1126 | 1126 | ))] |
1127 | 1127 | GtkBox(Sender<GtkBox>), |
1128 | | - RawWindowHandle(Sender<RawWindowHandle>), |
| 1128 | + RawWindowHandle(Sender<std::result::Result<SendRawWindowHandle, raw_window_handle::HandleError>>), |
1129 | 1129 | Theme(Sender<Theme>), |
1130 | 1130 | // Setters |
1131 | 1131 | Center, |
@@ -1400,6 +1400,12 @@ pub struct WryWindowDispatcher<T: UserEvent> { |
1400 | 1400 | #[allow(clippy::non_send_fields_in_send_ty)] |
1401 | 1401 | unsafe impl<T: UserEvent> Sync for WryWindowDispatcher<T> {} |
1402 | 1402 |
|
| 1403 | +fn get_raw_window_handle<T: UserEvent>( |
| 1404 | + dispatcher: &WryWindowDispatcher<T>, |
| 1405 | +) -> Result<std::result::Result<SendRawWindowHandle, raw_window_handle::HandleError>> { |
| 1406 | + window_getter!(dispatcher, WindowMessage::RawWindowHandle) |
| 1407 | +} |
| 1408 | + |
1403 | 1409 | impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> { |
1404 | 1410 | type Runtime = Wry<T>; |
1405 | 1411 | type WindowBuilder = WindowBuilderWrapper; |
@@ -1531,8 +1537,12 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> { |
1531 | 1537 | window_getter!(self, WindowMessage::GtkBox).map(|w| w.0) |
1532 | 1538 | } |
1533 | 1539 |
|
1534 | | - fn raw_window_handle(&self) -> Result<raw_window_handle::RawWindowHandle> { |
1535 | | - window_getter!(self, WindowMessage::RawWindowHandle).map(|w| w.0) |
| 1540 | + fn window_handle( |
| 1541 | + &self, |
| 1542 | + ) -> std::result::Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> { |
| 1543 | + get_raw_window_handle(self) |
| 1544 | + .map_err(|_| raw_window_handle::HandleError::Unavailable) |
| 1545 | + .and_then(|r| r.map(|h| unsafe { raw_window_handle::WindowHandle::borrow_raw(h.0) })) |
1536 | 1546 | } |
1537 | 1547 |
|
1538 | 1548 | // Setters |
@@ -2046,8 +2056,8 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> { |
2046 | 2056 | send_user_message(&self.context, Message::Task(Box::new(f))) |
2047 | 2057 | } |
2048 | 2058 |
|
2049 | | - fn raw_display_handle(&self) -> RawDisplayHandle { |
2050 | | - self.context.main_thread.window_target.raw_display_handle() |
| 2059 | + fn display_handle(&self) -> std::result::Result<DisplayHandle, raw_window_handle::HandleError> { |
| 2060 | + self.context.main_thread.window_target.display_handle() |
2051 | 2061 | } |
2052 | 2062 |
|
2053 | 2063 | fn primary_monitor(&self) -> Option<Monitor> { |
@@ -2547,7 +2557,11 @@ fn handle_user_message<T: UserEvent>( |
2547 | 2557 | .send(GtkBox(window.default_vbox().unwrap().clone())) |
2548 | 2558 | .unwrap(), |
2549 | 2559 | WindowMessage::RawWindowHandle(tx) => tx |
2550 | | - .send(RawWindowHandle(window.raw_window_handle())) |
| 2560 | + .send( |
| 2561 | + window |
| 2562 | + .window_handle() |
| 2563 | + .map(|h| SendRawWindowHandle(h.as_raw())), |
| 2564 | + ) |
2551 | 2565 | .unwrap(), |
2552 | 2566 | WindowMessage::Theme(tx) => { |
2553 | 2567 | tx.send(map_theme(&window.theme())).unwrap(); |
|
0 commit comments