import QtQuick import Quickshell import Quickshell.Services.SystemTray import "../core" import "../services" import "../theme" Item { id: root objectName: "trayIcon" required property var trayItem readonly property var containingWindow: root.QsWindow.window property var barScreen // Tray pill this icon sits in. Menus and tooltips are placed under it so // they do not jump sideways while moving between icons. property var group: null readonly property Item placement: group || root readonly property bool pointerInside: mouse.containsMouse || (!!group && group.hovered) readonly property bool menuActive: TrayService.opened && TrayService.anchorItem === root width: TrayService.options.iconSize + 12; height: ModuleRegistry.pillHeight Component.onCompleted: TrayService.registerIcon(root) Component.onDestruction: TrayService.unregisterIcon(root) readonly property string label: trayItem ? (trayItem.tooltipTitle || trayItem.title || trayItem.id) : "" readonly property bool hoverMenu: TrayService.options.hoverMenus && !!trayItem && trayItem.hasMenu // Once a menu or bar popout is open, hovering another icon switches instantly // (keeping a click-opened menu sticky); otherwise wait for the hover delay. function enter() { if (menuActive) return; if (!hoverMenu) { PopoutState.hover(root, label ? "tooltip" : "", label); return; } if (PopoutState.warm) openMenu(TrayService.opened ? TrayService.closeOnLeave : true); else intent.restart(); } function leave() { intent.stop(); PopoutState.unhover(root); } function openMenu(hover) { intent.stop(); return TrayService.open(trayItem, root, hover); } function click(button, modifiers) { intent.stop(); PopoutState.close(); if (!trayItem) return; if (button === Qt.RightButton || (button === Qt.LeftButton && trayItem.onlyMenu)) { if ((modifiers & Qt.ShiftModifier) || !trayItem.hasMenu) { TrayService.close(); const window = root.containingWindow; const point = root.mapToItem(window.contentItem, 0, root.height); trayItem.display(window, point.x, point.y); } else openMenu(false); } else { TrayService.close(); if (button === Qt.MiddleButton) trayItem.secondaryActivate(); else trayItem.activate(); } } Rectangle { anchors.fill: parent; radius: height / 2 color: root.menuActive ? Qt.alpha(Theme.accent, 0.2) : root.pointerInside ? Qt.alpha(Theme.text, 0.12) : TrayService.options.background === "icons" ? Theme.surfaceVariant : Theme.transparent border.width: root.menuActive ? 1 : 0; border.color: Theme.border Behavior on color { ColorAnimation { duration: Theme.duration } } } Image { anchors.centerIn: parent; width: TrayService.options.iconSize; height: width source: root.trayItem ? root.trayItem.icon : "" sourceSize.width: width; sourceSize.height: height fillMode: Image.PreserveAspectFit scale: mouse.pressed ? 0.92 : 1 Behavior on scale { NumberAnimation { duration: Theme.duration / 2 } } } Rectangle { anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter width: 4; height: 4; radius: 2; color: Theme.urgent visible: root.trayItem && root.trayItem.status === Status.NeedsAttention } MouseArea { id: mouse; anchors.fill: parent; hoverEnabled: true acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton cursorShape: Qt.PointingHandCursor onEntered: root.enter() onExited: root.leave() // Moving over an icon also starts the hover, in case no enter event // arrived (e.g. the pointer was already there when a menu closed). onPositionChanged: if (!root.menuActive && !intent.running && !TrayService.opened && root.hoverMenu) intent.restart() onClicked: event => root.click(event.button, event.modifiers) onWheel: event => { if (root.trayItem) root.trayItem.scroll(event.angleDelta.y || event.angleDelta.x, event.angleDelta.y === 0); } } Timer { id: intent; interval: TrayService.options.hoverDelay; onTriggered: if (mouse.containsMouse && TrayService.options.hoverMenus) root.openMenu(true) } }