From 70fc8f66e95f340514418b4a758671b339d650be Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Tue, 5 Mar 2024 14:27:40 +0400 Subject: [PATCH] chore(wayland): don't reapply same cursor grab Some compositors break when re-taking the same grab. Closes: https://github.com/rust-windowing/winit/issues/3566 --- CHANGELOG.md | 1 + src/platform_impl/linux/wayland/window/state.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cdaec60f..1ca7100f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Unreleased` header. # Unreleased +- On Wayland, don't reapply cursor grab when unchanged. - On X11, fix a bug where some mouse events would be unexpectedly filtered out. # 0.29.13 diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index c4c1ce473..1d36b1291 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -758,9 +758,14 @@ impl WindowState { /// Set the cursor grabbing state on the top-level. pub fn set_cursor_grab(&mut self, mode: CursorGrabMode) -> Result<(), ExternalError> { - // Replace the user grabbing mode. + if self.cursor_grab_mode.user_grab_mode == mode { + return Ok(()); + } + + self.set_cursor_grab_inner(mode)?; + // Update user grab on success. self.cursor_grab_mode.user_grab_mode = mode; - self.set_cursor_grab_inner(mode) + Ok(()) } /// Reload the hints for minimum and maximum sizes.