diff options
Diffstat (limited to 'src/x11')
-rw-r--r-- | src/x11/ffi.rs | 4 | ||||
-rw-r--r-- | src/x11/window/mod.rs | 46 |
2 files changed, 49 insertions, 1 deletions
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 cff2c61..402beec 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,48 @@ impl Window { pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) { } + + pub fn set_cursor(&self, cursor: MouseCursor) { + unsafe { + use std::ffi::CString; + let cursor_name = match cursor { + MouseCursor::Default => "left_ptr", + MouseCursor::Crosshair => "crosshair", + MouseCursor::Hand => "hand", + MouseCursor::Arrow => "arrow", + MouseCursor::Move => "fleur", + MouseCursor::Text => "xterm", + MouseCursor::Wait => "watch", + MouseCursor::Help => "question_arrow", + MouseCursor::Progress => "watch", // TODO: Find better matching X11 cursor + 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 => "h_double_arrow", + MouseCursor::NsResize => "v_double_arrow", + + + MouseCursor::NeswResize | MouseCursor::NwseResize => "sizing", // TODO: Better matching X11 cursor + + MouseCursor::ColResize | MouseCursor::RowResize => "double_arrow", // TODO: Better matching X11 cursor + + /// TODO: Find matching X11 cursors + MouseCursor::NotAllowed | MouseCursor::ContextMenu | + MouseCursor::NoneCursor | MouseCursor::Cell | + MouseCursor::VerticalText | MouseCursor::Alias | + MouseCursor::Copy | MouseCursor::NoDrop | MouseCursor::Grab | + MouseCursor::Grabbing | 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); + } + } } |