From 7d38ed2fab9c5b63163b35d5488e483ec5e8487a Mon Sep 17 00:00:00 2001 From: Benjamin Cheng Date: Fri, 26 Jan 2018 15:52:18 -0500 Subject: [PATCH] X11: Cursor grabbing fixes (#385) - Only update cursor_state when the grab is successful - Ungrab before grabbing to prevent passive grabs (ex. clicking) from causing AlreadyGrabbed --- src/platform/linux/x11/window.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index bb77664d..b6a8ca37 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -714,15 +714,22 @@ impl Window2 { Hide => self.update_cursor(self.get_cursor(*self.cursor.lock().unwrap())), } - *cursor_state = state; match state { - Normal => Ok(()), + Normal => { + *cursor_state = state; + Ok(()) + }, Hide => { + *cursor_state = state; self.update_cursor(self.create_empty_cursor()); Ok(()) }, Grab => { unsafe { + // Ungrab before grabbing to prevent passive grabs + // from causing AlreadyGrabbed + (self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime); + match (self.x.display.xlib.XGrabPointer)( self.x.display.display, self.x.window, ffi::True, (ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask | @@ -733,7 +740,10 @@ impl Window2 { ffi::GrabModeAsync, ffi::GrabModeAsync, self.x.window, 0, ffi::CurrentTime ) { - ffi::GrabSuccess => Ok(()), + ffi::GrabSuccess => { + *cursor_state = state; + Ok(()) + }, ffi::AlreadyGrabbed | ffi::GrabInvalidTime | ffi::GrabNotViewable | ffi::GrabFrozen => Err("cursor could not be grabbed".to_string()),