Skip to content

Commit

Permalink
Adjust icon search paths + include Papirus
Browse files Browse the repository at this point in the history
Should find more icons and also be faster if Papirus is installed
  • Loading branch information
Beinsezii committed Jul 20, 2023
1 parent 6124c55 commit 73c1e95
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,41 +183,53 @@ fn get_applications(include_hidden: bool) -> Vec<Item> {
} // }}}

fn get_icon_loc(name: &str) -> Option<PathBuf> {
let mut buf: PathBuf;
// on my system covers every app that doesn't have a stupid location
for f in [
name.to_string(),
// Prefer Papirus SVGs
format!("/usr/share/icons/Papirus/64x64/apps/{}.svg", name),
format!("/usr/share/icons/hicolor/scalable/apps/{}.svg", name),
format!(
"/usr/share/icons/hicolor/symbolic/apps/{}-symbolic.svg",
name
),
// HiColor PNGs
format!("/usr/share/icons/hicolor/64x64/apps/{}.png", name),
format!("/usr/share/icons/hicolor/128x128/apps/{}.png", name),
format!("/usr/share/icons/hicolor/256x256/apps/{}.png", name),
format!("/usr/share/icons/hicolor/32x32/apps/{}.png", name),
// Check other locations
format!("/usr/share/icons/Papirus/64x64/devices/{}.svg", name),
] {
buf = PathBuf::from(f);
let buf = PathBuf::from(f);
if buf.is_file() {
return Some(buf);
}
}
// fall back to scanning
// let mut osname = OsString::new();
// osname.push(name);
// osname.push(".png");
// fall back to scanning. Don't like this, kind of want to remove but idk how other
// distros'/themes' layouts may differ
let osname = Some(OsStr::new(name));
let png = Some(OsStr::new("png"));
let svg = Some(OsStr::new("svg"));
// No Papirus scannign since its layout is super standardized and there's like a million files
for entry in WalkDir::new("/usr/share/icons/hicolor")
.follow_links(true)
.into_iter()
.chain(WalkDir::new("/usr/share/icons/Adwaita"))
// scan all other themes as last resort
.chain(
WalkDir::new("/usr/share/icons")
.into_iter()
.filter_entry(|e| {
e.file_name() != "Papirus"
&& e.file_name() != "hicolor"
&& e.file_name() != "Adwaita"
// also skip symbolic icons. I'm not gonna support them
&& e.file_name() != "symbolic"
}),
)
.filter_map(|e| e.ok())
.filter(|e| e.path().file_stem() == osname)
.filter(|e| e.path().extension() == png || e.path().extension() == svg)
{
println!("{}", entry.path().display());
// println!("### FOUND {} AT {}", name, entry.path().display());
return Some(entry.path().to_owned());
}
// println!("### COULD NOT FIND {}", name);
None
}

Expand Down Expand Up @@ -414,6 +426,7 @@ impl Linch {
}

let mut images = HashMap::new();
// let now = std::time::Instant::now();
if icons {
for icon in items.iter().filter_map(|i| i.icon.as_ref()) {
if !images.contains_key(icon) {
Expand All @@ -440,6 +453,10 @@ impl Linch {
}
}
}
// println!(
// "Icons loaded in {}ms",
// (std::time::Instant::now() - now).as_millis()
// );

Self {
input: String::new(),
Expand Down

0 comments on commit 73c1e95

Please sign in to comment.