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
This commit is contained in:
Benjamin Cheng 2018-01-26 15:52:18 -05:00 committed by Pierre Krieger
parent 1609808e27
commit 7d38ed2fab

View file

@ -714,15 +714,22 @@ impl Window2 {
Hide => self.update_cursor(self.get_cursor(*self.cursor.lock().unwrap())), Hide => self.update_cursor(self.get_cursor(*self.cursor.lock().unwrap())),
} }
*cursor_state = state;
match state { match state {
Normal => Ok(()), Normal => {
*cursor_state = state;
Ok(())
},
Hide => { Hide => {
*cursor_state = state;
self.update_cursor(self.create_empty_cursor()); self.update_cursor(self.create_empty_cursor());
Ok(()) Ok(())
}, },
Grab => { Grab => {
unsafe { 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)( match (self.x.display.xlib.XGrabPointer)(
self.x.display.display, self.x.window, ffi::True, self.x.display.display, self.x.window, ffi::True,
(ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask | (ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask |
@ -733,7 +740,10 @@ impl Window2 {
ffi::GrabModeAsync, ffi::GrabModeAsync, ffi::GrabModeAsync, ffi::GrabModeAsync,
self.x.window, 0, ffi::CurrentTime self.x.window, 0, ffi::CurrentTime
) { ) {
ffi::GrabSuccess => Ok(()), ffi::GrabSuccess => {
*cursor_state = state;
Ok(())
},
ffi::AlreadyGrabbed | ffi::GrabInvalidTime | ffi::AlreadyGrabbed | ffi::GrabInvalidTime |
ffi::GrabNotViewable | ffi::GrabFrozen ffi::GrabNotViewable | ffi::GrabFrozen
=> Err("cursor could not be grabbed".to_string()), => Err("cursor could not be grabbed".to_string()),