mpris: player switcher for multiple media sessions
This commit is contained in:
parent
dea4541718
commit
b5b2276ff1
1 changed files with 49 additions and 10 deletions
|
|
@ -12,8 +12,14 @@ M.BarSection {
|
||||||
visible: opacity > 0
|
visible: opacity > 0
|
||||||
tooltip: ""
|
tooltip: ""
|
||||||
|
|
||||||
readonly property MprisPlayer player: Mpris.players.values[0] ?? null
|
property int _playerIdx: 0
|
||||||
|
readonly property var _players: Mpris.players.values ?? []
|
||||||
|
readonly property MprisPlayer player: _players[_playerIdx] ?? _players[0] ?? null
|
||||||
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
|
readonly property bool playing: player?.playbackState === MprisPlaybackState.Playing
|
||||||
|
|
||||||
|
// Reset index if current player disappears
|
||||||
|
on_PlayersChanged: if (_playerIdx >= _players.length)
|
||||||
|
_playerIdx = 0
|
||||||
property string _cachedArt: ""
|
property string _cachedArt: ""
|
||||||
property string _artTrack: ""
|
property string _artTrack: ""
|
||||||
|
|
||||||
|
|
@ -428,15 +434,48 @@ M.BarSection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player name
|
// Player switcher
|
||||||
|
Row {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
height: 22
|
||||||
|
spacing: 6
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: root._players
|
||||||
|
|
||||||
|
delegate: Rectangle {
|
||||||
|
required property var modelData
|
||||||
|
required property int index
|
||||||
|
|
||||||
|
readonly property bool _active: index === root._playerIdx
|
||||||
|
|
||||||
|
width: _pLabel.implicitWidth + 12
|
||||||
|
height: 18
|
||||||
|
radius: 9
|
||||||
|
color: _active ? M.Theme.base02 : (pArea.containsMouse ? M.Theme.base02 : "transparent")
|
||||||
|
border.color: _active ? M.Theme.base0E : M.Theme.base03
|
||||||
|
border.width: _active ? 1 : 0
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
width: parent.width
|
id: _pLabel
|
||||||
height: 20
|
anchors.centerIn: parent
|
||||||
horizontalAlignment: Text.AlignHCenter
|
text: modelData.identity ?? "Player"
|
||||||
text: root.player?.identity ?? ""
|
color: _active ? M.Theme.base0E : M.Theme.base04
|
||||||
color: M.Theme.base03
|
|
||||||
font.pixelSize: M.Theme.fontSize - 2
|
font.pixelSize: M.Theme.fontSize - 2
|
||||||
font.family: M.Theme.fontFamily
|
font.family: M.Theme.fontFamily
|
||||||
|
font.bold: _active
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: pArea
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: root._playerIdx = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue