From d04314957ba586cf6f74e2f094dabe8bffd0f50e Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 4 Nov 2025 12:55:59 -0800 Subject: [PATCH] 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. --- cosmic-applet-status-area/src/components/app.rs | 13 +++++++++---- .../src/components/status_menu.rs | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cosmic-applet-status-area/src/components/app.rs b/cosmic-applet-status-area/src/components/app.rs index c1678493..a36ba745 100644 --- a/cosmic-applet-status-area/src/components/app.rs +++ b/cosmic-applet-status-area/src/components/app.rs @@ -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), } } diff --git a/cosmic-applet-status-area/src/components/status_menu.rs b/cosmic-applet-status-area/src/components/status_menu.rs index e0adeafa..4f33422d 100644 --- a/cosmic-applet-status-area/src/components/status_menu.rs +++ b/cosmic-applet-status-area/src/components/status_menu.rs @@ -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_theme_path: Option, 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)