From 68740704e4c98986ef9c00b7f8006265aac79097 Mon Sep 17 00:00:00 2001 From: hantengc <1341910529@qq.com> Date: Fri, 20 Sep 2024 17:04:21 +0800 Subject: [PATCH] optimize icon acquisition logic to prepare for customizing icons for other desktop environments in the future --- .../notificationitem/notificationitem.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/notificationitem/notificationitem.cpp b/src/modules/notificationitem/notificationitem.cpp index b94f7789e..0e42b71e4 100644 --- a/src/modules/notificationitem/notificationitem.cpp +++ b/src/modules/notificationitem/notificationitem.cpp @@ -53,20 +53,24 @@ class StatusNotifierItem : public dbus::ObjectVTable { } void activate(int, int) { parent_->instance()->toggle(); } void secondaryActivate(int, int) {} - std::string iconName() { - static bool preferSymbolic = !isKDE(); - std::string icon; - if (preferSymbolic) { - icon = "input-keyboard-symbolic"; + std::string keyboardIconName() const { + if (isKDE()) { + return "input-keyboard"; } else { - icon = "input-keyboard"; + return "input-keyboard-symbolic"; } + } + std::string iconName() { + std::string icon; + if (auto *ic = parent_->menu()->lastRelevantIc()) { icon = parent_->instance()->inputMethodIcon(ic); } - if (icon == "input-keyboard" && preferSymbolic) { - return "input-keyboard-symbolic"; + + if (icon.empty() || icon == "input-keyboard") { + icon = keyboardIconName(); } + return IconTheme::iconName(icon); }