From 60ea06e188b1f774823728adf7829bbcf269d808 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 18 Jan 2022 19:26:44 -0700 Subject: [PATCH] revise default xcursor path refs: https://github.com/wez/wezterm/issues/524#issuecomment-1015984205 --- window/src/os/x11/cursor.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/window/src/os/x11/cursor.rs b/window/src/os/x11/cursor.rs index e2b6ad7f2..72d3bbe7e 100644 --- a/window/src/os/x11/cursor.rs +++ b/window/src/os/x11/cursor.rs @@ -3,7 +3,7 @@ use crate::MouseCursor; use anyhow::{ensure, Context}; use std::collections::HashMap; use std::convert::TryInto; -use std::ffi::OsString; +use std::ffi::OsStr; use std::io::prelude::*; use std::io::SeekFrom; use std::path::PathBuf; @@ -34,9 +34,35 @@ pub struct CursorInfo { } fn icon_path() -> Vec { - let path = std::env::var_os("XCURSOR_PATH").unwrap_or_else(|| { - OsString::from("~/.icons:/usr/share/icons:/usr/share/pixmaps:/usr/X11R6/lib/X11/icons") - }); + let path = match std::env::var_os("XCURSOR_PATH") { + Some(path) => path, + None => { + fn add_icons_dir(path: &OsStr, dest: &mut Vec) { + for entry in std::env::split_paths(path) { + dest.push(entry.join("icons")); + } + } + + fn xdg_location(name: &str, def: &str, dest: &mut Vec) { + if let Some(var) = std::env::var_os(name) { + add_icons_dir(&var, dest); + } else { + add_icons_dir(OsStr::new(def), dest); + } + } + + let mut path = vec![]; + xdg_location("XDG_DATA_HOME", "~/.local/share", &mut path); + path.push("~/.icons".into()); + xdg_location("XDG_DATA_DIRS", "/usr/local/share:/usr/share", &mut path); + path.push("/usr/share/pixmaps".into()); + path.push("~/.cursors".into()); + path.push("/usr/share/cursors/xorg-x11".into()); + path.push("/usr/X11R6/lib/X11/icons".into()); + + std::env::join_paths(path).expect("failed to compose default xcursor path") + } + }; fn tilde_expand(p: PathBuf) -> PathBuf { match p.to_str() {