blob: f7b4ed96e021137b161e1560c127568ac0c60605 (
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 | import QtQuick
import QtQuick.Effects
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: ScriptModel {
        values: {
	  var trayItems = Array.from(SystemTray.items.values).filter(item => item.status !== Status.Passive);
	  trayItems.sort((a, b) => a.category !== b.category ? b.category - a.category : a.id.localeCompare(b.id))
	  return trayItems;
	}
      }
      delegate: Item {
        id: trayItemWrapper
	required property var modelData
	required property int index
	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: icon.width + 6
	height: parent.height
	anchors.verticalCenter: parent.verticalCenter
	WrapperMouseArea {
	  id: trayItemArea
	  anchors.fill: parent
	  acceptedButtons: Qt.LeftButton | Qt.RightButton
	  hoverEnabled: true
	  cursorShape: trayItem.onlyMenu ? Qt.ArrowCursor : 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()
	    }
	  }
	  Rectangle {
	    anchors.fill: parent
	    color: {
	      if (trayItemArea.containsMouse)
		return "#33808080";
	      return "transparent";
	    }
	    Item {
	      anchors.fill: parent
	      layer.enabled: true
	      layer.effect: MultiEffect {
	        colorization: 1
		colorizationColor: "#555"
	      }
	      IconImage {
		id: icon
		anchors.centerIn: parent
		implicitSize: 16
		source: trayItemWrapper.iconSource
		asynchronous: true
		smooth: true
		mipmap: true
		layer.enabled: true
		layer.effect: MultiEffect {
		  id: effect
		  brightness: 1
		}
	      }
	    }
	  }
	}
	PopupWindow {
	  id: tooltip
          property bool nextVisible: (trayItem.tooltipTitle || trayItem.tooltipDescription) && (trayItemArea.containsMouse || tooltipMouseArea.containsMouse) && !menuAnchor.visible
	  anchor {
	    item: trayItemArea
	    edges: Edges.Bottom
	  }
	  visible: false
	  onNextVisibleChanged: hangTimer.restart()
	  Timer {
	    id: hangTimer
	    interval: 100
	    onTriggered: tooltip.visible = tooltip.nextVisible
	  }
	  color: "black"
	  implicitWidth: Math.max(tooltipTitle.contentWidth, tooltipDescription.contentWidth) + 16
	  implicitHeight: (trayItem.tooltipTitle ? tooltipTitle.contentHeight : 0) + (trayItem.tooltipDescription ? tooltipDescription.contentHeight : 0) + 16
          WrapperMouseArea {
	    id: tooltipMouseArea
	    hoverEnabled: true
	    enabled: true
	    margin: 4
	    anchors.fill: parent
	    Item {
	      anchors.fill: parent
	      Column {
		anchors.centerIn: parent
		Text {
		  id: tooltipTitle
		  enabled: trayItem.tooltipTitle
		  font.pointSize: 10
		  font.family: "Fira Sans"
		  font.bold: true
		  color: "white"
		  text: trayItem.tooltipTitle
		}
		Text {
		  id: tooltipDescription
		  enabled: trayItem.tooltipDescription
		  font.pointSize: 10
		  font.family: "Fira Sans"
		  color: "white"
		  text: trayItem.tooltipDescription
		}
	      }
	    }
	  }
	}
      }
    }
  }
  QsMenuAnchor {
    id: menuAnchor
  }
}
 |