From 5b81104ffa22465e8f97a4d625e1a151c5d50c2f Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 9 Sep 2025 21:02:24 +1000 Subject: bar/tray: add icon subs Usage: array of { id, image | icon } --- README.md | 1 + config/BarConfig.qml | 1 + modules/bar/components/TrayItem.qml | 10 ++-------- utils/Icons.qml | 13 +++++++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b483910..029dbb5 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,7 @@ default, you must create it manually. }, "tray": { "background": false, + "iconSubs": [], "recolour": false }, "workspaces": { diff --git a/config/BarConfig.qml b/config/BarConfig.qml index 65236bd..4815259 100644 --- a/config/BarConfig.qml +++ b/config/BarConfig.qml @@ -77,6 +77,7 @@ JsonObject { component Tray: JsonObject { property bool background: false property bool recolour: false + property list iconSubs: [] } component Status: JsonObject { diff --git a/modules/bar/components/TrayItem.qml b/modules/bar/components/TrayItem.qml index 6e7c2c5..9911907 100644 --- a/modules/bar/components/TrayItem.qml +++ b/modules/bar/components/TrayItem.qml @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound import qs.components.effects import qs.services import qs.config +import qs.utils import Quickshell.Services.SystemTray import QtQuick @@ -26,14 +27,7 @@ MouseArea { id: icon anchors.fill: parent - source: { - let icon = root.modelData.icon; - if (icon.includes("?path=")) { - const [name, path] = icon.split("?path="); - icon = Qt.resolvedUrl(`${path}/${name.slice(name.lastIndexOf("/") + 1)}`); - } - return icon; - } + source: Icons.getTrayIcon(root.modelData.id, root.modelData.icon) colour: Colours.palette.m3secondary layer.enabled: Config.bar.tray.recolour } diff --git a/utils/Icons.qml b/utils/Icons.qml index 76eef43..45c1537 100644 --- a/utils/Icons.qml +++ b/utils/Icons.qml @@ -1,5 +1,6 @@ pragma Singleton +import qs.config import Quickshell import Quickshell.Services.Notifications @@ -205,4 +206,16 @@ Singleton { return "monitor_heart"; return name[0].toUpperCase(); } + + function getTrayIcon(id: string, icon: string): string { + for (const sub of Config.bar.tray.iconSubs) + if (sub.id === id) + return sub.image ? Qt.resolvedUrl(sub.image) : Quickshell.iconPath(sub.icon); + + if (icon.includes("?path=")) { + const [name, path] = icon.split("?path="); + icon = Qt.resolvedUrl(`${path}/${name.slice(name.lastIndexOf("/") + 1)}`); + } + return icon; + } } -- cgit v1.2.3-freya