mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
fix(image): using fallback in places it shouldn't
This commit is contained in:
parent
1c68a97d33
commit
2367faab04
7 changed files with 27 additions and 15 deletions
|
@ -12,7 +12,7 @@ pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button
|
||||||
image.add_class("image");
|
image.add_class("image");
|
||||||
image.add_class("icon");
|
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()))
|
.map(|provider| provider.load_into_image(image.clone()))
|
||||||
{
|
{
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
|
@ -41,7 +41,7 @@ pub fn new_icon_label(input: &str, icon_theme: &IconTheme, size: i32) -> gtk::Bo
|
||||||
|
|
||||||
container.add(&image);
|
container.add(&image);
|
||||||
|
|
||||||
ImageProvider::parse(input, icon_theme, size)
|
ImageProvider::parse(input, icon_theme, false, size)
|
||||||
.map(|provider| provider.load_into_image(image));
|
.map(|provider| provider.load_into_image(image));
|
||||||
} else {
|
} else {
|
||||||
let label = Label::new(Some(input));
|
let label = Label::new(Some(input));
|
||||||
|
|
|
@ -41,8 +41,9 @@ impl<'a> ImageProvider<'a> {
|
||||||
///
|
///
|
||||||
/// Note this checks that icons exist in theme, or files exist on disk
|
/// Note this checks that icons exist in theme, or files exist on disk
|
||||||
/// but no other check is performed.
|
/// but no other check is performed.
|
||||||
pub fn parse(input: &str, theme: &'a IconTheme, size: i32) -> Option<Self> {
|
pub fn parse(input: &str, theme: &'a IconTheme, use_fallback: bool, size: i32) -> Option<Self> {
|
||||||
let location = Self::get_location(input, theme, size, 0)?;
|
let location = Self::get_location(input, theme, size, use_fallback, 0)?;
|
||||||
|
|
||||||
Some(Self { location, size })
|
Some(Self { location, size })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +62,19 @@ impl<'a> ImageProvider<'a> {
|
||||||
input: &str,
|
input: &str,
|
||||||
theme: &'a IconTheme,
|
theme: &'a IconTheme,
|
||||||
size: i32,
|
size: i32,
|
||||||
|
use_fallback: bool,
|
||||||
recurse_depth: usize,
|
recurse_depth: usize,
|
||||||
) -> Option<ImageLocation<'a>> {
|
) -> Option<ImageLocation<'a>> {
|
||||||
|
macro_rules! fallback {
|
||||||
|
() => {
|
||||||
|
if use_fallback {
|
||||||
|
Some(Self::get_fallback_icon(theme))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_RECURSE_DEPTH: usize = 2;
|
const MAX_RECURSE_DEPTH: usize = 2;
|
||||||
|
|
||||||
let (input_type, input_name) = input
|
let (input_type, input_name) = input
|
||||||
|
@ -99,20 +111,20 @@ impl<'a> ImageProvider<'a> {
|
||||||
Report::msg(format!("Unsupported image type: {input_type}"))
|
Report::msg(format!("Unsupported image type: {input_type}"))
|
||||||
.note("You may need to recompile with support if available")
|
.note("You may need to recompile with support if available")
|
||||||
);
|
);
|
||||||
None
|
fallback!()
|
||||||
}
|
}
|
||||||
None if PathBuf::from(input_name).is_file() => {
|
None if PathBuf::from(input_name).is_file() => {
|
||||||
Some(ImageLocation::Local(PathBuf::from(input_name)))
|
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 => {
|
None => {
|
||||||
if let Some(location) = get_desktop_icon_name(input_name)
|
if let Some(location) = get_desktop_icon_name(input_name).map(|input| {
|
||||||
.map(|input| Self::get_location(&input, theme, size, recurse_depth + 1))
|
Self::get_location(&input, theme, size, use_fallback, recurse_depth + 1)
|
||||||
{
|
}) {
|
||||||
location
|
location
|
||||||
} else {
|
} else {
|
||||||
warn!("Failed to find image: {input}");
|
warn!("Failed to find image: {input}");
|
||||||
Some(Self::get_fallback_icon(theme))
|
fallback!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl CustomWidget for ImageWidget {
|
||||||
let icon_theme = context.icon_theme.clone();
|
let icon_theme = context.icon_theme.clone();
|
||||||
|
|
||||||
dynamic_string(&self.src, move |src| {
|
dynamic_string(&self.src, move |src| {
|
||||||
ImageProvider::parse(&src, &icon_theme, self.size)
|
ImageProvider::parse(&src, &icon_theme, false, self.size)
|
||||||
.map(|image| image.load_into_image(gtk_image.clone()));
|
.map(|image| image.load_into_image(gtk_image.clone()));
|
||||||
|
|
||||||
Continue(true)
|
Continue(true)
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl Module<gtk::Box> for FocusedModule {
|
||||||
let icon_theme = icon_theme.clone();
|
let icon_theme = icon_theme.clone();
|
||||||
context.widget_rx.attach(None, move |(name, id)| {
|
context.widget_rx.attach(None, move |(name, id)| {
|
||||||
if self.show_icon {
|
if self.show_icon {
|
||||||
match ImageProvider::parse(&id, &icon_theme, self.icon_size)
|
match ImageProvider::parse(&id, &icon_theme, true, self.icon_size)
|
||||||
.map(|image| image.load_into_image(icon.clone()))
|
.map(|image| image.load_into_image(icon.clone()))
|
||||||
{
|
{
|
||||||
Some(Ok(_)) => icon.show(),
|
Some(Ok(_)) => icon.show(),
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl ItemButton {
|
||||||
if appearance.show_icons {
|
if appearance.show_icons {
|
||||||
let gtk_image = gtk::Image::new();
|
let gtk_image = gtk::Image::new();
|
||||||
let image =
|
let image =
|
||||||
ImageProvider::parse(&item.app_id.clone(), icon_theme, appearance.icon_size);
|
ImageProvider::parse(&item.app_id.clone(), icon_theme, true, appearance.icon_size);
|
||||||
if let Some(image) = image {
|
if let Some(image) = image {
|
||||||
button.set_image(Some(>k_image));
|
button.set_image(Some(>k_image));
|
||||||
button.set_always_show_image(true);
|
button.set_always_show_image(true);
|
||||||
|
|
|
@ -408,7 +408,7 @@ impl Module<Button> for MusicModule {
|
||||||
if prev_cover != new_cover {
|
if prev_cover != new_cover {
|
||||||
prev_cover = new_cover.clone();
|
prev_cover = new_cover.clone();
|
||||||
let res = if let Some(image) = new_cover.and_then(|cover_path| {
|
let res = if let Some(image) = new_cover.and_then(|cover_path| {
|
||||||
ImageProvider::parse(&cover_path, &icon_theme, image_size)
|
ImageProvider::parse(&cover_path, &icon_theme, false, image_size)
|
||||||
}) {
|
}) {
|
||||||
image.load_into_image(album_image.clone())
|
image.load_into_image(album_image.clone())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -189,7 +189,7 @@ impl Module<gtk::Button> for UpowerModule {
|
||||||
.attach(None, move |properties: UpowerProperties| {
|
.attach(None, move |properties: UpowerProperties| {
|
||||||
let format = format.replace("{percentage}", &properties.percentage.to_string());
|
let format = format.replace("{percentage}", &properties.percentage.to_string());
|
||||||
let icon_name = String::from("icon:") + &properties.icon_name;
|
let icon_name = String::from("icon:") + &properties.icon_name;
|
||||||
ImageProvider::parse(&icon_name, &icon_theme, self.icon_size)
|
ImageProvider::parse(&icon_name, &icon_theme, false, self.icon_size)
|
||||||
.map(|provider| provider.load_into_image(icon.clone()));
|
.map(|provider| provider.load_into_image(icon.clone()));
|
||||||
label.set_markup(format.as_ref());
|
label.set_markup(format.as_ref());
|
||||||
Continue(true)
|
Continue(true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue