Files
dotfiles/.config/quickshell/own/modules/SysTrayWidget.qml
T

79 lines
2.5 KiB
QML

// modules/SysTrayWidget.qml - SNI system tray (nm-applet, blueman ...)
import QtQuick
import QtQuick.Layouts
import Quickshell.Services.SystemTray
import Quickshell
import ".."
Rectangle {
id: root
required property var parentWindow
color: "transparent"
radius: Theme.radius
implicitWidth: trayRow.implicitWidth + 6
implicitHeight: Theme.barHeight
RowLayout {
id: trayRow
anchors.centerIn: parent
spacing: Theme.spacing
Repeater {
model: SystemTray.items
Rectangle {
id: trayRect
required property SystemTrayItem modelData
width: Theme.barHeight-Theme.barPadding*2; height: Theme.barHeight-Theme.barPadding*2
radius: Theme.radius
color: trayHover.containsMouse
? Theme.pillHover
: Theme.pill
Behavior on color { ColorAnimation { duration: 150 } }
Image {
anchors { fill: parent; margins: 4 }
source: modelData.icon
fillMode: Image.PreserveAspectFit
smooth: true
}
QsMenuAnchor {
id: menuAnchor
menu: modelData.menu
anchor.window: root.parentWindow
anchor.rect: Qt.rect(
trayRect.mapToItem(null, 0, 0).x,
trayRect.mapToItem(null, 0, 0).y,
trayRect.width,
trayRect.height
)
}
MouseArea {
id: trayHover
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: (m) => {
if (m.button === Qt.LeftButton)
modelData.activate()
else if (modelData.hasMenu)
menuAnchor.open()
}
}
// Attention indicator dot
Rectangle {
visible: modelData.status === SystemTrayItem.NeedsAttention
width: 5; height: 5; radius: 2.5
color: Theme.wsUrgent
anchors { bottom: parent.bottom; right: parent.right; margins: 1 }
}
}
}
}
}