From b1a5fae1f5d0ed2d398a41647885539d4da6637b Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 18 Jan 2023 05:58:09 +0300 Subject: [PATCH] On X11, fix errors bleeding from hooks handling them This commit fixes it, by not updating the `latest_error` when any of the hooks handled the error, otherwise it'd interfere with the winit's error checking. --- CHANGELOG.md | 1 + src/platform/x11.rs | 10 +++++++--- src/platform_impl/linux/mod.rs | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67a2873d..28919e9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On X11, fix errors handled during `register_xlib_error_hook` invocation bleeding into winit. - Add `Window::has_focus`. - On Windows, fix `Window::set_minimized(false)` not working for windows minimized by `Win + D` hotkey. - **Breaking:** On Web, touch input no longer fires `WindowEvent::Cursor*`, `WindowEvent::MouseInput`, or `DeviceEvent::MouseMotion` like other platforms, but instead it fires `WindowEvent::Touch`. diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 09c40dab..1dbdf3fb 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -24,9 +24,13 @@ pub type XlibErrorHook = /// Hook to winit's xlib error handling callback. /// -/// This method is provided as a safe way to handle the errors comming from X11 when using xlib -/// in external crates, like glutin for GLX access. Trying to handle errors by speculating with -/// `XSetErrorHandler` is [`unsafe`]. +/// This method is provided as a safe way to handle the errors comming from X11 +/// when using xlib in external crates, like glutin for GLX access. Trying to +/// handle errors by speculating with `XSetErrorHandler` is [`unsafe`]. +/// +/// **Be aware that your hook is always invoked and returning `true` from it will +/// prevent `winit` from getting the error itself. It's wise to always return +/// `false` if you're not initiated the `Sync`.** /// /// [`unsafe`]: https://www.remlab.net/op/xlib.shtml #[inline] diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 8e9d2edf..964ca06c 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -653,9 +653,9 @@ unsafe extern "C" fn x_error_callback( // Don't log error. if !error_handled { error!("X11 error: {:#?}", error); + // XXX only update the error, if it wasn't handled by any of the hooks. + *xconn.latest_error.lock().unwrap() = Some(error); } - - *xconn.latest_error.lock().unwrap() = Some(error); } // Fun fact: this return value is completely ignored. 0