Files
Quickbar/SysTrayWidget.qml

98 lines
3.2 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Widgets
import Quickshell.Services.SystemTray
import qs.Common
import qs.Common.Styled
import qs.Services
BackgroundRectangle {
id: root
MarginWrapperManager {
rightMargin: Theme.gaps
leftMargin: Theme.gaps
}
property string monitor: ""
// color: Theme.backgroudColor
RowLayout {
property var monitor: parent.monitor
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
Repeater {
property string monitor: parent.monitor
model: SystemTray.items.values
delegate: Rectangle {
id: systrayItem
required property var modelData
property string monitor: parent.monitor
property var model: modelData
property string iconSource: {
let icon = systrayItem.model && systrayItem.model.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 "";
}
implicitHeight: 30
implicitWidth: 30
color: "transparent"
IconImage {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
width: 25
height: 25
source: systrayItem.iconSource
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
hoverEnabled: true
onEntered: {
PopUpHover.start(systrayItem, "systray");
}
onExited: {
PopUpHover.exit();
}
onClicked: mouse => {
if (mouse.button === Qt.RightButton) {
menuAnchor.menu = systrayItem.model.menu;
menuAnchor.anchor.item = systrayItem;
menuAnchor.anchor.rect = Qt.rect(0, systrayItem.implicitHeight, 0, 0);
menuAnchor.open();
} else if (mouse.button === Qt.LeftButton)
// systrayItem.model.activate()
{}
}
onDoubleClicked: {
systrayItem.model.activate();
}
}
}
}
}
QsMenuAnchor {
id: menuAnchor
}
}