fix: search the theme path provided by the app to find status-area icons

This commit is contained in:
Hojjat 2026-05-18 13:53:50 -06:00 committed by Lionel DARNIS
parent da53a9f45f
commit 9c4299429e
2 changed files with 17 additions and 8 deletions

View file

@ -26,6 +26,7 @@ pub struct State {
expanded: Option<i32>, expanded: Option<i32>,
// TODO handle icon with multiple sizes? // TODO handle icon with multiple sizes?
icon_handle: icon::Handle, icon_handle: icon::Handle,
icon_theme_path: Option<PathBuf>,
click_event: Option<(i32, bool)>, click_event: Option<(i32, bool)>,
} }
@ -39,6 +40,7 @@ impl State {
icon_handle: icon::from_name("application-default") icon_handle: icon::from_name("application-default")
.prefer_svg(true) .prefer_svg(true)
.handle(), .handle(),
icon_theme_path: None,
click_event: None, click_event: None,
}, },
iced::Task::none(), iced::Task::none(),
@ -63,6 +65,7 @@ impl State {
} }
Msg::Icon(update) => { Msg::Icon(update) => {
let icon_name = update.name.unwrap_or_default(); let icon_name = update.name.unwrap_or_default();
self.icon_theme_path = update.theme_path;
// Use the icon pixmap if an icon was not defined by name. // Use the icon pixmap if an icon was not defined by name.
if icon_name.is_empty() { if icon_name.is_empty() {
@ -93,13 +96,18 @@ impl State {
self.icon_handle = if Path::new(&icon_name).exists() { self.icon_handle = if Path::new(&icon_name).exists() {
icon::from_path(Path::new(&icon_name).to_path_buf()).symbolic(true) icon::from_path(Path::new(&icon_name).to_path_buf()).symbolic(true)
} else { } else {
icon::from_name(icon_name) let mut builder = icon::from_name(icon_name).prefer_svg(true).fallback(Some(
.prefer_svg(true) IconFallback::Names(vec![
.fallback(Some(IconFallback::Names(vec![
"application-default".into(), "application-default".into(),
"application-x-executable".into(), "application-x-executable".into(),
]))) ]),
.handle() ));
if let Some(ref theme_path) = self.icon_theme_path {
builder = builder.with_extra_paths(vec![theme_path.clone()]);
}
builder.handle()
}; };
iced::Task::none() iced::Task::none()

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use std::hash::Hash; use std::hash::Hash;
use std::path::PathBuf;
use cosmic::iced::{self, Subscription}; use cosmic::iced::{self, Subscription};
use futures::{FutureExt, StreamExt}; use futures::{FutureExt, StreamExt};
@ -27,7 +28,7 @@ pub struct Icon {
pub struct IconUpdate { pub struct IconUpdate {
pub name: Option<String>, pub name: Option<String>,
pub pixmap: Option<Vec<Icon>>, pub pixmap: Option<Vec<Icon>>,
// pub theme_path: Option<PathBuf>, pub theme_path: Option<PathBuf>,
} }
impl StatusNotifierItem { impl StatusNotifierItem {
@ -118,11 +119,11 @@ impl StatusNotifierItem {
async fn icon_events(item_proxy: StatusNotifierItemProxy<'static>) -> IconUpdate { async fn icon_events(item_proxy: StatusNotifierItemProxy<'static>) -> IconUpdate {
let icon_name = item_proxy.icon_name().await; let icon_name = item_proxy.icon_name().await;
let icon_pixmap = item_proxy.icon_pixmap().await; let icon_pixmap = item_proxy.icon_pixmap().await;
// let icon_theme_path = item_proxy.icon_theme_path().await.map(PathBuf::from); let icon_theme_path = item_proxy.icon_theme_path().await.map(PathBuf::from);
IconUpdate { IconUpdate {
name: icon_name.ok(), name: icon_name.ok(),
pixmap: icon_pixmap.ok(), pixmap: icon_pixmap.ok(),
// theme_path: icon_theme_path.ok().filter(|x| !x.as_os_str().is_empty()), theme_path: icon_theme_path.ok().filter(|x| !x.as_os_str().is_empty()),
} }
} }