diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index a0b2229cb..57b099070 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -525,7 +525,13 @@ impl WindowOps for Window { where Self: Sized, { - Connection::with_window_inner(self.0, move |inner| { + // If we're already on the correct thread, just queue it up + if let Some(conn) = Connection::get() { + let handle = match conn.window_by_id(self.0) { + Some(h) => h, + None => return, + }; + let mut inner = handle.borrow_mut(); if let Some(window_view) = WindowView::get_this(unsafe { &**inner.view }) { window_view .inner @@ -534,8 +540,20 @@ impl WindowOps for Window { .try_send(WindowEvent::Notification(Box::new(t))) .ok(); } - Ok(()) - }); + } else { + // Otherwise, get into that thread and write to the queue + Connection::with_window_inner(self.0, move |inner| { + if let Some(window_view) = WindowView::get_this(unsafe { &**inner.view }) { + window_view + .inner + .borrow() + .events + .try_send(WindowEvent::Notification(Box::new(t))) + .ok(); + } + Ok(()) + }); + } } fn close(&self) -> Future<()> { diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index c37fa0054..5a5ff0f9d 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -644,7 +644,10 @@ impl WindowOps for WaylandWindow { { // If we're already on the correct thread, just queue it up if let Some(conn) = Connection::get() { - let handle = conn.wayland().window_by_id(self.0).unwrap(); + let handle = match conn.wayland().window_by_id(self.0) { + Some(h) => h, + None => return, + }; let inner = handle.borrow(); inner .events diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index 37b5e9787..a5dfd4469 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -580,7 +580,10 @@ impl WindowOps for Window { { // If we're already on the correct thread, just queue it up if let Some(conn) = Connection::get() { - let handle = conn.get_window(self.0).unwrap(); + let handle = match conn.get_window(self.0) { + Some(h) => h, + None => return, + }; let inner = handle.borrow_mut(); inner .events diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 145833171..280640bbd 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -932,7 +932,10 @@ impl WindowOps for XWindow { { // If we're already on the correct thread, just queue it up if let Some(conn) = Connection::get() { - let handle = conn.x11().window_by_id(self.0).unwrap(); + let handle = match conn.x11().window_by_id(self.0) { + Some(h) => h, + None => return, + }; let inner = handle.lock().unwrap(); inner .events