diff --git a/Cargo.lock b/Cargo.lock index d302d82..4bc26d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,12 +23,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" - [[package]] name = "ahash" version = "0.7.6" @@ -547,7 +541,16 @@ version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", ] [[package]] @@ -556,7 +559,18 @@ version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", ] [[package]] @@ -573,12 +587,9 @@ dependencies = [ [[package]] name = "dlv-list" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b" -dependencies = [ - "rand 0.8.5", -] +checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "either" @@ -663,15 +674,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "file-locker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91c8a37357ab5d51f1a8053900fe8374283449695c5418b66f45deece50705f" -dependencies = [ - "nix 0.25.1", -] - [[package]] name = "flagset" version = "0.4.3" @@ -761,13 +763,16 @@ dependencies = [ ] [[package]] -name = "freedesktop_entry_parser" -version = "1.3.0" +name = "freedesktop-icons" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db9c27b72f19a99a895f8ca89e2d26e4ef31013376e56fdafef697627306c3e4" +checksum = "00e61ac115df4632b592d36b71fda3c259f4c8061c70b7fa429bac145890e880" dependencies = [ - "nom", + "dirs 4.0.0", + "once_cell", + "rust-ini", "thiserror", + "xdg", ] [[package]] @@ -890,20 +895,14 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -dependencies = [ - "ahash 0.4.7", -] - [[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "hashbrown" @@ -938,6 +937,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "iana-time-zone" version = "0.1.56" @@ -1101,29 +1109,6 @@ version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" -[[package]] -name = "linicon" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee8c5653188a809616c97296180a0547a61dba205bcdcbdd261dbd022a25fd9" -dependencies = [ - "file-locker", - "freedesktop_entry_parser", - "linicon-theme", - "memmap2", - "thiserror", -] - -[[package]] -name = "linicon-theme" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4f8240c33bb08c5d8b8cdea87b683b05e61037aa76ff26bef40672cc6ecbb80" -dependencies = [ - "freedesktop_entry_parser", - "rust-ini", -] - [[package]] name = "linux-raw-sys" version = "0.3.7" @@ -1194,15 +1179,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.7.1" @@ -1221,12 +1197,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.6.2" @@ -1285,20 +1255,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "nix" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" -dependencies = [ - "autocfg", - "bitflags", - "cfg-if", - "libc", - "memoffset 0.6.5", - "pin-utils", -] - [[package]] name = "nix" version = "0.26.2" @@ -1313,16 +1269,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1417,12 +1363,12 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "ordered-multimap" -version = "0.3.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" +checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" dependencies = [ "dlv-list", - "hashbrown 0.9.1", + "hashbrown 0.12.3", ] [[package]] @@ -1616,15 +1562,15 @@ dependencies = [ "clap", "color-eyre", "directories", - "dirs", + "dirs 5.0.1", "ez-pixmap", + "freedesktop-icons", "glam", "image", "lazy_static", - "linicon", "manifest-dir-macros", "mint", - "nix 0.26.2", + "nix", "regex", "resvg", "rustc-hash", @@ -1867,9 +1813,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22" +checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" dependencies = [ "cfg-if", "ordered-multimap", @@ -2096,7 +2042,7 @@ dependencies = [ "chrono", "cluFlock", "color-rs", - "dirs", + "dirs 5.0.1", "mint", "parking_lot 0.12.1", "rustc-hash", @@ -2529,7 +2475,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "371436099f2980de56dc385b615696d3eabbdac9649a72b85f9d75f68474fa9c" dependencies = [ - "ahash 0.7.6", + "ahash", "byteorder", "lazy_static", "parking_lot 0.11.2", @@ -2849,6 +2795,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "xdg" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "688597db5a750e9cad4511cb94729a078e274308099a0382b5b8203bbc767fee" +dependencies = [ + "home", +] + [[package]] name = "xkbcommon" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index fd1dda7..06f6a35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,10 @@ color-eyre = "0.6.2" directories = "5.0.0" dirs = "5.0.0" ez-pixmap = "0.2.2" +freedesktop-icons = "0.2.3" glam = { version = "0.24.0", features = ["mint"] } image = "0.24.5" lazy_static = "1.4.0" -linicon = "2.3.0" manifest-dir-macros = "0.1.16" mint = "0.5.9" nix = "0.26.1" diff --git a/src/application.rs b/src/application.rs index 37ce141..e12cf55 100644 --- a/src/application.rs +++ b/src/application.rs @@ -39,7 +39,7 @@ impl Application { } pub fn icon(&self, preferred_px_size: u16, prefer_3d: bool) -> Option { - let raw_icons = self.desktop_file.get_raw_icons(preferred_px_size); + let raw_icons = self.desktop_file.get_icon(preferred_px_size); let mut icon = raw_icons.iter().max_by_key(|i| i.size).cloned(); if prefer_3d { icon = raw_icons diff --git a/src/xdg.rs b/src/xdg.rs index 275830d..7d1c1dc 100644 --- a/src/xdg.rs +++ b/src/xdg.rs @@ -1,6 +1,6 @@ use color_eyre::eyre::Result; +use freedesktop_icons::lookup; use lazy_static::lazy_static; -use linicon; use regex::Regex; use resvg::render; use resvg::tiny_skia::{Pixmap, Transform}; @@ -232,40 +232,43 @@ pub struct DesktopFile { pub icon: Option, pub no_display: bool, } + +const ICON_SIZES: [u16; 7] = [512, 256, 128, 64, 48, 32, 24]; + impl DesktopFile { - pub fn get_raw_icons(&self, preferred_px_size: u16) -> Vec { + pub fn get_icon(&self, preferred_px_size: u16) -> Option { // Get the name of the icon from the DesktopFile struct - let Some(icon_name) = self.icon.as_ref() else { return Vec::new(); }; + let Some(icon_name) = self.icon.as_ref() else { return None }; let test_icon_path = self.path.join(Path::new(icon_name)); if test_icon_path.exists() { if let Some(icon) = Icon::from_path(test_icon_path, preferred_px_size) { - return vec![icon]; + return Some(icon); } } if let Some(cache_icon_path) = IMAGE_CACHE.lock().unwrap().map.get(icon_name) { if cache_icon_path.exists() { if let Some(icon) = Icon::from_path(cache_icon_path.to_owned(), preferred_px_size) { - return vec![icon]; + return Some(icon); } } } - let mut icons_iter = linicon::lookup_icon(icon_name) - .use_fallback_themes(false) - .peekable(); - - if icons_iter.peek().is_none() { - //dbg!("No icons found in current theme"); - icons_iter = linicon::lookup_icon(icon_name).peekable(); + // TODO: handle preferred_theme + if let Some(icon_path) = lookup(icon_name).with_size(preferred_px_size).find() { + if let Some(icon) = Icon::from_path(icon_path, preferred_px_size) { + return Some(icon); + } } - let sized_png: Vec = icons_iter - .filter_map(|i| i.ok()) - .filter(|i| i.icon_type != linicon::IconType::XMP) //TODO: support XMP - .map(|i| Icon::from_path(i.path, i.max_size - 2).unwrap()) - .collect(); - sized_png + for icon_size in ICON_SIZES { + if let Some(icon_path) = lookup(icon_name).with_size(icon_size).find() { + if let Some(icon) = Icon::from_path(icon_path, preferred_px_size) { + return Some(icon); + } + } + } + None } } @@ -341,17 +344,18 @@ fn test_get_icon_path() { }; // Call the get_icon_path() function with a size argument and store the result - let icon_paths = desktop_file.get_raw_icons(32); - dbg!(&icon_paths); + let icon = desktop_file.get_icon(32); + dbg!(&icon); // Assert that the get_icon_path() function returns the expected result - assert!(icon_paths.contains( - &Icon::from_path( - PathBuf::from("/usr/share/icons/hicolor/32x32/apps/krita.png"), - 32 - ) - .unwrap() - )); + assert!( + icon.unwrap() + == Icon::from_path( + PathBuf::from("/usr/share/icons/hicolor/32x32/apps/krita.png"), + 32 + ) + .unwrap() + ); } pub fn get_image_cache_dir() -> PathBuf {