Skip to content

Commit

Permalink
When using glutin, set the mouse cursor
Browse files Browse the repository at this point in the history
Only call set_cursor on linux, since glutin
currently only implements set_cursor on linux.
  • Loading branch information
bjwbell committed Feb 13, 2015
1 parent 58b7186 commit e277199
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion ports/glutin/window.rs
Expand Up @@ -27,7 +27,7 @@ use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg};
#[cfg(feature = "window")]
use geom::point::{Point2D, TypedPoint2D};
#[cfg(feature = "window")]
use glutin::{ElementState, Event, MouseButton, VirtualKeyCode};
use glutin::{ElementState, Event, MouseButton, MouseCursor, VirtualKeyCode};
#[cfg(feature = "window")]
use msg::constellation_msg::{KeyState, CONTROL, SHIFT, ALT};
#[cfg(feature = "window")]
Expand Down Expand Up @@ -491,8 +491,56 @@ impl WindowMethods for Window {
fn load_end(&self) {
}

// TODO: Enable on macos when supported by glutin.
#[cfg(target_os="macos")]
fn set_cursor(&self, _: Cursor) {
}

#[cfg(target_os="android")]
fn set_cursor(&self, _: Cursor) {
}

#[cfg(target_os="linux")]
fn set_cursor(&self, c: Cursor) {
let glutin_cursor = match c {
Cursor::NoCursor => MouseCursor::NoneCursor,
Cursor::DefaultCursor => MouseCursor::Default,
Cursor::PointerCursor => MouseCursor::Hand,
Cursor::ContextMenuCursor => MouseCursor::ContextMenu,
Cursor::HelpCursor => MouseCursor::Help,
Cursor::ProgressCursor => MouseCursor::Progress,
Cursor::WaitCursor => MouseCursor::Wait,
Cursor::CellCursor => MouseCursor::Cell,
Cursor::CrosshairCursor => MouseCursor::Crosshair,
Cursor::TextCursor => MouseCursor::Text,
Cursor::VerticalTextCursor => MouseCursor::VerticalText,
Cursor::AliasCursor => MouseCursor::Alias,
Cursor::CopyCursor => MouseCursor::Copy,
Cursor::MoveCursor => MouseCursor::Move,
Cursor::NoDropCursor => MouseCursor::NoDrop,
Cursor::NotAllowedCursor => MouseCursor::NotAllowed,
Cursor::GrabCursor => MouseCursor::Grab,
Cursor::GrabbingCursor => MouseCursor::Grabbing,
Cursor::EResizeCursor => MouseCursor::EResize,
Cursor::NResizeCursor => MouseCursor::NResize,
Cursor::NeResizeCursor => MouseCursor::NeResize,
Cursor::NwResizeCursor => MouseCursor::NwResize,
Cursor::SResizeCursor => MouseCursor::SResize,
Cursor::SeResizeCursor => MouseCursor::SeResize,
Cursor::SwResizeCursor => MouseCursor::SwResize,
Cursor::WResizeCursor => MouseCursor::WResize,
Cursor::EwResizeCursor => MouseCursor::EwResize,
Cursor::NsResizeCursor => MouseCursor::NsResize,
Cursor::NeswResizeCursor => MouseCursor::NeswResize,
Cursor::NwseResizeCursor => MouseCursor::NwseResize,
Cursor::ColResizeCursor => MouseCursor::ColResize,
Cursor::RowResizeCursor => MouseCursor::RowResize,
Cursor::AllScrollCursor => MouseCursor::AllScroll,
Cursor::ZoomInCursor => MouseCursor::ZoomIn,
Cursor::ZoomOutCursor => MouseCursor::ZoomOut,
};
self.window.set_cursor(glutin_cursor);
}

fn prepare_for_composite(&self) -> bool {
true
Expand Down

5 comments on commit e277199

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from glennw
at bjwbell@e277199

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjwbell/servo/mouse-cursor = e277199 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjwbell/servo/mouse-cursor = e277199 merged ok, testing candidate = a848a00

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a848a00

Please sign in to comment.