window: Replace MouseCursor with cursor-icon from winit (#8100)
This commit is contained in:
1 parent
572f7496e4
commit
08e50ca2cd
12 files changed
+188
-92
No files matched your search
Generated
+1
@@ -7614,6 +7614,7 @@ dependencies = [
|
||||
"config",
|
||||
"core-foundation 0.10.0",
|
||||
"core-graphics 0.24.0",
|
||||
"cursor-icon",
|
||||
"dirs-next",
|
||||
"downcast-rs",
|
||||
"euclid",
|
||||
|
||||
@@ -74,6 +74,7 @@ core-text = "=21.0.0"
|
||||
criterion = "0.5"
|
||||
crossbeam = "0.8"
|
||||
csscolorparser = "0.6"
|
||||
cursor-icon = "1.2"
|
||||
deltae = "0.3"
|
||||
dhat = "0.3"
|
||||
dirs-next = "2.0"
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::termwindow::{
|
||||
GuiWin, MouseCapture, PositionedSplit, ScrollHit, TermWindowNotif, UIItem, UIItemType, TMB,
|
||||
};
|
||||
use ::window::{
|
||||
MouseButtons as WMB, MouseCursor, MouseEvent, MouseEventKind as WMEK, MousePress,
|
||||
CursorIcon, MouseButtons as WMB, MouseEvent, MouseEventKind as WMEK, MousePress,
|
||||
WindowDecorations, WindowOps, WindowState,
|
||||
};
|
||||
use config::keyassignment::{KeyAssignment, MouseEventTrigger, SpawnTabDomain};
|
||||
@@ -247,7 +247,7 @@ impl super::TermWindow {
|
||||
pub fn mouse_leave_impl(&mut self, context: &dyn WindowOps) {
|
||||
self.current_mouse_event = None;
|
||||
self.update_title();
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
context.invalidate();
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ impl super::TermWindow {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
}
|
||||
|
||||
fn do_new_tab_button_click(&mut self, button: MousePress) {
|
||||
@@ -560,7 +560,7 @@ impl super::TermWindow {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
}
|
||||
|
||||
pub fn mouse_event_above_scroll_thumb(
|
||||
@@ -585,7 +585,7 @@ impl super::TermWindow {
|
||||
);
|
||||
context.invalidate();
|
||||
}
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
}
|
||||
|
||||
pub fn mouse_event_below_scroll_thumb(
|
||||
@@ -610,7 +610,7 @@ impl super::TermWindow {
|
||||
);
|
||||
context.invalidate();
|
||||
}
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
}
|
||||
|
||||
pub fn mouse_event_scroll_thumb(
|
||||
@@ -625,7 +625,7 @@ impl super::TermWindow {
|
||||
// self.scroll_drag_start = Some(from_top);
|
||||
self.dragging = Some((item, event));
|
||||
}
|
||||
context.set_cursor(Some(MouseCursor::Arrow));
|
||||
context.set_cursor(Some(CursorIcon::Default));
|
||||
}
|
||||
|
||||
pub fn mouse_event_split(
|
||||
@@ -636,8 +636,8 @@ impl super::TermWindow {
|
||||
context: &dyn WindowOps,
|
||||
) {
|
||||
context.set_cursor(Some(match &split.direction {
|
||||
SplitDirection::Horizontal => MouseCursor::SizeLeftRight,
|
||||
SplitDirection::Vertical => MouseCursor::SizeUpDown,
|
||||
SplitDirection::Horizontal => CursorIcon::EwResize,
|
||||
SplitDirection::Vertical => CursorIcon::NsResize,
|
||||
}));
|
||||
|
||||
if event.kind == WMEK::Press(MousePress::Left) {
|
||||
@@ -836,11 +836,11 @@ impl super::TermWindow {
|
||||
context.set_cursor(Some(if self.current_highlight.is_some() {
|
||||
// When hovering over a hyperlink, show an appropriate
|
||||
// mouse cursor to give the cue that it is clickable
|
||||
MouseCursor::Hand
|
||||
CursorIcon::Pointer
|
||||
} else if pane.is_mouse_grabbed() || outside_window {
|
||||
MouseCursor::Arrow
|
||||
CursorIcon::Default
|
||||
} else {
|
||||
MouseCursor::Text
|
||||
CursorIcon::Text
|
||||
}));
|
||||
|
||||
let event_trigger_type = match &event.kind {
|
||||
|
||||
@@ -25,6 +25,7 @@ async-trait.workspace = true
|
||||
anyhow.workspace = true
|
||||
bytes.workspace = true
|
||||
config.workspace = true
|
||||
cursor-icon.workspace = true
|
||||
downcast-rs.workspace = true
|
||||
thiserror.workspace = true
|
||||
bitflags.workspace = true
|
||||
|
||||
@@ -47,7 +47,7 @@ impl MyWindow {
|
||||
WindowEvent::MouseEvent(event) => {
|
||||
self.cursor_pos = event.coords;
|
||||
// win.invalidate();
|
||||
win.set_cursor(Some(MouseCursor::Arrow));
|
||||
win.set_cursor(Some(CursorIcon::Default));
|
||||
|
||||
if event.kind == MouseEventKind::Press(MousePress::Left) {
|
||||
eprintln!("{:?}", event);
|
||||
@@ -55,11 +55,11 @@ impl MyWindow {
|
||||
}
|
||||
WindowEvent::KeyEvent(key) => {
|
||||
eprintln!("{:?}", key);
|
||||
win.set_cursor(Some(MouseCursor::Text));
|
||||
win.set_cursor(Some(CursorIcon::Text));
|
||||
}
|
||||
WindowEvent::RawKeyEvent(key) => {
|
||||
eprintln!("{:?}", key);
|
||||
win.set_cursor(Some(MouseCursor::Text));
|
||||
win.set_cursor(Some(CursorIcon::Text));
|
||||
}
|
||||
WindowEvent::NeedRepaint => {
|
||||
if let Some(gl) = self.gl.as_mut() {
|
||||
|
||||
+2
-10
@@ -16,6 +16,7 @@ pub mod os;
|
||||
pub mod screen;
|
||||
mod spawn;
|
||||
|
||||
pub use cursor_icon::CursorIcon;
|
||||
pub use raw_window_handle;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -64,15 +65,6 @@ pub type Size = euclid::Size2D<isize, PixelUnit>;
|
||||
pub type SizeF = euclid::Size2D<f32, PixelUnit>;
|
||||
pub type ScreenRect = euclid::Rect<isize, ScreenPixelUnit>;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum MouseCursor {
|
||||
Arrow,
|
||||
Hand,
|
||||
Text,
|
||||
SizeUpDown,
|
||||
SizeLeftRight,
|
||||
}
|
||||
|
||||
/// Represents the preferred appearance of the windowing
|
||||
/// environment.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
@@ -271,7 +263,7 @@ pub trait WindowOps {
|
||||
fn close(&self);
|
||||
|
||||
/// Change the cursor
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>);
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>);
|
||||
|
||||
/// Invalidate the window so that the entire client area will
|
||||
/// be repainted shortly
|
||||
|
||||
@@ -8,8 +8,8 @@ use crate::connection::ConnectionOps;
|
||||
use crate::os::macos::menu::{MenuItem, RepresentedItem};
|
||||
use crate::parameters::{Border, Parameters, TitleBar};
|
||||
use crate::{
|
||||
Clipboard, Connection, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
|
||||
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
|
||||
Clipboard, Connection, CursorIcon, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent,
|
||||
Modifiers, MouseButtons, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
|
||||
RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, ScreenPoint, Size, ULength,
|
||||
WindowDecorations, WindowEvent, WindowEventSender, WindowOps, WindowState,
|
||||
};
|
||||
@@ -780,7 +780,7 @@ impl WindowOps for Window {
|
||||
});
|
||||
}
|
||||
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>) {
|
||||
Connection::with_window_inner(self.id, move |inner| {
|
||||
let _ = inner.set_cursor(cursor);
|
||||
Ok(())
|
||||
@@ -983,6 +983,54 @@ fn screen_point_to_cartesian(point: ScreenPoint) -> NSPoint {
|
||||
}
|
||||
}
|
||||
|
||||
// Official selectors: https://developer.apple.com/documentation/appkit/nscursor#overview
|
||||
// All selectors: https://github.com/mstg/OSX-Runtime-Headers/blob/9e1686ba1c48e0ca17f6baf7cfb209d4f7cfa4f2/AppKit/NSCursor.h
|
||||
fn mouse_icon_selector(cursor: CursorIcon) -> Sel {
|
||||
match cursor {
|
||||
CursorIcon::Alias => sel!(dragLinkCursor),
|
||||
CursorIcon::Cell | CursorIcon::Crosshair => sel!(crosshairCursor),
|
||||
CursorIcon::Copy => sel!(dragCopyCursor),
|
||||
CursorIcon::EResize => sel!(resizeRightCursor),
|
||||
CursorIcon::EwResize | CursorIcon::ColResize => sel!(resizeLeftRightCursor),
|
||||
CursorIcon::Grab | CursorIcon::Move | CursorIcon::AllScroll | CursorIcon::AllResize => {
|
||||
sel!(openHandCursor)
|
||||
}
|
||||
CursorIcon::Grabbing => sel!(closedHandCursor),
|
||||
CursorIcon::Help | CursorIcon::ContextMenu => sel!(contextualMenuCursor),
|
||||
CursorIcon::NResize => sel!(resizeUpCursor),
|
||||
CursorIcon::NeResize | CursorIcon::NeswResize | CursorIcon::SwResize => {
|
||||
sel!(_windowResizeNorthEastSouthWestCursor)
|
||||
}
|
||||
CursorIcon::NoDrop | CursorIcon::NotAllowed => sel!(operationNotAllowedCursor),
|
||||
CursorIcon::NsResize | CursorIcon::RowResize => sel!(resizeUpDownCursor),
|
||||
CursorIcon::NwResize | CursorIcon::NwseResize | CursorIcon::SeResize => {
|
||||
sel!(_windowResizeNorthWestSouthEastCursor)
|
||||
}
|
||||
CursorIcon::Pointer => sel!(pointingHandCursor),
|
||||
CursorIcon::Progress | CursorIcon::Wait => sel!(busyButClickableCursor),
|
||||
CursorIcon::SResize => sel!(resizeDownCursor),
|
||||
CursorIcon::Text => sel!(IBeamCursor),
|
||||
CursorIcon::VerticalText => sel!(IBeamCursorForVerticalLayout),
|
||||
CursorIcon::WResize => sel!(resizeLeftCursor),
|
||||
CursorIcon::ZoomIn => sel!(zoomInCursor),
|
||||
CursorIcon::ZoomOut => sel!(zoomOutCursor),
|
||||
_ => sel!(arrowCursor),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cursor_icons_use_macos_cursors() {
|
||||
assert_eq!(
|
||||
mouse_icon_selector(CursorIcon::Pointer),
|
||||
sel!(pointingHandCursor)
|
||||
);
|
||||
assert_eq!(
|
||||
mouse_icon_selector(CursorIcon::NsResize),
|
||||
sel!(resizeUpDownCursor)
|
||||
);
|
||||
assert_eq!(mouse_icon_selector(CursorIcon::Text), sel!(IBeamCursor));
|
||||
}
|
||||
|
||||
impl WindowInner {
|
||||
fn enable_opengl(&mut self) -> anyhow::Result<Rc<glium::backend::Context>> {
|
||||
if let Some(window_view) = WindowView::get_this(unsafe { &**self.view }) {
|
||||
@@ -1225,20 +1273,22 @@ impl WindowInner {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_cursor(&mut self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&mut self, cursor: Option<CursorIcon>) {
|
||||
unsafe {
|
||||
let ns_cursor_cls = class!(NSCursor);
|
||||
if let Some(cursor) = cursor {
|
||||
// Unconditionally apply the requested cursor, as there are
|
||||
// cases where macOS can decide to change the cursor to something
|
||||
// that we don't know about.
|
||||
let instance: id = match cursor {
|
||||
MouseCursor::Arrow => msg_send![ns_cursor_cls, arrowCursor],
|
||||
MouseCursor::Text => msg_send![ns_cursor_cls, IBeamCursor],
|
||||
MouseCursor::Hand => msg_send![ns_cursor_cls, pointingHandCursor],
|
||||
MouseCursor::SizeUpDown => msg_send![ns_cursor_cls, resizeUpDownCursor],
|
||||
MouseCursor::SizeLeftRight => msg_send![ns_cursor_cls, resizeLeftRightCursor],
|
||||
let selector = mouse_icon_selector(cursor);
|
||||
let cursor_is_supported =
|
||||
from_yes_no(msg_send![ns_cursor_cls, respondsToSelector: selector]);
|
||||
let selector = if cursor_is_supported {
|
||||
selector
|
||||
} else {
|
||||
sel!(arrowCursor)
|
||||
};
|
||||
let instance: id = msg_send![ns_cursor_cls, performSelector: selector];
|
||||
let () = msg_send![ns_cursor_cls, setHiddenUntilMouseMoves: NO];
|
||||
let () = msg_send![instance, set];
|
||||
} else {
|
||||
|
||||
@@ -55,7 +55,7 @@ use wezterm_input_types::{
|
||||
use crate::wayland::WaylandConnection;
|
||||
use crate::x11::KeyboardWithFallback;
|
||||
use crate::{
|
||||
Appearance, Clipboard, Connection, ConnectionOps, Dimensions, MouseCursor, Point, Rect,
|
||||
Appearance, Clipboard, Connection, ConnectionOps, Dimensions, Point, Rect,
|
||||
RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, Window, WindowEvent,
|
||||
WindowEventSender, WindowKeyEvent, WindowOps, WindowState,
|
||||
};
|
||||
@@ -405,7 +405,7 @@ impl WindowOps for WaylandWindow {
|
||||
});
|
||||
}
|
||||
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>) {
|
||||
WaylandConnection::with_window_inner(self.0, move |inner| {
|
||||
inner.set_cursor(cursor);
|
||||
Ok(())
|
||||
@@ -991,7 +991,7 @@ impl WaylandWindowInner {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_cursor(&mut self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&mut self, cursor: Option<CursorIcon>) {
|
||||
if !PendingMouse::in_window(&self.pending_mouse) {
|
||||
return;
|
||||
}
|
||||
@@ -1005,16 +1005,7 @@ impl WaylandWindowInner {
|
||||
|
||||
match cursor {
|
||||
Some(cursor) => {
|
||||
if let Err(err) = pointer.set_cursor(
|
||||
&conn.connection,
|
||||
match cursor {
|
||||
MouseCursor::Arrow => CursorIcon::Default,
|
||||
MouseCursor::Hand => CursorIcon::Pointer,
|
||||
MouseCursor::SizeUpDown => CursorIcon::NsResize,
|
||||
MouseCursor::SizeLeftRight => CursorIcon::EwResize,
|
||||
MouseCursor::Text => CursorIcon::Text,
|
||||
},
|
||||
) {
|
||||
if let Err(err) = pointer.set_cursor(&conn.connection, cursor) {
|
||||
log::error!("set_cursor: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use super::*;
|
||||
use crate::connection::ConnectionOps;
|
||||
use crate::parameters::{self, Parameters};
|
||||
use crate::{
|
||||
Appearance, Clipboard, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
|
||||
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
|
||||
Appearance, Clipboard, CursorIcon, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent,
|
||||
Modifiers, MouseButtons, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
|
||||
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, ScreenRect, ULength, WindowDecorations,
|
||||
WindowEvent, WindowEventSender, WindowOps, WindowState,
|
||||
};
|
||||
@@ -624,7 +624,7 @@ impl WindowInner {
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn set_cursor(&mut self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&mut self, cursor: Option<CursorIcon>) {
|
||||
apply_mouse_cursor(cursor);
|
||||
}
|
||||
|
||||
@@ -854,7 +854,7 @@ impl WindowOps for Window {
|
||||
schedule_show_window(self.0, ShowWindowCommand::Normal);
|
||||
}
|
||||
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>) {
|
||||
Connection::with_window_inner(self.0, move |inner| {
|
||||
inner.set_cursor(cursor);
|
||||
Ok(())
|
||||
@@ -1710,26 +1710,48 @@ fn client_to_screen(hwnd: HWND, point: Point) -> ScreenPoint {
|
||||
ScreenPoint::new(point.x.try_into().unwrap(), point.y.try_into().unwrap())
|
||||
}
|
||||
|
||||
fn apply_mouse_cursor(cursor: Option<MouseCursor>) {
|
||||
fn apply_mouse_cursor(cursor: Option<CursorIcon>) {
|
||||
match cursor {
|
||||
None => unsafe {
|
||||
SetCursor(null_mut());
|
||||
},
|
||||
Some(cursor) => unsafe {
|
||||
SetCursor(LoadCursorW(
|
||||
null_mut(),
|
||||
match cursor {
|
||||
MouseCursor::Arrow => IDC_ARROW,
|
||||
MouseCursor::Hand => IDC_HAND,
|
||||
MouseCursor::Text => IDC_IBEAM,
|
||||
MouseCursor::SizeUpDown => IDC_SIZENS,
|
||||
MouseCursor::SizeLeftRight => IDC_SIZEWE,
|
||||
},
|
||||
));
|
||||
SetCursor(LoadCursorW(null_mut(), mouse_cursor_id(cursor)));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn mouse_cursor_id(cursor: CursorIcon) -> LPCWSTR {
|
||||
match cursor {
|
||||
CursorIcon::Cell | CursorIcon::Crosshair => IDC_CROSS,
|
||||
CursorIcon::EResize
|
||||
| CursorIcon::EwResize
|
||||
| CursorIcon::WResize
|
||||
| CursorIcon::ColResize => IDC_SIZEWE,
|
||||
CursorIcon::Grab | CursorIcon::Grabbing | CursorIcon::Pointer => IDC_HAND,
|
||||
CursorIcon::Help | CursorIcon::ContextMenu => IDC_HELP,
|
||||
CursorIcon::Move | CursorIcon::AllScroll | CursorIcon::AllResize => IDC_SIZEALL,
|
||||
CursorIcon::NResize
|
||||
| CursorIcon::NsResize
|
||||
| CursorIcon::SResize
|
||||
| CursorIcon::RowResize => IDC_SIZENS,
|
||||
CursorIcon::NeResize | CursorIcon::NeswResize | CursorIcon::SwResize => IDC_SIZENESW,
|
||||
CursorIcon::NoDrop | CursorIcon::NotAllowed => IDC_NO,
|
||||
CursorIcon::NwResize | CursorIcon::NwseResize | CursorIcon::SeResize => IDC_SIZENWSE,
|
||||
CursorIcon::Progress => IDC_APPSTARTING,
|
||||
CursorIcon::Text | CursorIcon::VerticalText => IDC_IBEAM,
|
||||
CursorIcon::Wait => IDC_WAIT,
|
||||
_ => IDC_ARROW,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cursor_icons_use_windows_cursors() {
|
||||
assert_eq!(mouse_cursor_id(CursorIcon::Pointer), IDC_HAND);
|
||||
assert_eq!(mouse_cursor_id(CursorIcon::NsResize), IDC_SIZENS);
|
||||
assert_eq!(mouse_cursor_id(CursorIcon::Text), IDC_IBEAM);
|
||||
}
|
||||
|
||||
unsafe fn mouse_button(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<LRESULT> {
|
||||
let inner = rc_from_hwnd(hwnd)?;
|
||||
// To support dragging the window, capture when the left
|
||||
|
||||
+61
-23
@@ -1,6 +1,6 @@
|
||||
use crate::os::x11::xcb_util::*;
|
||||
use crate::x11::XConnection;
|
||||
use crate::MouseCursor;
|
||||
use crate::CursorIcon;
|
||||
use anyhow::{ensure, Context};
|
||||
use config::ConfigHandle;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -13,14 +13,64 @@ use std::rc::{Rc, Weak};
|
||||
use xcb::x::Cursor;
|
||||
use xcb::Xid;
|
||||
|
||||
// `/usr/include/X11/cursorfont.h`
|
||||
// <https://docs.rs/xcb-util/0.3.0/src/xcb_util/cursor.rs.html>
|
||||
// X11 classic Cursor glyphs
|
||||
pub const BOTTOM_LEFT_CORNER: u16 = 12;
|
||||
pub const BOTTOM_RIGHT_CORNER: u16 = 14;
|
||||
pub const BOTTOM_SIDE: u16 = 16;
|
||||
pub const CIRCLE: u16 = 24;
|
||||
pub const CROSSHAIR: u16 = 34;
|
||||
pub const FLEUR: u16 = 52;
|
||||
pub const HAND1: u16 = 58;
|
||||
pub const HAND2: u16 = 60;
|
||||
pub const LEFT_SIDE: u16 = 70;
|
||||
pub const PLUS: u16 = 90;
|
||||
pub const QUESTION_ARROW: u16 = 92;
|
||||
pub const RIGHT_SIDE: u16 = 96;
|
||||
pub const SB_H_DOUBLE_ARROW: u16 = 108;
|
||||
pub const SB_V_DOUBLE_ARROW: u16 = 116;
|
||||
pub const SIZING: u16 = 120;
|
||||
pub const TOP_LEFT_ARROW: u16 = 132;
|
||||
pub const TOP_LEFT_CORNER: u16 = 134;
|
||||
pub const TOP_RIGHT_CORNER: u16 = 136;
|
||||
pub const TOP_SIDE: u16 = 138;
|
||||
pub const WATCH: u16 = 150;
|
||||
pub const XTERM: u16 = 152;
|
||||
|
||||
fn basic_cursor_glyph(cursor: CursorIcon) -> u16 {
|
||||
match cursor {
|
||||
CursorIcon::Cell => PLUS,
|
||||
CursorIcon::Crosshair => CROSSHAIR,
|
||||
CursorIcon::Help | CursorIcon::ContextMenu | CursorIcon::DndAsk => QUESTION_ARROW,
|
||||
CursorIcon::Pointer => HAND2,
|
||||
CursorIcon::Progress | CursorIcon::Wait => WATCH,
|
||||
CursorIcon::Text | CursorIcon::VerticalText => XTERM,
|
||||
CursorIcon::Move | CursorIcon::AllScroll | CursorIcon::AllResize => FLEUR,
|
||||
CursorIcon::NoDrop | CursorIcon::NotAllowed => CIRCLE,
|
||||
CursorIcon::Grab | CursorIcon::Grabbing => HAND1,
|
||||
CursorIcon::EResize => RIGHT_SIDE,
|
||||
CursorIcon::NResize => TOP_SIDE,
|
||||
CursorIcon::NeResize | CursorIcon::NeswResize => TOP_RIGHT_CORNER,
|
||||
CursorIcon::NwResize | CursorIcon::NwseResize => TOP_LEFT_CORNER,
|
||||
CursorIcon::SResize => BOTTOM_SIDE,
|
||||
CursorIcon::SeResize => BOTTOM_RIGHT_CORNER,
|
||||
CursorIcon::SwResize => BOTTOM_LEFT_CORNER,
|
||||
CursorIcon::WResize => LEFT_SIDE,
|
||||
CursorIcon::EwResize | CursorIcon::ColResize => SB_H_DOUBLE_ARROW,
|
||||
CursorIcon::NsResize | CursorIcon::RowResize => SB_V_DOUBLE_ARROW,
|
||||
CursorIcon::ZoomIn | CursorIcon::ZoomOut => SIZING,
|
||||
_ => TOP_LEFT_ARROW,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cursor_icons_use_x11_cursor_glyphs() {
|
||||
assert_eq!(basic_cursor_glyph(CursorIcon::Pointer), HAND2);
|
||||
assert_eq!(basic_cursor_glyph(CursorIcon::NeResize), TOP_RIGHT_CORNER);
|
||||
assert_eq!(basic_cursor_glyph(CursorIcon::Text), XTERM);
|
||||
}
|
||||
|
||||
pub struct XcbCursor {
|
||||
pub id: Cursor,
|
||||
pub conn: Weak<XConnection>,
|
||||
@@ -35,8 +85,8 @@ impl Drop for XcbCursor {
|
||||
}
|
||||
|
||||
pub struct CursorInfo {
|
||||
cursors: HashMap<Option<MouseCursor>, XcbCursor>,
|
||||
cursor: Option<MouseCursor>,
|
||||
cursors: HashMap<Option<CursorIcon>, XcbCursor>,
|
||||
cursor: Option<CursorIcon>,
|
||||
conn: Weak<XConnection>,
|
||||
size: Option<u32>,
|
||||
theme: Option<String>,
|
||||
@@ -195,7 +245,7 @@ impl CursorInfo {
|
||||
pub fn set_cursor(
|
||||
&mut self,
|
||||
window_id: xcb::x::Window,
|
||||
cursor: Option<MouseCursor>,
|
||||
cursor: Option<CursorIcon>,
|
||||
) -> anyhow::Result<()> {
|
||||
if cursor == self.cursor {
|
||||
return Ok(());
|
||||
@@ -287,7 +337,7 @@ impl CursorInfo {
|
||||
fn load_themed(
|
||||
&mut self,
|
||||
conn: &Rc<XConnection>,
|
||||
cursor: Option<MouseCursor>,
|
||||
cursor: Option<CursorIcon>,
|
||||
) -> Option<Cursor> {
|
||||
if cursor.is_none() {
|
||||
match self.create_blank(conn) {
|
||||
@@ -303,7 +353,7 @@ impl CursorInfo {
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Failed to create blank cursor: {:#}", err);
|
||||
return self.load_themed(conn, Some(MouseCursor::Arrow));
|
||||
return self.load_themed(conn, Some(CursorIcon::Default));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,13 +361,7 @@ impl CursorInfo {
|
||||
let theme = self.theme.as_deref().unwrap_or("default");
|
||||
self.pict_format_id?;
|
||||
|
||||
let names: &[&str] = match cursor.unwrap_or(MouseCursor::Arrow) {
|
||||
MouseCursor::Arrow => &["top_left_arrow", "left_ptr"],
|
||||
MouseCursor::Hand => &["hand2"],
|
||||
MouseCursor::Text => &["xterm"],
|
||||
MouseCursor::SizeUpDown => &["sb_v_double_arrow"],
|
||||
MouseCursor::SizeLeftRight => &["sb_h_double_arrow"],
|
||||
};
|
||||
let icon = cursor.unwrap_or_default();
|
||||
|
||||
let mut theme_list = vec![theme.to_string()];
|
||||
let mut visited = HashSet::new();
|
||||
@@ -331,6 +375,8 @@ impl CursorInfo {
|
||||
visited.insert(theme.clone());
|
||||
|
||||
for dir in &self.icon_path {
|
||||
// Try the W3C name first, followed by common X11 aliases.
|
||||
let names = std::iter::once(icon.name()).chain(icon.alt_names().iter().copied());
|
||||
for name in names {
|
||||
let candidate = dir.join(&theme).join("cursors").join(name);
|
||||
log::trace!(
|
||||
@@ -367,16 +413,8 @@ impl CursorInfo {
|
||||
None
|
||||
}
|
||||
|
||||
fn load_basic(&mut self, conn: &Rc<XConnection>, cursor: Option<MouseCursor>) -> Cursor {
|
||||
let id_no = match cursor.unwrap_or(MouseCursor::Arrow) {
|
||||
// `/usr/include/X11/cursorfont.h`
|
||||
// <https://docs.rs/xcb-util/0.3.0/src/xcb_util/cursor.rs.html>
|
||||
MouseCursor::Arrow => TOP_LEFT_ARROW,
|
||||
MouseCursor::Hand => HAND1,
|
||||
MouseCursor::Text => XTERM,
|
||||
MouseCursor::SizeUpDown => SB_V_DOUBLE_ARROW,
|
||||
MouseCursor::SizeLeftRight => SB_H_DOUBLE_ARROW,
|
||||
};
|
||||
fn load_basic(&mut self, conn: &Rc<XConnection>, cursor: Option<CursorIcon>) -> Cursor {
|
||||
let id_no = basic_cursor_glyph(cursor.unwrap_or_default());
|
||||
log::trace!("loading X11 basic cursor {} for {:?}", id_no, cursor);
|
||||
|
||||
let cursor_id: Cursor = conn.generate_id();
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::bitmaps::*;
|
||||
use crate::connection::ConnectionOps;
|
||||
use crate::os::{xkeysyms, Connection, Window};
|
||||
use crate::{
|
||||
Appearance, Clipboard, DeadKeyStatus, Dimensions, MouseButtons, MouseCursor, MouseEvent,
|
||||
Appearance, Clipboard, CursorIcon, DeadKeyStatus, Dimensions, MouseButtons, MouseEvent,
|
||||
MouseEventKind, MousePress, Point, Rect, RequestedWindowGeometry, ResizeIncrement,
|
||||
ResolvedGeometry, ScreenPoint, ScreenRect, WindowDecorations, WindowEvent, WindowEventSender,
|
||||
WindowOps, WindowState,
|
||||
@@ -235,7 +235,7 @@ impl XWindowInner {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_cursor(&mut self, cursor: Option<MouseCursor>) -> anyhow::Result<()> {
|
||||
fn set_cursor(&mut self, cursor: Option<CursorIcon>) -> anyhow::Result<()> {
|
||||
self.cursors.set_cursor(self.window_id, cursor)
|
||||
}
|
||||
|
||||
@@ -2028,7 +2028,7 @@ impl WindowOps for XWindow {
|
||||
});
|
||||
}
|
||||
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>) {
|
||||
XConnection::with_window_inner(self.0, move |inner| {
|
||||
let _ = inner.set_cursor(cursor);
|
||||
Ok(())
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::os::x11::connection::XConnection;
|
||||
use crate::os::x11::window::XWindow;
|
||||
use crate::screen::Screens;
|
||||
use crate::{
|
||||
Appearance, Clipboard, MouseCursor, Rect, RequestedWindowGeometry, ResizeIncrement,
|
||||
ScreenPoint, WindowEvent, WindowOps,
|
||||
Appearance, Clipboard, CursorIcon, Rect, RequestedWindowGeometry, ResizeIncrement, ScreenPoint,
|
||||
WindowEvent, WindowOps,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use config::ConfigHandle;
|
||||
@@ -298,7 +298,7 @@ impl WindowOps for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_cursor(&self, cursor: Option<MouseCursor>) {
|
||||
fn set_cursor(&self, cursor: Option<CursorIcon>) {
|
||||
match self {
|
||||
Self::X11(x) => x.set_cursor(cursor),
|
||||
#[cfg(feature = "wayland")]
|
||||
|
||||
Reference in new issue
Block a user