Skip to content

Commit

Permalink
api: add alt_names for cursor icons
Browse files Browse the repository at this point in the history
Add alternative names for the cursor icon to provide Wayland/X11 users with
fallbacks they can try before deciding that there's no matching icon found.

The cursor names was picked by various toolkits doing similar fallbacks.
  • Loading branch information
Friz64 authored Nov 2, 2023
1 parent 108c2a1 commit 9d77551
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ The sections should follow the order `Packaging`, `Added`, `Changed`, `Fixed` an

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Unreleased
## Unreleased

### Added

- Access to alternative names for cursor icons through the `CursorIcon::alt_names` method.
44 changes: 44 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,50 @@ impl CursorIcon {
CursorIcon::ZoomOut => "zoom-out",
}
}

/// A list of alternative names for the cursor icon as commonly found in
/// legacy Xcursor themes.
///
/// This should only be used as a fallback in case the cursor theme does not
/// adhere to the w3c standard.
pub fn alt_names(&self) -> &[&'static str] {
match self {
CursorIcon::Default => &["left_ptr", "arrow", "top_left_arrow", "left_arrow"],
CursorIcon::ContextMenu => &[],
CursorIcon::Help => &["question_arrow", "whats_this"],
CursorIcon::Pointer => &["hand2", "hand1", "hand", "pointing_hand"],
CursorIcon::Progress => &["left_ptr_watch", "half-busy"],
CursorIcon::Wait => &["watch"],
CursorIcon::Cell => &["plus"],
CursorIcon::Crosshair => &["cross"],
CursorIcon::Text => &["xterm", "ibeam"],
CursorIcon::VerticalText => &[],
CursorIcon::Alias => &["link"],
CursorIcon::Copy => &[],
CursorIcon::Move => &[],
CursorIcon::NoDrop => &["circle"],
CursorIcon::NotAllowed => &["crossed_circle", "forbidden"],
CursorIcon::Grab => &["openhand", "fleur"],
CursorIcon::Grabbing => &["closedhand"],
CursorIcon::EResize => &["right_side"],
CursorIcon::NResize => &["top_side"],
CursorIcon::NeResize => &["top_right_corner"],
CursorIcon::NwResize => &["top_left_corner"],
CursorIcon::SResize => &["bottom_side"],
CursorIcon::SeResize => &["bottom_right_corner"],
CursorIcon::SwResize => &["bottom_left_corner"],
CursorIcon::WResize => &["left_side"],
CursorIcon::EwResize => &["h_double_arrow", "size_hor"],
CursorIcon::NsResize => &["v_double_arrow", "size_ver"],
CursorIcon::NeswResize => &["fd_double_arrow", "size_bdiag"],
CursorIcon::NwseResize => &["bd_double_arrow", "size_fdiag"],
CursorIcon::ColResize => &["split_h", "h_double_arrow", "sb_h_double_arrow"],
CursorIcon::RowResize => &["split_v", "v_double_arrow", "sb_v_double_arrow"],
CursorIcon::AllScroll => &["size_all"],
CursorIcon::ZoomIn => &[],
CursorIcon::ZoomOut => &[],
}
}
}

impl core::fmt::Display for CursorIcon {
Expand Down

0 comments on commit 9d77551

Please # to comment.