From ad43c3c694671ebfcadf2fc38bc90a52b84a13eb Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Thu, 16 Oct 2025 16:15:49 +0200 Subject: [PATCH] trayicon rendering --- Modules/GetIcons.qml | 16 +++++++++++++ Modules/TrayItem.qml | 56 ++++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 Modules/GetIcons.qml diff --git a/Modules/GetIcons.qml b/Modules/GetIcons.qml new file mode 100644 index 0000000..293adc9 --- /dev/null +++ b/Modules/GetIcons.qml @@ -0,0 +1,16 @@ +pragma Singleton + +import Quickshell +import Quickshell.Services.Notifications + +Singleton { + id: root + + function getTrayIcon(id: string, icon: string): string { + if (icon.includes("?path=")) { + const [name, path] = icon.split("?path="); + icon = Qt.resolvedUrl(`${path}/${name.slice(name.lastIndexOf("/") + 1)}`); + } + return icon; + } +} diff --git a/Modules/TrayItem.qml b/Modules/TrayItem.qml index 420f967..406bd06 100644 --- a/Modules/TrayItem.qml +++ b/Modules/TrayItem.qml @@ -3,31 +3,53 @@ import QtQuick import QtQuick.Controls import QtQuick.Effects +import Caelestia import Quickshell import Quickshell.Widgets import Quickshell.Services.SystemTray -IconImage { +MouseArea { id: root + required property SystemTrayItem item - source: root.item.icon - implicitWidth: 18 - implicitHeight: 18 - mipmap: false - asynchronous: true - MouseArea { + implicitWidth: 22 + implicitHeight: 22 + + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: event => { + switch (event.button) { + case Qt.LeftButton: root.item.activate(); break; + case Qt.RightButton: + if (root.item.hasMenu) { + menuAnchor.open(); + } + break; + } + } + IconImage { + id: icon + anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton - onClicked: event => { - switch (event.button) { - case Qt.LeftButton: root.item.activate(); break; - case Qt.RightButton: - if (root.item.hasMenu) { - menuAnchor.open(); - } - break; - } + layer.enabled: true + + layer.onEnabledChanged: { + if (layer.enabled && status === Image.Ready) + analyser.requestUpdate(); + } + + onStatusChanged: { + if (layer.enabled && status === Image.Ready) + analyser.requestUpdate(); + } + + source: GetIcons.getTrayIcon(root.item.id, root.item.icon) + + mipmap: false + asynchronous: true + ImageAnalyser { + id: analyser + sourceItem: icon } } QsMenuAnchor {