diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 6d6e7c488..7ed41d5c1 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -615,14 +615,24 @@ impl WindowOps for WaylandWindow { where Self: Sized, { - let mut t = Some(t); - WaylandConnection::with_window_inner(self.0, move |inner| { + // If we're already on the correct thread, just queue it up + if let Some(handle) = Connection::get().unwrap().wayland().window_by_id(self.0) { + let inner = handle.borrow(); inner .events - .try_send(WindowEvent::Notification(Box::new(t.take().unwrap()))) + .try_send(WindowEvent::Notification(Box::new(t))) .ok(); - Ok(()) - }); + } else { + // Otherwise, get into that thread and write to the queue + let mut t = Some(t); + WaylandConnection::with_window_inner(self.0, move |inner| { + inner + .events + .try_send(WindowEvent::Notification(Box::new(t.take().unwrap()))) + .ok(); + Ok(()) + }); + } } fn close(&self) -> Future<()> { diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 757c0353c..487bb8030 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -905,14 +905,24 @@ impl WindowOps for XWindow { where Self: Sized, { - let mut t = Some(t); - XConnection::with_window_inner(self.0, move |inner| { + // If we're already on the correct thread, just queue it up + if let Some(handle) = Connection::get().unwrap().x11().window_by_id(self.0) { + let inner = handle.lock().unwrap(); inner .events - .try_send(WindowEvent::Notification(Box::new(t.take().unwrap()))) + .try_send(WindowEvent::Notification(Box::new(t))) .ok(); - Ok(()) - }); + } else { + // Otherwise, get into that thread and write to the queue + let mut t = Some(t); + XConnection::with_window_inner(self.0, move |inner| { + inner + .events + .try_send(WindowEvent::Notification(Box::new(t.take().unwrap()))) + .ok(); + Ok(()) + }); + } } fn close(&self) -> Future<()> {