aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/x11/window.rs32
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 };