Fix set_cursor_state on X11

When the state is not changed, no code must be executed. Such no-ops previously
hit the unimplemented cursor hiding.
This commit is contained in:
Eduard Bopp 2015-05-25 21:01:39 +02:00
parent d089ea8674
commit 267b2c027a

View file

@ -711,20 +711,22 @@ impl Window {
}
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
use CursorState::{ Grab, Normal };
let mut cursor_state = self.cursor_state.lock().unwrap();
match (state, *cursor_state) {
(CursorState::Normal, CursorState::Grab) => {
(Normal, Grab) => {
unsafe {
(self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime);
*cursor_state = CursorState::Normal;
*cursor_state = Normal;
Ok(())
}
},
(CursorState::Grab, CursorState::Normal) => {
(Grab, Normal) => {
unsafe {
*cursor_state = CursorState::Grab;
*cursor_state = Grab;
match (self.x.display.xlib.XGrabPointer)(
self.x.display.display, self.x.window, ffi::False,
@ -745,6 +747,9 @@ impl Window {
}
},
// Nothing needs to change
(Grab, Grab) | (Normal, Normal) => Ok(()),
_ => unimplemented!(),
}
}