blob: ee5bf42522da82ec062ca044680f39aefb28dba6 (
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
|
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Services.Mpris
Item {
id: root
property QtObject manualExpandedPlayer: null
readonly property var activePlayers: Mpris.players?.values || []
readonly property var expandedPlayer: {
if (root.manualExpandedPlayer !== null && root.activePlayers.includes(root.manualExpandedPlayer)) {
return root.manualExpandedPlayer;
}
for (const player of root.activePlayers) {
if (player.playbackState === MprisPlaybackState.Playing) {
return player;
}
}
if (root.activePlayers.length > 0) {
return root.activePlayers[0];
}
return null;
}
width: childrenRect.width
height: parent.height
Row {
anchors.verticalCenter: parent.verticalCenter
MusicVisualizer {
active: root.expandedPlayer?.playbackState === MprisPlaybackState.Playing
anchors.verticalCenter: parent.verticalCenter
}
}
MouseArea {
anchors.fill: parent
onClicked: GlobalState.toggle("Media")
}
PopupWindow {
id: popup
visible: GlobalState.activePopup === "Media"
grabFocus: true
implicitWidth: card.width
implicitHeight: card.height
anchor {
window: barWindow
item: root
edges: Edges.Bottom
gravity: Edges.Bottom
margins.top: Theme.popupGap
}
color: Theme.transparent
PopupCard {
id: card
width: 320
ColumnLayout {
Layout.fillWidth: true
spacing: 0
Layout.margins: 8
Repeater {
model: root.activePlayers.length > 0 ? root.activePlayers : [null]
delegate: Item {
id: playerDelegate
Layout.fillWidth: true
implicitHeight: mediaCard.implicitHeight + (separator.visible ? separator.height + 16 : 0)
required property var modelData
required property int index
readonly property bool isEmpty: modelData === null
readonly property bool isExpanded: root.expandedPlayer === modelData && !isEmpty
ColumnLayout {
anchors.fill: parent
spacing: 16
MediaCard {
id: mediaCard
Layout.fillWidth: true
player: playerDelegate.modelData
isExpanded: playerDelegate.isExpanded
onClicked: {
if (!playerDelegate.isEmpty) {
root.manualExpandedPlayer = playerDelegate.modelData;
} else {
Quickshell.execDetached(["spotify"]);
}
}
}
Rectangle {
id: separator
Layout.fillWidth: true
height: 1
color: Theme.border
opacity: 0.3
visible: !playerDelegate.isEmpty && playerDelegate.index < root.activePlayers.length - 1
Layout.topMargin: 4
}
}
}
}
}
}
}
}
|