From f7ea663a3de1ceedd21deea2fa70309ffef89114 Mon Sep 17 00:00:00 2001 From: nik012003 Date: Tue, 16 May 2023 14:37:20 +0200 Subject: [PATCH] Get current theme --- Cargo.lock | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + src/xdg.rs | 13 +++++++- 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bc26d7..7146509 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,12 @@ 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" @@ -585,6 +591,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dlv-list" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b" +dependencies = [ + "rand 0.8.5", +] + [[package]] name = "dlv-list" version = "0.3.0" @@ -770,11 +785,21 @@ checksum = "00e61ac115df4632b592d36b71fda3c259f4c8061c70b7fa429bac145890e880" dependencies = [ "dirs 4.0.0", "once_cell", - "rust-ini", + "rust-ini 0.18.0", "thiserror", "xdg", ] +[[package]] +name = "freedesktop_entry_parser" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db9c27b72f19a99a895f8ca89e2d26e4ef31013376e56fdafef697627306c3e4" +dependencies = [ + "nom", + "thiserror", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -895,13 +920,22 @@ 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", + "ahash 0.7.6", ] [[package]] @@ -1109,6 +1143,16 @@ version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" +[[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 0.17.0", +] + [[package]] name = "linux-raw-sys" version = "0.3.7" @@ -1197,6 +1241,12 @@ 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" @@ -1269,6 +1319,16 @@ 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" @@ -1361,13 +1421,23 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-multimap" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" +dependencies = [ + "dlv-list 0.2.3", + "hashbrown 0.9.1", +] + [[package]] name = "ordered-multimap" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" dependencies = [ - "dlv-list", + "dlv-list 0.3.0", "hashbrown 0.12.3", ] @@ -1568,6 +1638,7 @@ dependencies = [ "glam", "image", "lazy_static", + "linicon-theme", "manifest-dir-macros", "mint", "nix", @@ -1811,6 +1882,16 @@ dependencies = [ "xmlparser", ] +[[package]] +name = "rust-ini" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22" +dependencies = [ + "cfg-if", + "ordered-multimap 0.3.1", +] + [[package]] name = "rust-ini" version = "0.18.0" @@ -1818,7 +1899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" dependencies = [ "cfg-if", - "ordered-multimap", + "ordered-multimap 0.4.3", ] [[package]] @@ -2475,7 +2556,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "371436099f2980de56dc385b615696d3eabbdac9649a72b85f9d75f68474fa9c" dependencies = [ - "ahash", + "ahash 0.7.6", "byteorder", "lazy_static", "parking_lot 0.11.2", diff --git a/Cargo.toml b/Cargo.toml index 06f6a35..0118e3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ freedesktop-icons = "0.2.3" glam = { version = "0.24.0", features = ["mint"] } image = "0.24.5" lazy_static = "1.4.0" +linicon-theme = "1.2.0" manifest-dir-macros = "0.1.16" mint = "0.5.9" nix = "0.26.1" diff --git a/src/xdg.rs b/src/xdg.rs index 8c332b8..9f70bff 100644 --- a/src/xdg.rs +++ b/src/xdg.rs @@ -251,8 +251,14 @@ impl DesktopFile { print!("Cache miss") } + let preferred_theme = match linicon_theme::get_icon_theme() { + Some(t) => t, + None => "hicolor".to_owned(), + }; + if let Some(icon_path) = lookup(icon_name) .with_size(preferred_px_size) + .with_theme(preferred_theme.as_str()) .with_cache() .find() { @@ -262,7 +268,12 @@ impl DesktopFile { } for icon_size in ICON_SIZES { - if let Some(icon_path) = lookup(icon_name).with_size(icon_size).with_cache().find() { + if let Some(icon_path) = lookup(icon_name) + .with_size(icon_size) + .with_theme(preferred_theme.as_str()) + .with_cache() + .find() + { if let Some(icon) = Icon::from_path(icon_path, preferred_px_size) { return Some(icon); }