Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ca356fb5 | ||
|
|
1b6c2fee91 |
2 changed files with 53 additions and 79 deletions
|
|
@ -306,58 +306,50 @@ Column {
|
||||||
// Player switcher
|
// Player switcher
|
||||||
Item {
|
Item {
|
||||||
width: root.width
|
width: root.width
|
||||||
height: root.players.length > 1 ? 28 : 0
|
height: root.players.length > 1 ? _playerFlow.implicitHeight + 6 : 0
|
||||||
visible: root.players.length > 1
|
visible: root.players.length > 1
|
||||||
|
|
||||||
Flickable {
|
Flow {
|
||||||
id: _switcher
|
id: _playerFlow
|
||||||
anchors.centerIn: parent
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
width: Math.min(_playerRow.implicitWidth, parent.width - 16)
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
height: 22
|
width: parent.width - 16
|
||||||
contentWidth: _playerRow.implicitWidth
|
spacing: 6
|
||||||
clip: true
|
|
||||||
|
|
||||||
Row {
|
Repeater {
|
||||||
id: _playerRow
|
model: root.players
|
||||||
height: 22
|
|
||||||
spacing: 6
|
|
||||||
|
|
||||||
Repeater {
|
delegate: Rectangle {
|
||||||
model: root.players
|
required property var modelData
|
||||||
|
required property int index
|
||||||
|
|
||||||
delegate: Rectangle {
|
readonly property bool _active: index === root.playerIdx
|
||||||
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 ? S.Theme.base02 : (pHover.hovered ? S.Theme.base02 : "transparent")
|
||||||
|
border.color: _active ? root.accentColor : S.Theme.base03
|
||||||
|
border.width: _active ? 1 : 0
|
||||||
|
|
||||||
width: _pLabel.implicitWidth + 12
|
Text {
|
||||||
height: 18
|
id: _pLabel
|
||||||
radius: 9
|
anchors.centerIn: parent
|
||||||
color: _active ? S.Theme.base02 : (pHover.hovered ? S.Theme.base02 : "transparent")
|
text: modelData.identity ?? "Player"
|
||||||
border.color: _active ? root.accentColor : S.Theme.base03
|
color: _active ? root.accentColor : S.Theme.base04
|
||||||
border.width: _active ? 1 : 0
|
font.pixelSize: S.Theme.fontSize - 2
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
font.family: S.Theme.fontFamily
|
||||||
|
font.bold: _active
|
||||||
|
}
|
||||||
|
|
||||||
Text {
|
HoverHandler {
|
||||||
id: _pLabel
|
id: pHover
|
||||||
anchors.centerIn: parent
|
cursorShape: Qt.PointingHandCursor
|
||||||
text: modelData.identity ?? "Player"
|
}
|
||||||
color: _active ? root.accentColor : S.Theme.base04
|
|
||||||
font.pixelSize: S.Theme.fontSize - 2
|
|
||||||
font.family: S.Theme.fontFamily
|
|
||||||
font.bold: _active
|
|
||||||
}
|
|
||||||
|
|
||||||
HoverHandler {
|
TapHandler {
|
||||||
id: pHover
|
onTapped: {
|
||||||
cursorShape: Qt.PointingHandCursor
|
root.playerSwitched(index);
|
||||||
}
|
|
||||||
|
|
||||||
TapHandler {
|
|
||||||
onTapped: {
|
|
||||||
root.playerSwitched(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
|
import QtQml.Models
|
||||||
import Quickshell.Services.Mpris
|
import Quickshell.Services.Mpris
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
|
|
@ -13,7 +14,6 @@ QtObject {
|
||||||
|
|
||||||
property string _selectedIdentity: ""
|
property string _selectedIdentity: ""
|
||||||
property var _lastPlayedTime: ({})
|
property var _lastPlayedTime: ({})
|
||||||
property var _watchers: []
|
|
||||||
|
|
||||||
onPlayerChanged: {
|
onPlayerChanged: {
|
||||||
if (player)
|
if (player)
|
||||||
|
|
@ -33,33 +33,18 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch raw Mpris.players for add/remove - this does NOT fire on state changes
|
// Watch all raw players for state changes via Instantiator -
|
||||||
property Connections _mprisConn: Connections {
|
// delegates persist across state changes since the model only
|
||||||
target: Mpris
|
// changes on player add/remove, not property changes
|
||||||
function onPlayersChanged() {
|
property Instantiator _stateWatchers: Instantiator {
|
||||||
root._reconnectWatchers();
|
model: Mpris.players
|
||||||
}
|
delegate: QtObject {
|
||||||
}
|
required property MprisPlayer modelData
|
||||||
|
property Connections _conn: Connections {
|
||||||
function _reconnectWatchers() {
|
target: modelData
|
||||||
for (const w of _watchers)
|
function onPlaybackStateChanged() {
|
||||||
w.destroy();
|
root._onPlaybackStateChanged(modelData);
|
||||||
|
}
|
||||||
const raw = Mpris.players.values ?? [];
|
|
||||||
const newWatchers = [];
|
|
||||||
for (const p of raw) {
|
|
||||||
const conn = _watcherComp.createObject(root, {
|
|
||||||
target: p
|
|
||||||
});
|
|
||||||
newWatchers.push(conn);
|
|
||||||
}
|
|
||||||
_watchers = newWatchers;
|
|
||||||
}
|
|
||||||
|
|
||||||
property Component _watcherComp: Component {
|
|
||||||
Connections {
|
|
||||||
function onPlaybackStateChanged() {
|
|
||||||
root._onPlaybackStateChanged(target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +69,6 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (p.playbackState === MprisPlaybackState.Paused && p === player) {
|
} else if (p.playbackState === MprisPlaybackState.Paused && p === player) {
|
||||||
// Current player paused - switch to a playing one if available
|
|
||||||
_switchToPlaying();
|
_switchToPlaying();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +123,4 @@ QtObject {
|
||||||
if (players[idx])
|
if (players[idx])
|
||||||
_selectedIdentity = players[idx].identity ?? "";
|
_selectedIdentity = players[idx].identity ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: _reconnectWatchers()
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue