aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/window
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-01-13 10:43:46 +0100
committertomaka <pierre.krieger1708@gmail.com>2015-01-13 10:43:46 +0100
commit05a03fb6a1232621e570fe46a82c6088c74696a9 (patch)
treef066387449265cb233fbc6040a0902a6a4df9360 /src/x11/window
parent88fd84f5952ba9fc758957bdc55b911ec694d46b (diff)
parent0fba0a9a734dcc7c30f9c369d6481a9b1d33828c (diff)
downloadglutin-05a03fb6a1232621e570fe46a82c6088c74696a9.tar.gz
glutin-05a03fb6a1232621e570fe46a82c6088c74696a9.zip
Merge pull request #192 from bjwbell/mouse-cursors
Add mouse cursor support
Diffstat (limited to 'src/x11/window')
-rw-r--r--src/x11/window/mod.rs49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 7f85675..904bef9 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -1,4 +1,4 @@
-use {Event, BuilderAttribs};
+use {Event, BuilderAttribs, MouseCursor};
use CreationError;
use CreationError::OsError;
use libc;
@@ -611,4 +611,51 @@ impl Window {
pub fn set_window_resize_callback(&mut self, _: Option<fn(usize, usize)>) {
}
+
+ pub fn set_cursor(&self, cursor: MouseCursor) {
+ unsafe {
+ use std::ffi::CString;
+ let cursor_name = match cursor {
+ MouseCursor::Alias => "link",
+ MouseCursor::Arrow => "arrow",
+ MouseCursor::Cell => "plus",
+ MouseCursor::Copy => "copy",
+ MouseCursor::Crosshair => "crosshair",
+ MouseCursor::Default => "left_ptr",
+ MouseCursor::Grabbing => "grabbing",
+ MouseCursor::Hand | MouseCursor::Grab => "hand",
+ MouseCursor::Help => "question_arrow",
+ MouseCursor::Move => "move",
+ MouseCursor::NoDrop => "circle",
+ MouseCursor::NotAllowed => "crossed_circle",
+ MouseCursor::Progress => "left_ptr_watch",
+
+ /// Resize cursors
+ MouseCursor::EResize => "right_side",
+ MouseCursor::NResize => "top_side",
+ MouseCursor::NeResize => "top_right_corner",
+ MouseCursor::NwResize => "top_left_corner",
+ MouseCursor::SResize => "bottom_side",
+ MouseCursor::SeResize => "bottom_right_corner",
+ MouseCursor::SwResize => "bottom_left_corner",
+ MouseCursor::WResize => "left_side",
+ MouseCursor::EwResize | MouseCursor::ColResize => "h_double_arrow",
+ MouseCursor::NsResize | MouseCursor::RowResize => "v_double_arrow",
+ MouseCursor::NwseResize => "bd_double_arrow",
+ MouseCursor::NeswResize => "fd_double_arrow",
+
+ MouseCursor::Text | MouseCursor::VerticalText => "xterm",
+ MouseCursor::Wait => "watch",
+
+ /// TODO: Find matching X11 cursors
+ MouseCursor::ContextMenu | MouseCursor::NoneCursor |
+ MouseCursor::AllScroll | MouseCursor::ZoomIn |
+ MouseCursor::ZoomOut => "left_ptr",
+ };
+ let c_string = CString::from_slice(cursor_name.as_bytes());
+ let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
+ ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
+ ffi::XFlush(self.x.display);
+ }
+ }
}