diff options
author | Emilio Cobos Álvarez <me@emiliocobos.me> | 2016-04-17 17:32:34 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <me@emiliocobos.me> | 2016-04-17 17:41:58 +0200 |
commit | 51aeb27d7e231227c34bc822da3e7f27b42b54f4 (patch) | |
tree | d19150dadd22764841e2982e23f59dae4527bee3 /src | |
parent | 558eeadbd5969b330c83efa10f3fd8b22d543f32 (diff) | |
download | glutin-51aeb27d7e231227c34bc822da3e7f27b42b54f4.tar.gz glutin-51aeb27d7e231227c34bc822da3e7f27b42b54f4.zip |
x11: Add cursor hiding
The created cursor could be cached and whatnot, but I'm not sure it
deserves the complexity.
Diffstat (limited to 'src')
-rw-r--r-- | src/api/x11/window.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index b524795..85ad70d 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -11,6 +11,7 @@ use std::sync::{Arc, Mutex}; use std::os::raw::c_long; use std::thread; use std::time::Duration; +use x11_dl::xlib; use Api; use ContextError; @@ -902,8 +903,7 @@ impl Window { MouseCursor::ZoomIn => load("zoom-in"), MouseCursor::ZoomOut => load("zoom-out"), - // TODO: Hide cursor - MouseCursor::NoneCursor => 0, + MouseCursor::NoneCursor => self.create_empty_cursor(), }; (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> { use CursorState::{ Grab, Normal, Hide }; |