1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-02 03:01:04 +02:00

fix(image): using fallback in places it shouldn't

This commit is contained in:
Jake Stanger 2023-07-26 21:49:45 +01:00
parent 1c68a97d33
commit 2367faab04
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
7 changed files with 27 additions and 15 deletions

View file

@ -12,7 +12,7 @@ pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button
image.add_class("image");
image.add_class("icon");
match ImageProvider::parse(input, icon_theme, size)
match ImageProvider::parse(input, icon_theme, false, size)
.map(|provider| provider.load_into_image(image.clone()))
{
Some(_) => {
@ -41,7 +41,7 @@ pub fn new_icon_label(input: &str, icon_theme: &IconTheme, size: i32) -> gtk::Bo
container.add(&image);
ImageProvider::parse(input, icon_theme, size)
ImageProvider::parse(input, icon_theme, false, size)
.map(|provider| provider.load_into_image(image));
} else {
let label = Label::new(Some(input));

View file

@ -41,8 +41,9 @@ impl<'a> ImageProvider<'a> {
///
/// Note this checks that icons exist in theme, or files exist on disk
/// but no other check is performed.
pub fn parse(input: &str, theme: &'a IconTheme, size: i32) -> Option<Self> {
let location = Self::get_location(input, theme, size, 0)?;
pub fn parse(input: &str, theme: &'a IconTheme, use_fallback: bool, size: i32) -> Option<Self> {
let location = Self::get_location(input, theme, size, use_fallback, 0)?;
Some(Self { location, size })
}
@ -61,8 +62,19 @@ impl<'a> ImageProvider<'a> {
input: &str,
theme: &'a IconTheme,
size: i32,
use_fallback: bool,
recurse_depth: usize,
) -> Option<ImageLocation<'a>> {
macro_rules! fallback {
() => {
if use_fallback {
Some(Self::get_fallback_icon(theme))
} else {
None
}
};
}
const MAX_RECURSE_DEPTH: usize = 2;
let (input_type, input_name) = input
@ -99,20 +111,20 @@ impl<'a> ImageProvider<'a> {
Report::msg(format!("Unsupported image type: {input_type}"))
.note("You may need to recompile with support if available")
);
None
fallback!()
}
None if PathBuf::from(input_name).is_file() => {
Some(ImageLocation::Local(PathBuf::from(input_name)))
}
None if recurse_depth == MAX_RECURSE_DEPTH => Some(Self::get_fallback_icon(theme)),
None if recurse_depth == MAX_RECURSE_DEPTH => fallback!(),
None => {
if let Some(location) = get_desktop_icon_name(input_name)
.map(|input| Self::get_location(&input, theme, size, recurse_depth + 1))
{
if let Some(location) = get_desktop_icon_name(input_name).map(|input| {
Self::get_location(&input, theme, size, use_fallback, recurse_depth + 1)
}) {
location
} else {
warn!("Failed to find image: {input}");
Some(Self::get_fallback_icon(theme))
fallback!()
}
}
}