From 762bae37cb008ac2aa536dac01dc52538e2e4601 Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Tue, 28 Oct 2025 00:46:21 +0100 Subject: [PATCH] I guess it works lmao --- Bar.qml | 1 + Modules/TrayItem.qml | 37 +++++++++--------- Modules/TrayMenu.qml | 87 ++++++++++++++++++++++++++++++++++++++++++ Modules/TrayWidget.qml | 4 ++ 4 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 Modules/TrayMenu.qml diff --git a/Bar.qml b/Bar.qml index ce0cd79..bbdb1ae 100644 --- a/Bar.qml +++ b/Bar.qml @@ -16,6 +16,7 @@ Scope { PanelWindow { id: bar required property var modelData + property bool trayMenuVisible: false screen: modelData anchors { diff --git a/Modules/TrayItem.qml b/Modules/TrayItem.qml index 406bd06..35f5825 100644 --- a/Modules/TrayItem.qml +++ b/Modules/TrayItem.qml @@ -7,6 +7,7 @@ import Caelestia import Quickshell import Quickshell.Widgets import Quickshell.Services.SystemTray +import qs.Modules MouseArea { id: root @@ -16,17 +17,9 @@ MouseArea { implicitWidth: 22 implicitHeight: 22 + hoverEnabled: true 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 @@ -51,13 +44,23 @@ MouseArea { id: analyser sourceItem: icon } + + TrayMenu { + id: trayMenu + menu: root.item.menu + anchor.item: root + anchor.edges: Edges.Bottom + anchor.margins { + left: -270 + } + } + } - QsMenuAnchor { - id: menuAnchor - menu: root.item.menu - anchor.item: root - anchor.edges: Edges.Bottom | Edges.Left - anchor.margins.top: 23 - anchor.adjustment: PopupAdjustment.SlideX + onClicked: { + if ( mouse.button === Qt.LeftButton ) { + root.item.activate(); + } else if ( mouse.button === Qt.RightButton ) { + trayMenu.visible = !trayMenu.visible; + } } } diff --git a/Modules/TrayMenu.qml b/Modules/TrayMenu.qml new file mode 100644 index 0000000..f7ff246 --- /dev/null +++ b/Modules/TrayMenu.qml @@ -0,0 +1,87 @@ +pragma ComponentBehavior: Bound + +import Quickshell +import QtQuick +import QtQuick.Layouts +import Quickshell.Hyprland + +PopupWindow { + id: root + required property QsMenuHandle menu + property int height: entryCount * ( entryHeight + 3 ) + property int entryHeight: 30 + property int entryCount: 0 + implicitWidth: 300 + implicitHeight: height + color: "transparent" + + QsMenuOpener { + id: menuOpener + menu: root.menu + } + + HyprlandFocusGrab { + id: grab + windows: [ root ] + onCleared: { + root.visible = false; + } + } + + onVisibleChanged: { + grab.active = root.visible; + } + Rectangle { + anchors.fill: parent + color: "#90000000" + radius: 8 + border.color: "#10FFFFFF" + ColumnLayout { + id: columnLayout + anchors.fill: parent + anchors.margins: 5 + spacing: 2 + Repeater { + id: repeater + model: menuOpener.children + Rectangle { + id: menuItem + width: root.implicitWidth + Layout.maximumWidth: parent.width + Layout.fillHeight: true + height: root.entryHeight + color: mouseArea.containsMouse && !modelData.isSeparator ? "#15FFFFFF" : "transparent" + radius: 4 + visible: modelData.isSeparator ? false : true + required property QsMenuEntry modelData + + Component.onCompleted: { + if ( !modelData.isSeparator ) { + root.entryCount += 1; + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + preventStealing: true + propagateComposedEvents: true + acceptedButtons: Qt.LeftButton + onClicked: { + menuItem.modelData.triggered(); + root.visible = false; + } + } + Text { + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 10 + text: menuItem.modelData.text + color: "white" + } + } + } + } + } +} diff --git a/Modules/TrayWidget.qml b/Modules/TrayWidget.qml index 23122aa..13f4a52 100644 --- a/Modules/TrayWidget.qml +++ b/Modules/TrayWidget.qml @@ -1,9 +1,12 @@ +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Layouts import Quickshell import Quickshell.Services.SystemTray Rectangle { + id: root required property PanelWindow bar implicitHeight: parent.height implicitWidth: rowL.implicitWidth + 20 @@ -14,6 +17,7 @@ Rectangle { id: rowL anchors.centerIn: parent Repeater { + id: repeater model: SystemTray.items TrayItem { required property SystemTrayItem modelData