blob: a02a81fdf4678fe712c4d1a97754138b130738ca (
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
90
91
92
93
94
|
import QtQuick
import Quickshell
import Quickshell.Widgets
import Quickshell.Services.SystemTray
Item {
anchors.verticalCenter: parent.verticalCenter
width: systemTrayRow.childrenRect.width
height: parent.height
clip: true
Row {
id: systemTrayRow
anchors.centerIn: parent
width: childrenRect.width
height: parent.height
spacing: 0
Repeater {
model: SystemTray.items.values
delegate: Item {
property var trayItem: modelData
property string iconSource: {
let icon = trayItem && trayItem.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 ""
}
width: 16
height: parent.height
anchors.verticalCenter: parent.verticalCenter
IconImage {
anchors.centerIn: parent
width: parent.width
height: parent.width
source: parent.iconSource
asynchronous: true
smooth: true
mipmap: true
}
MouseArea {
id: trayItemArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: mouse => {
if (!trayItem)
return
if (mouse.button === Qt.LeftButton
&& !trayItem.onlyMenu) {
trayItem.activate()
return
}
if (trayItem.hasMenu) {
var globalPos = mapToGlobal(0, 0)
var currentScreen = screen || Screen
var screenX = currentScreen.x || 0
var relativeX = globalPos.x - screenX
menuAnchor.menu = trayItem.menu
menuAnchor.anchor.window = bar
menuAnchor.anchor.rect = Qt.rect(
relativeX,
21,
parent.width, 1)
menuAnchor.open()
}
}
}
}
}
}
QsMenuAnchor {
id: menuAnchor
}
}
|