From f4f652ed8a3f0daff8096f250f448ca55023c4b0 Mon Sep 17 00:00:00 2001 From: lucy Date: Fri, 16 Jan 2026 12:00:55 +0100 Subject: [PATCH] add systray --- modules/Bar/Bar.qml | 1 + modules/Bar/SystemTray.qml | 18 ++++++++++++++++++ modules/Bar/TrayItem.qml | 36 ++++++++++++++++++++++++++++++++++++ shell.qml | 1 + 4 files changed, 56 insertions(+) diff --git a/modules/Bar/Bar.qml b/modules/Bar/Bar.qml index 113b20b..24d36fa 100644 --- a/modules/Bar/Bar.qml +++ b/modules/Bar/Bar.qml @@ -44,6 +44,7 @@ Variants { anchors.verticalCenter: parent.verticalCenter Clock {} Volume {} + SystemTray {} Battery {} } } diff --git a/modules/Bar/SystemTray.qml b/modules/Bar/SystemTray.qml index e69de29..4f9b638 100644 --- a/modules/Bar/SystemTray.qml +++ b/modules/Bar/SystemTray.qml @@ -0,0 +1,18 @@ +import Quickshell.Services.SystemTray +import QtQuick +import "." +import "../../settings/" + +Item { + id: root + implicitWidth: trayRow.implicitWidth + implicitHeight: Settings.config.barHeight + Row { + id: trayRow + Repeater { + id: trayRepeater + model: SystemTray.items + delegate: TrayItem {} + } + } +} diff --git a/modules/Bar/TrayItem.qml b/modules/Bar/TrayItem.qml index e69de29..94cdd38 100644 --- a/modules/Bar/TrayItem.qml +++ b/modules/Bar/TrayItem.qml @@ -0,0 +1,36 @@ +import QtQuick +import Quickshell +import Quickshell.Services.SystemTray +import Quickshell.Widgets + +MouseArea { + id: root + property var bar: root.QsWindow.window + required property SystemTrayItem modelData + + acceptedButtons: Qt.LeftButton | Qt.RightButton + implicitWidth: 16 + implicitHeight: 16 + + onClicked: event => { + if (event.button === Qt.LeftButton) { + modelData.activate(); + } else if (modelData.hasMenu) { + menu.open(); + } + } + + QsMenuAnchor { + id: menu + menu: root.modelData.hasMenu ? root.modelData.menu : null + anchor.item: root + } + + IconImage { + id: trayIcon + width: parent.implicitWidth + height: parent.implicitHeight + source: root.modelData.icon + anchors.centerIn: parent + } +} diff --git a/shell.qml b/shell.qml index 1d1ac4d..79d7067 100644 --- a/shell.qml +++ b/shell.qml @@ -1,3 +1,4 @@ +//@ pragma UseQApplication import Quickshell import QtQuick import "./settings/"