staus-area: Initial support to use IconThemePath for icon loading

We should use a more complicated method to lookup the icon from the
theme, but `cosmic-freedesktop-icons` will need some changes to be able
to accomodate a custom theme path.

This is probably an improvement. Anything that uses `IconThemePath`
is likely not working currently, so it won't make things worse.
This commit is contained in:
Ian Douglas Scott 2025-11-04 12:55:59 -08:00 committed by Jacob Kauffmann
parent 080f07e0b4
commit d04314957b
2 changed files with 17 additions and 4 deletions

View file

@ -524,11 +524,16 @@ fn menu_icon_button<'a>(
applet: &'a cosmic::applet::Context,
menu: &'a status_menu::State,
) -> cosmic::widget::Button<'a, Msg> {
match menu.icon_pixmap() {
Some(icon) if menu.icon_name() == "" => {
applet.icon_button_from_handle(icon.clone().symbolic(true))
match (menu.icon_pixmap(), menu.icon_name(), menu.icon_theme_path()) {
(Some(icon), "", _) => applet.icon_button_from_handle(icon.clone().symbolic(true)),
(_, name, Some(theme_path)) if name != "" => {
let mut path = theme_path.to_owned();
// XXX right way to lookup icon in dir?
path.push(name.to_owned() + ".png");
let icon = cosmic::widget::icon::from_path(path).symbolic(true);
applet.icon_button_from_handle(icon)
}
_ => applet.icon_button(menu.icon_name()),
(_, name, _) => applet.icon_button(name),
}
}

View file

@ -8,6 +8,7 @@ use cosmic::{
iced,
widget::icon,
};
use std::path::{Path, PathBuf};
use crate::subscriptions::status_notifier_item::{IconUpdate, Layout, StatusNotifierItem};
@ -26,6 +27,7 @@ pub struct State {
icon_name: String,
// TODO handle icon with multiple sizes?
icon_pixmap: Option<icon::Handle>,
icon_theme_path: Option<PathBuf>,
click_event: Option<(i32, bool)>,
}
@ -38,6 +40,7 @@ impl State {
expanded: None,
icon_name: String::new(),
icon_pixmap: None,
icon_theme_path: None,
click_event: None,
},
iced::Task::none(),
@ -78,6 +81,7 @@ impl State {
}
icon::from_raster_pixels(i.width as u32, i.height as u32, i.bytes)
}));
self.icon_theme_path = update.theme_path;
iced::Task::none()
}
@ -138,6 +142,10 @@ impl State {
self.icon_pixmap.as_ref()
}
pub fn icon_theme_path(&self) -> Option<&Path> {
self.icon_theme_path.as_deref()
}
pub fn popup_view(&self) -> cosmic::Element<'_, Msg> {
if let Some(layout) = self.layout.as_ref() {
layout_view(layout, self.expanded)