mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
x11: Add cursor hiding
The created cursor could be cached and whatnot, but I'm not sure it deserves the complexity.
This commit is contained in:
parent
558eeadbd5
commit
51aeb27d7e
|
@ -11,6 +11,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::os::raw::c_long;
|
use std::os::raw::c_long;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use x11_dl::xlib;
|
||||||
|
|
||||||
use Api;
|
use Api;
|
||||||
use ContextError;
|
use ContextError;
|
||||||
|
@ -902,8 +903,7 @@ impl Window {
|
||||||
MouseCursor::ZoomIn => load("zoom-in"),
|
MouseCursor::ZoomIn => load("zoom-in"),
|
||||||
MouseCursor::ZoomOut => load("zoom-out"),
|
MouseCursor::ZoomOut => load("zoom-out"),
|
||||||
|
|
||||||
// TODO: Hide cursor
|
MouseCursor::NoneCursor => self.create_empty_cursor(),
|
||||||
MouseCursor::NoneCursor => 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(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);
|
||||||
|
@ -914,6 +914,34 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This could maybe be cached. I don't think it's worth
|
||||||
|
// the complexity, since cursor changes are not so common,
|
||||||
|
// and this is just allocating a 1x1 pixmap...
|
||||||
|
fn create_empty_cursor(&self) -> xlib::Cursor {
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
let data = 0;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let pixmap = (self.x.display.xlib.XCreateBitmapFromData)(self.x.display.display, self.x.window, &data, 1, 1);
|
||||||
|
if pixmap == 0 {
|
||||||
|
// Failed to allocate
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't care about this color, since it only fills bytes
|
||||||
|
// in the pixmap which are not 0 in the mask.
|
||||||
|
let dummy_color: xlib::XColor = mem::uninitialized();
|
||||||
|
let cursor = (self.x.display.xlib.XCreatePixmapCursor)(self.x.display.display,
|
||||||
|
pixmap,
|
||||||
|
pixmap,
|
||||||
|
&dummy_color as *const _ as *mut _,
|
||||||
|
&dummy_color as *const _ as *mut _, 0, 0);
|
||||||
|
(self.x.display.xlib.XFreePixmap)(self.x.display.display, pixmap);
|
||||||
|
cursor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
|
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
|
||||||
use CursorState::{ Grab, Normal, Hide };
|
use CursorState::{ Grab, Normal, Hide };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue