summaryrefslogtreecommitdiff
path: root/bar/Tray.qml
blob: 1011e0155f2864b3fbc7febca3c6f1e58ca5b46c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell.Services.SystemTray
import Quickshell.Widgets
import Qt5Compat.GraphicalEffects

import qs.components
import qs.config

Item {
	id: root

	property bool active
	property bool hasImportant: false

	implicitWidth: layout.implicitWidth
	implicitHeight: layout.implicitHeight

	visible: active || hasImportant

	RowLayout {
		id: layout
		anchors.fill: parent

		Repeater {
			Layout.fillHeight: true
			model: SystemTray.items

			delegate: IRect {
				required property SystemTrayItem modelData

				color: "transparent"

				Layout.fillHeight: true
				implicitWidth: childrenRect.width
				implicitHeight: childrenRect.height

				IconImage {
					source: parent.modelData.icon
					implicitSize: parent.height
				}

				IToolTip {
					active: (modelData.tooltipTitle || modelData.tooltipDescription)
					text: (modelData.tooltipTitle || '') + (modelData.tooltipTitle && modelData.tooltipDescription ? '\n' : '') + (modelData.tooltipDescription || '')
				}

				function syncImportance() {
					if (modelData?.status === Status.Active || modelData?.status === Status.NeedsAttention)
						root.hasImportant = true;
					else if (SystemTray.items.values.every(item => item.status === Status.Passive))
						root.hasImportant = false;
				}

				Component.onCompleted: {
					syncImportance();
				}

				Connections {
					target: modelData

					function onStatusChanged() {
						syncImportance();
					}
				}

				TapHandler {
					acceptedButtons: Qt.LeftButton
					onTapped: parent.modelData.activate()
				}
				TapHandler {
					acceptedButtons: Qt.MiddleButton
					onTapped: parent.modelData.secondaryActivate()
				}
				TapHandler {
					acceptedButtons: Qt.RightButton
					onTapped: (eventPoint, button) => parent.modelData.display(barWindow, eventPoint.scenePosition.x, eventPoint.scenePosition.y)
				}
				WheelHandler {
					onWheel: event => parent.modelData.scroll(event.angleDelta.y)
				}
				HoverHandler {
					id: hover
				}
			}
		}
	}
}