aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/mod.rs3
-rw-r--r--src/lib.rs62
-rw-r--r--src/osx/mod.rs6
-rw-r--r--src/win32/mod.rs6
-rw-r--r--src/x11/ffi.rs4
-rw-r--r--src/x11/window/mod.rs49
6 files changed, 127 insertions, 3 deletions
diff --git a/src/android/mod.rs b/src/android/mod.rs
index 0dbe164..0c88709 100644
--- a/src/android/mod.rs
+++ b/src/android/mod.rs
@@ -280,6 +280,9 @@ impl Window {
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
}
+
+ pub fn set_cursor(&self, cursor: MouseCursor) {
+ }
}
unsafe impl Send for Window {}
diff --git a/src/lib.rs b/src/lib.rs
index ce9b524..a970b36 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,6 +90,62 @@ pub enum Api {
OpenGlEs,
}
+#[derive(Show, Copy)]
+pub enum MouseCursor {
+ /// The platform-dependent default cursor.
+ Default,
+ /// A simple crosshair.
+ Crosshair,
+ /// A hand (often used to indicate links in web browsers).
+ Hand,
+ /// Self explanatory.
+ Arrow,
+ /// Indicates something is to be moved.
+ Move,
+ /// Indicates text that may be selected or edited.
+ Text,
+ /// Program busy indicator.
+ Wait,
+ /// Help indicator (often rendered as a "?")
+ Help,
+ /// Progress indicator. Shows that processing is being done. But in contrast
+ /// with "Wait" the user may still interact with the program. Often rendered
+ /// as a spinning beach ball, or an arrow with a watch or hourglass.
+ Progress,
+
+ /// Cursor showing that something cannot be done.
+ NotAllowed,
+ ContextMenu,
+ NoneCursor,
+ Cell,
+ VerticalText,
+ Alias,
+ Copy,
+ NoDrop,
+ Grab,
+ Grabbing,
+ AllScroll,
+ ZoomIn,
+ ZoomOut,
+
+ /// Indicate that some edge is to be moved. For example, the 'SeResize' cursor
+ /// is used when the movement starts from the south-east corner of the box.
+ EResize,
+ NResize,
+ NeResize,
+ NwResize,
+ SResize,
+ SeResize,
+ SwResize,
+ WResize,
+ EwResize,
+ NsResize,
+ NeswResize,
+ NwseResize,
+ ColResize,
+ RowResize,
+}
+
/// Object that allows you to build windows.
#[cfg(feature = "window")]
pub struct WindowBuilder<'a> {
@@ -559,6 +615,12 @@ impl Window {
pub fn set_window_resize_callback(&mut self, callback: Option<fn(usize, usize)>) {
self.window.set_window_resize_callback(callback);
}
+
+ /// Modifies the mouse cursor of the window.
+ /// Has no effect on Android.
+ pub fn set_cursor(&mut self, cursor: MouseCursor) {
+ self.window.set_cursor(cursor);
+ }
}
#[cfg(feature = "window")]
diff --git a/src/osx/mod.rs b/src/osx/mod.rs
index df62089..7b362ba 100644
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -1,7 +1,7 @@
#[cfg(feature = "headless")]
pub use self::headless::HeadlessContext;
-use {CreationError, Event};
+use {CreationError, Event, MouseCursor};
use CreationError::OsError;
use libc;
@@ -491,4 +491,8 @@ impl Window {
pub fn set_window_resize_callback(&mut self, callback: Option<fn(uint, uint)>) {
self.resize = callback;
}
+
+ pub fn set_cursor(&self, cursor: MouseCursor) {
+ unimplemented!()
+ }
}
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 168771d..463d5fe 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -4,7 +4,7 @@ use std::ffi::CString;
use std::collections::RingBuf;
use std::sync::mpsc::Receiver;
use libc;
-use {CreationError, Event};
+use {CreationError, Event, MouseCursor};
use BuilderAttribs;
@@ -285,6 +285,10 @@ impl Window {
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
}
+
+ pub fn set_cursor(&self, cursor: MouseCursor) {
+ unimplemented!()
+ }
}
#[unsafe_destructor]
diff --git a/src/x11/ffi.rs b/src/x11/ffi.rs
index 0528720..5e7b5a1 100644
--- a/src/x11/ffi.rs
+++ b/src/x11/ffi.rs
@@ -1384,6 +1384,7 @@ extern "C" {
#[link(name = "GL")]
#[link(name = "X11")]
#[link(name = "Xxf86vm")]
+#[link(name = "Xcursor")]
extern "C" {
pub fn XCloseDisplay(display: *mut Display);
pub fn XCheckMaskEvent(display: *mut Display, event_mask: libc::c_long,
@@ -1454,6 +1455,9 @@ extern "C" {
x: libc::c_int, y: libc::c_int) -> Bool;
pub fn XF86VidModeGetAllModeLines(dpy: *mut Display, screen: libc::c_int,
modecount_return: *mut libc::c_int, modesinfo: *mut *mut *mut XF86VidModeModeInfo) -> Bool;
+
+ pub fn XcursorLibraryLoadCursor(dpy: *mut Display, name: *const libc::c_char) -> Cursor;
+ pub fn XDefineCursor(dby: *mut Display, w: Window, cursor: Cursor);
}
/*
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);
+ }
+ }
}