From ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 23 Sep 2026 21:08:35 +0200 Subject: ... --- .../gkleen@skadhi/shell/quickshell/SystemTray.qml | 201 +++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 accounts/gkleen@skadhi/shell/quickshell/SystemTray.qml (limited to 'accounts/gkleen@skadhi/shell/quickshell/SystemTray.qml') diff --git a/accounts/gkleen@skadhi/shell/quickshell/SystemTray.qml b/accounts/gkleen@skadhi/shell/quickshell/SystemTray.qml new file mode 100644 index 00000000..f0c50632 --- /dev/null +++ b/accounts/gkleen@skadhi/shell/quickshell/SystemTray.qml @@ -0,0 +1,201 @@ +import QtQuick +import QtQuick.Effects +import Quickshell +import Quickshell.Widgets +import Quickshell.Services.SystemTray + +Item { + anchors.verticalCenter: parent.verticalCenter + width: systemTrayRow.childrenRect.width + height: parent.height + clip: true + + Row { + id: systemTrayRow + anchors.centerIn: parent + width: childrenRect.width + height: parent.height + spacing: 0 + + Repeater { + model: ScriptModel { + values: { + var trayItems = Array.from(SystemTray.items.values).filter(item => item.status !== Status.Passive && !(["Fcitx"].includes(item.id))); + trayItems.sort((a, b) => a.category !== b.category ? b.category - a.category : a.id.localeCompare(b.id)) + return trayItems; + } + } + + delegate: Item { + id: trayItemWrapper + + required property var modelData + required property int index + + property var trayItem: modelData + property string iconSource: { + let icon = trayItem && trayItem.icon + if (typeof icon === 'string' || icon instanceof String) { + if (icon.includes("?path=")) { + const split = icon.split("?path=") + if (split.length !== 2) + return icon + const name = split[0] + const path = split[1] + const fileName = name.substring( + name.lastIndexOf("/") + 1) + return `file://${path}/${fileName}` + } + return icon + } + return "" + } + + width: icon.width + 6 + height: parent.height + anchors.verticalCenter: parent.verticalCenter + + WrapperMouseArea { + id: trayItemArea + + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + hoverEnabled: true + cursorShape: trayItem.onlyMenu ? Qt.ArrowCursor : Qt.PointingHandCursor + onClicked: mouse => { + if (!trayItem) + return + + if (mouse.button === Qt.LeftButton + && !trayItem.onlyMenu) { + trayItem.activate() + return + } + + if (trayItem.hasMenu) { + var globalPos = mapToGlobal(0, 0) + var currentScreen = screen || Screen + var screenX = currentScreen.x || 0 + var relativeX = globalPos.x - screenX + menuAnchor.menu = trayItem.menu + menuAnchor.anchor.window = bar + menuAnchor.anchor.rect = Qt.rect( + relativeX, + 21, + parent.width, 1) + menuAnchor.open() + } + } + + Rectangle { + anchors.fill: parent + color: { + if (trayItemArea.containsMouse) + return "#33808080"; + return "transparent"; + } + + Item { + anchors.fill: parent + + layer.enabled: true + layer.effect: MultiEffect { + colorization: 1 + colorizationColor: "#555" + } + + IconImage { + id: icon + + anchors.centerIn: parent + implicitSize: 16 + source: trayItemWrapper.iconSource + asynchronous: true + smooth: true + mipmap: true + + layer.enabled: true + layer.effect: MultiEffect { + id: effect + + brightness: 1 + } + } + } + } + } + + PopupWindow { + id: tooltip + + property bool nextVisible: (trayItem.tooltipTitle || trayItem.tooltipDescription) && (trayItemArea.containsMouse || tooltipMouseArea.containsMouse) && !menuAnchor.visible + + anchor { + item: trayItemArea + edges: Edges.Bottom + } + + visible: false + onNextVisibleChanged: hangTimer.restart() + + Timer { + id: hangTimer + interval: 100 + onTriggered: tooltip.visible = tooltip.nextVisible + } + + color: "black" + + implicitWidth: Math.max(tooltipTitle.contentWidth, tooltipDescription.contentWidth) + 16 + implicitHeight: (trayItem.tooltipTitle ? tooltipTitle.contentHeight : 0) + (trayItem.tooltipDescription ? tooltipDescription.contentHeight : 0) + 16 + + WrapperMouseArea { + id: tooltipMouseArea + + hoverEnabled: true + enabled: true + + margin: 4 + + anchors.fill: parent + + Item { + anchors.fill: parent + + Column { + anchors.centerIn: parent + Text { + id: tooltipTitle + + enabled: trayItem.tooltipTitle + + font.pointSize: 10 + font.family: "Fira Sans" + font.bold: true + color: "white" + + text: trayItem.tooltipTitle + } + + Text { + id: tooltipDescription + + enabled: trayItem.tooltipDescription + + font.pointSize: 10 + font.family: "Fira Sans" + color: "white" + + text: trayItem.tooltipDescription + } + } + } + } + } + } + } + } + QsMenuAnchor { + id: menuAnchor + } +} -- cgit v1.2.3