diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-09-18 15:10:16 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-09-18 15:10:16 +0800 |
| commit | 8a71bd72f53e3629fb1d23d7c1b153207ba44789 (patch) | |
| tree | 3d91e82c5be62d6e65383df0b906e80c13f0a4cc /bar/Tray.qml | |
| parent | 654a198d61b82dba6203280163b5c92ed9d48ceb (diff) | |
feat: system tray
Diffstat (limited to 'bar/Tray.qml')
| -rw-r--r-- | bar/Tray.qml | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/bar/Tray.qml b/bar/Tray.qml index 1148ac3..1011e01 100644 --- a/bar/Tray.qml +++ b/bar/Tray.qml @@ -1,10 +1,89 @@ import QtQuick +import QtQuick.Controls import QtQuick.Layouts -import Quickshell.Hyprland import Quickshell.Services.SystemTray -import Quickshell.Wayland import Quickshell.Widgets import Qt5Compat.GraphicalEffects -import Quickshell -Item {} +import qs.components +import qs.config + +Item { + id: root + + property bool active + property bool hasImportant: false + + implicitWidth: layout.implicitWidth + implicitHeight: layout.implicitHeight + + visible: active || hasImportant + + RowLayout { + id: layout + anchors.fill: parent + + Repeater { + Layout.fillHeight: true + model: SystemTray.items + + delegate: IRect { + required property SystemTrayItem modelData + + color: "transparent" + + Layout.fillHeight: true + implicitWidth: childrenRect.width + implicitHeight: childrenRect.height + + IconImage { + source: parent.modelData.icon + implicitSize: parent.height + } + + IToolTip { + active: (modelData.tooltipTitle || modelData.tooltipDescription) + text: (modelData.tooltipTitle || '') + (modelData.tooltipTitle && modelData.tooltipDescription ? '\n' : '') + (modelData.tooltipDescription || '') + } + + function syncImportance() { + if (modelData?.status === Status.Active || modelData?.status === Status.NeedsAttention) + root.hasImportant = true; + else if (SystemTray.items.values.every(item => item.status === Status.Passive)) + root.hasImportant = false; + } + + Component.onCompleted: { + syncImportance(); + } + + Connections { + target: modelData + + function onStatusChanged() { + syncImportance(); + } + } + + TapHandler { + acceptedButtons: Qt.LeftButton + onTapped: parent.modelData.activate() + } + TapHandler { + acceptedButtons: Qt.MiddleButton + onTapped: parent.modelData.secondaryActivate() + } + TapHandler { + acceptedButtons: Qt.RightButton + onTapped: (eventPoint, button) => parent.modelData.display(barWindow, eventPoint.scenePosition.x, eventPoint.scenePosition.y) + } + WheelHandler { + onWheel: event => parent.modelData.scroll(event.angleDelta.y) + } + HoverHandler { + id: hover + } + } + } + } +} |
