diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/PipewireWidget.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/PipewireWidget.qml | 471 |
1 files changed, 471 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/PipewireWidget.qml b/accounts/gkleen@sif/shell/quickshell/PipewireWidget.qml new file mode 100644 index 00000000..3e0b8fd9 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/PipewireWidget.qml | |||
@@ -0,0 +1,471 @@ | |||
1 | import QtQuick | ||
2 | import QtQuick.Layouts | ||
3 | import QtQuick.Controls.Fusion | ||
4 | import Quickshell | ||
5 | import Quickshell.Services.Pipewire | ||
6 | import Quickshell.Widgets | ||
7 | |||
8 | Item { | ||
9 | height: parent.height | ||
10 | width: volumeIcon.width + 8 | ||
11 | anchors.verticalCenter: parent.verticalCenter | ||
12 | |||
13 | PwObjectTracker { | ||
14 | objects: [Pipewire.defaultAudioSink] | ||
15 | } | ||
16 | |||
17 | WrapperMouseArea { | ||
18 | id: widgetMouseArea | ||
19 | |||
20 | anchors.fill: parent | ||
21 | hoverEnabled: true | ||
22 | cursorShape: Qt.PointingHandCursor | ||
23 | |||
24 | onClicked: { | ||
25 | if (!Pipewire.defaultAudioSink) | ||
26 | return; | ||
27 | Pipewire.defaultAudioSink.audio.muted = !Pipewire.defaultAudioSink.audio.muted; | ||
28 | } | ||
29 | |||
30 | property real sensitivity: (1 / 40) / 120 | ||
31 | onWheel: event => { | ||
32 | if (!Pipewire.defaultAudioSink) | ||
33 | return; | ||
34 | Pipewire.defaultAudioSink.audio.volume += event.angleDelta.y * sensitivity; | ||
35 | } | ||
36 | |||
37 | Rectangle { | ||
38 | id: volumeWidget | ||
39 | |||
40 | anchors.fill: parent | ||
41 | color: { | ||
42 | if (widgetMouseArea.containsMouse) | ||
43 | return "#33808080"; | ||
44 | return "transparent"; | ||
45 | } | ||
46 | |||
47 | Item { | ||
48 | anchors.fill: parent | ||
49 | |||
50 | MaterialDesignIcon { | ||
51 | id: volumeIcon | ||
52 | |||
53 | implicitSize: 14 | ||
54 | anchors.centerIn: parent | ||
55 | |||
56 | icon: { | ||
57 | if (!Pipewire.defaultAudioSink || Pipewire.defaultAudioSink.audio.muted) | ||
58 | return "volume-off"; | ||
59 | if (Pipewire.defaultAudioSink.audio.volume <= 0.33) | ||
60 | return "volume-low"; | ||
61 | if (Pipewire.defaultAudioSink.audio.volume <= 0.67) | ||
62 | return "volume-medium"; | ||
63 | return "volume-high"; | ||
64 | } | ||
65 | color: "#555" | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | Loader { | ||
72 | id: tooltipLoader | ||
73 | |||
74 | active: false | ||
75 | |||
76 | Connections { | ||
77 | target: widgetMouseArea | ||
78 | function onContainsMouseChanged() { | ||
79 | if (widgetMouseArea.containsMouse) | ||
80 | tooltipLoader.active = true; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | PwObjectTracker { | ||
85 | objects: Pipewire.devices | ||
86 | } | ||
87 | PwObjectTracker { | ||
88 | objects: Pipewire.nodes | ||
89 | } | ||
90 | |||
91 | sourceComponent: PopupWindow { | ||
92 | id: tooltip | ||
93 | |||
94 | property bool openPopup: false | ||
95 | property bool nextVisible: widgetMouseArea.containsMouse || tooltipMouseArea.containsMouse || openPopup | ||
96 | |||
97 | anchor { | ||
98 | item: widgetMouseArea | ||
99 | edges: Edges.Bottom | Edges.Left | ||
100 | } | ||
101 | visible: false | ||
102 | |||
103 | onNextVisibleChanged: hangTimer.restart() | ||
104 | |||
105 | Timer { | ||
106 | id: hangTimer | ||
107 | interval: 100 | ||
108 | onTriggered: { | ||
109 | tooltip.visible = tooltip.nextVisible; | ||
110 | if (!tooltip.visible) | ||
111 | tooltipLoader.active = false; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | implicitWidth: tooltipContent.width | ||
116 | implicitHeight: tooltipContent.height | ||
117 | color: "transparent" | ||
118 | |||
119 | Rectangle { | ||
120 | width: tooltip.width | ||
121 | height: tooltipLayout.childrenRect.height + 16 | ||
122 | color: "black" | ||
123 | } | ||
124 | |||
125 | WrapperItem { | ||
126 | id: tooltipContent | ||
127 | |||
128 | bottomMargin: Math.max(0, 200 - tooltipLayout.implicitHeight) | ||
129 | |||
130 | WrapperMouseArea { | ||
131 | id: tooltipMouseArea | ||
132 | |||
133 | hoverEnabled: true | ||
134 | enabled: true | ||
135 | |||
136 | WrapperItem { | ||
137 | margin: 8 | ||
138 | bottomMargin: 8 | ||
139 | |||
140 | GridLayout { | ||
141 | id: tooltipLayout | ||
142 | |||
143 | columns: 4 | ||
144 | |||
145 | Repeater { | ||
146 | model: Array.from(Pipewire.devices.values).filter(dev => dev.type == "Audio/Device") | ||
147 | |||
148 | Item { | ||
149 | id: descItem | ||
150 | |||
151 | required property var modelData | ||
152 | required property int index | ||
153 | |||
154 | Layout.column: 0 | ||
155 | Layout.row: index | ||
156 | |||
157 | implicitWidth: descText.contentWidth | ||
158 | implicitHeight: descText.contentHeight | ||
159 | |||
160 | Text { | ||
161 | id: descText | ||
162 | |||
163 | color: "white" | ||
164 | font.pointSize: 10 | ||
165 | font.family: "Fira Sans" | ||
166 | |||
167 | text: descItem.modelData.description | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | Repeater { | ||
173 | id: defaultSinkRepeater | ||
174 | |||
175 | model: { | ||
176 | Array.from(Pipewire.devices.values) | ||
177 | .filter(dev => dev.type == "Audio/Device") | ||
178 | .map(device => Array.from(Pipewire.nodes.values).find(node => node.type == PwNodeType.AudioSink && node.device?.id == device.id )); | ||
179 | } | ||
180 | |||
181 | Item { | ||
182 | id: defaultSinkItem | ||
183 | |||
184 | required property var modelData | ||
185 | required property int index | ||
186 | |||
187 | visible: Boolean(modelData) | ||
188 | |||
189 | PwObjectTracker { | ||
190 | objects: [defaultSinkItem.modelData] | ||
191 | } | ||
192 | |||
193 | Layout.column: 1 | ||
194 | Layout.row: index | ||
195 | |||
196 | Layout.fillHeight: true | ||
197 | |||
198 | implicitWidth: 16 + 8 | ||
199 | |||
200 | WrapperMouseArea { | ||
201 | id: defaultSinkMouseArea | ||
202 | |||
203 | anchors.fill: parent | ||
204 | hoverEnabled: true | ||
205 | cursorShape: Qt.PointingHandCursor | ||
206 | |||
207 | onClicked: { | ||
208 | Pipewire.preferredDefaultAudioSink = defaultSinkItem.modelData | ||
209 | } | ||
210 | |||
211 | onWheel: event => scrollVolume(event); | ||
212 | property real sensitivity: (1 / 40) / 120 | ||
213 | function scrollVolume(event) { | ||
214 | defaultSinkItem.modelData.audio.volume += event.angleDelta.y * sensitivity; | ||
215 | } | ||
216 | |||
217 | Rectangle { | ||
218 | id: defaultSinkWidget | ||
219 | |||
220 | anchors.fill: parent | ||
221 | color: { | ||
222 | if (defaultSinkMouseArea.containsMouse) | ||
223 | return "#33808080"; | ||
224 | return "transparent"; | ||
225 | } | ||
226 | |||
227 | MaterialDesignIcon { | ||
228 | width: 16 | ||
229 | height: 16 | ||
230 | anchors.centerIn: parent | ||
231 | |||
232 | icon: { | ||
233 | if (defaultSinkItem.modelData?.id == Pipewire.defaultAudioSink?.id) | ||
234 | return "speaker"; | ||
235 | return "speaker-off"; | ||
236 | } | ||
237 | color: icon == "speaker" ? "white" : "#555" | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | PopupWindow { | ||
243 | id: volumeTooltip | ||
244 | |||
245 | property bool nextVisible: defaultSinkMouseArea.containsMouse || volumeTooltipMouseArea.containsMouse | ||
246 | |||
247 | anchor { | ||
248 | item: defaultSinkMouseArea | ||
249 | edges: Edges.Bottom | Edges.Left | ||
250 | } | ||
251 | visible: false | ||
252 | |||
253 | onNextVisibleChanged: volumeHangTimer.restart() | ||
254 | |||
255 | onVisibleChanged: tooltip.openPopup = volumeTooltip.visible | ||
256 | |||
257 | Timer { | ||
258 | id: volumeHangTimer | ||
259 | interval: 100 | ||
260 | onTriggered: volumeTooltip.visible = volumeTooltip.nextVisible | ||
261 | } | ||
262 | |||
263 | implicitWidth: volumeTooltipText.contentWidth + 16 | ||
264 | implicitHeight: volumeTooltipText.contentHeight + 16 | ||
265 | color: "black" | ||
266 | |||
267 | WrapperMouseArea { | ||
268 | id: volumeTooltipMouseArea | ||
269 | |||
270 | hoverEnabled: true | ||
271 | enabled: true | ||
272 | |||
273 | onWheel: event => defaultSinkMouseArea.scrollVolume(event); | ||
274 | |||
275 | anchors.centerIn: parent | ||
276 | |||
277 | Text { | ||
278 | id: volumeTooltipText | ||
279 | |||
280 | font.pointSize: 10 | ||
281 | font.family: "Fira Sans" | ||
282 | color: "white" | ||
283 | |||
284 | text: `${Math.round(defaultSinkItem.modelData?.audio?.volume * 100)}%` | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | Repeater { | ||
292 | id: defaultSourceRepeater | ||
293 | |||
294 | model: { | ||
295 | Array.from(Pipewire.devices.values) | ||
296 | .filter(dev => dev.type == "Audio/Device") | ||
297 | .map(device => Array.from(Pipewire.nodes.values).find(node => node.type == PwNodeType.AudioSource && node.device?.id == device.id )); | ||
298 | } | ||
299 | |||
300 | Item { | ||
301 | id: defaultSourceItem | ||
302 | |||
303 | required property var modelData | ||
304 | required property int index | ||
305 | |||
306 | visible: Boolean(modelData) | ||
307 | |||
308 | PwObjectTracker { | ||
309 | objects: [defaultSourceItem.modelData] | ||
310 | } | ||
311 | |||
312 | Layout.column: 2 | ||
313 | Layout.row: index | ||
314 | |||
315 | Layout.fillHeight: true | ||
316 | |||
317 | implicitWidth: 16 + 8 | ||
318 | |||
319 | WrapperMouseArea { | ||
320 | id: defaultSourceMouseArea | ||
321 | |||
322 | anchors.fill: parent | ||
323 | hoverEnabled: true | ||
324 | cursorShape: Qt.PointingHandCursor | ||
325 | |||
326 | onClicked: { | ||
327 | Pipewire.preferredDefaultAudioSource = defaultSourceItem.modelData | ||
328 | } | ||
329 | |||
330 | onWheel: event => scrollVolume(event); | ||
331 | property real sensitivity: (1 / 40) / 120 | ||
332 | function scrollVolume(event) { | ||
333 | defaultSourceItem.modelData.audio.volume += event.angleDelta.y * sensitivity; | ||
334 | } | ||
335 | |||
336 | Rectangle { | ||
337 | id: defaultSourceWidget | ||
338 | |||
339 | anchors.fill: parent | ||
340 | color: { | ||
341 | if (defaultSourceMouseArea.containsMouse) | ||
342 | return "#33808080"; | ||
343 | return "transparent"; | ||
344 | } | ||
345 | |||
346 | MaterialDesignIcon { | ||
347 | width: 16 | ||
348 | height: 16 | ||
349 | anchors.centerIn: parent | ||
350 | |||
351 | icon: { | ||
352 | if (defaultSourceItem.modelData?.id == Pipewire.defaultAudioSource?.id) | ||
353 | return "microphone"; | ||
354 | return "microphone-off"; | ||
355 | } | ||
356 | color: icon == "microphone" ? "white" : "#555" | ||
357 | } | ||
358 | } | ||
359 | } | ||
360 | |||
361 | PopupWindow { | ||
362 | id: volumeTooltip | ||
363 | |||
364 | property bool nextVisible: defaultSourceMouseArea.containsMouse || volumeTooltipMouseArea.containsMouse | ||
365 | |||
366 | anchor { | ||
367 | item: defaultSourceMouseArea | ||
368 | edges: Edges.Bottom | Edges.Left | ||
369 | } | ||
370 | visible: false | ||
371 | |||
372 | onNextVisibleChanged: volumeHangTimer.restart() | ||
373 | |||
374 | onVisibleChanged: tooltip.openPopup = volumeTooltip.visible | ||
375 | |||
376 | Timer { | ||
377 | id: volumeHangTimer | ||
378 | interval: 100 | ||
379 | onTriggered: volumeTooltip.visible = volumeTooltip.nextVisible | ||
380 | } | ||
381 | |||
382 | implicitWidth: volumeTooltipText.contentWidth + 16 | ||
383 | implicitHeight: volumeTooltipText.contentHeight + 16 | ||
384 | color: "black" | ||
385 | |||
386 | WrapperMouseArea { | ||
387 | id: volumeTooltipMouseArea | ||
388 | |||
389 | hoverEnabled: true | ||
390 | enabled: true | ||
391 | |||
392 | onWheel: event => defaultSourceMouseArea.scrollVolume(event); | ||
393 | |||
394 | anchors.centerIn: parent | ||
395 | |||
396 | Text { | ||
397 | id: volumeTooltipText | ||
398 | |||
399 | font.pointSize: 10 | ||
400 | font.family: "Fira Sans" | ||
401 | color: "white" | ||
402 | |||
403 | text: `${Math.round(defaultSourceItem.modelData?.audio?.volume * 100)}%` | ||
404 | } | ||
405 | } | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | |||
410 | Repeater { | ||
411 | id: profileRepeater | ||
412 | |||
413 | model: Array.from(Pipewire.devices.values).filter(dev => dev.type == "Audio/Device") | ||
414 | |||
415 | Item { | ||
416 | id: profileItem | ||
417 | |||
418 | required property var modelData | ||
419 | required property int index | ||
420 | |||
421 | PwObjectTracker { | ||
422 | objects: [profileItem.modelData] | ||
423 | } | ||
424 | |||
425 | Layout.column: 3 | ||
426 | Layout.row: index | ||
427 | |||
428 | Layout.fillWidth: true | ||
429 | |||
430 | implicitWidth: Math.max(profileBox.implicitWidth, 300) | ||
431 | implicitHeight: profileBox.height | ||
432 | |||
433 | ComboBox { | ||
434 | id: profileBox | ||
435 | |||
436 | model: profileItem.modelData.profiles | ||
437 | |||
438 | textRole: "description" | ||
439 | valueRole: "index" | ||
440 | onActivated: profileItem.modelData.setProfile(currentValue) | ||
441 | |||
442 | anchors.fill: parent | ||
443 | |||
444 | implicitContentWidthPolicy: ComboBox.WidestText | ||
445 | |||
446 | Connections { | ||
447 | target: profileItem.modelData | ||
448 | function onCurrentProfileChanged() { | ||
449 | profileBox.currentIndex = Array.from(profileItem.modelData.profiles).findIndex(profile => profile.index == profileItem.modelData.currentProfile); | ||
450 | } | ||
451 | } | ||
452 | Component.onCompleted: { | ||
453 | profileBox.currentIndex = Array.from(profileItem.modelData.profiles).findIndex(profile => profile.index == profileItem.modelData.currentProfile); | ||
454 | } | ||
455 | |||
456 | Connections { | ||
457 | target: profileBox.popup | ||
458 | function onVisibleChanged() { | ||
459 | tooltip.openPopup = profileBox.popup.visible | ||
460 | } | ||
461 | } | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | } | ||
471 | } | ||