mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Implement CursorState::Hide for x11
This commit is contained in:
parent
9a8ca6ebae
commit
267221af3e
|
@ -339,7 +339,7 @@ impl Window {
|
||||||
let m = (0 .. mode_num).map(|i| {
|
let m = (0 .. mode_num).map(|i| {
|
||||||
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
|
||||||
}).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16);
|
}).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16);
|
||||||
|
|
||||||
match m {
|
match m {
|
||||||
Some(m) => Some(m),
|
Some(m) => Some(m),
|
||||||
None => return Err(OsError(format!("Could not find a suitable graphics mode")))
|
None => return Err(OsError(format!("Could not find a suitable graphics mode")))
|
||||||
|
@ -845,29 +845,61 @@ impl Window {
|
||||||
self.x.display.check_errors().expect("Failed to call XcursorLibraryLoadCursor");
|
self.x.display.check_errors().expect("Failed to call XcursorLibraryLoadCursor");
|
||||||
(self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor);
|
(self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor);
|
||||||
(self.x.display.xlib.XFlush)(self.x.display.display);
|
(self.x.display.xlib.XFlush)(self.x.display.display);
|
||||||
|
(self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor);
|
||||||
self.x.display.check_errors().expect("Failed to call XDefineCursor");
|
self.x.display.check_errors().expect("Failed to call XDefineCursor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
|
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
|
||||||
use CursorState::{ Grab, Normal };
|
use CursorState::{ Grab, Normal, Hide };
|
||||||
|
|
||||||
let mut cursor_state = self.cursor_state.lock().unwrap();
|
let mut cursor_state = self.cursor_state.lock().unwrap();
|
||||||
|
|
||||||
match (state, *cursor_state) {
|
match (state, *cursor_state) {
|
||||||
(Normal, Grab) => {
|
(Normal, Normal) | (Hide, Hide) | (Grab, Grab) => return Ok(()),
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
match *cursor_state {
|
||||||
|
Grab => {
|
||||||
unsafe {
|
unsafe {
|
||||||
(self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime);
|
(self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime);
|
||||||
self.x.display.check_errors().expect("Failed to call XUngrabPointer");
|
self.x.display.check_errors().expect("Failed to call XUngrabPointer");
|
||||||
*cursor_state = Normal;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Normal => {},
|
||||||
(Grab, Normal) => {
|
Hide => {
|
||||||
unsafe {
|
unsafe {
|
||||||
*cursor_state = Grab;
|
let xcursor = (self.x.display.xlib.XCreateFontCursor)(self.x.display.display, 68/*XC_left_ptr*/);
|
||||||
|
self.x.display.check_errors().expect("Failed to call XCreateFontCursor");
|
||||||
|
(self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor);
|
||||||
|
self.x.display.check_errors().expect("Failed to call XDefineCursor");
|
||||||
|
(self.x.display.xlib.XFlush)(self.x.display.display);
|
||||||
|
(self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
*cursor_state = state;
|
||||||
|
match state {
|
||||||
|
Normal => Ok(()),
|
||||||
|
Hide => {
|
||||||
|
let data = &[0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
|
unsafe {
|
||||||
|
let mut black = ffi::XColor {
|
||||||
|
red: 0, green: 0, blue: 0,
|
||||||
|
pad: 0, pixel: 0, flags: 0,
|
||||||
|
};
|
||||||
|
let bitmap = (self.x.display.xlib.XCreateBitmapFromData)(self.x.display.display, self.x.window, data.as_ptr(), 8, 8);
|
||||||
|
let cursor = (self.x.display.xlib.XCreatePixmapCursor)(self.x.display.display, bitmap, bitmap, &mut black, &mut black, 0, 0);
|
||||||
|
(self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, cursor);
|
||||||
|
self.x.display.check_errors().expect("Failed to call XDefineCursor");
|
||||||
|
(self.x.display.xlib.XFreeCursor)(self.x.display.display, cursor);
|
||||||
|
(self.x.display.xlib.XFreePixmap)(self.x.display.display, bitmap);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Grab => {
|
||||||
|
unsafe {
|
||||||
match (self.x.display.xlib.XGrabPointer)(
|
match (self.x.display.xlib.XGrabPointer)(
|
||||||
self.x.display.display, self.x.window, ffi::False,
|
self.x.display.display, self.x.window, ffi::False,
|
||||||
(ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask |
|
(ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask |
|
||||||
|
@ -886,11 +918,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Nothing needs to change
|
|
||||||
(Grab, Grab) | (Normal, Normal) => Ok(()),
|
|
||||||
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue