mpris applet reads service directly, fix accent color gradient with pinned dock

This commit is contained in:
Damocles 2026-04-26 13:37:34 +02:00
parent 02910957f1
commit 200a844062
6 changed files with 31 additions and 63 deletions

View file

@ -1,19 +1,11 @@
import QtQuick
import Quickshell.Services.Mpris
import "../services" as S
Column {
id: root
required property var player
required property var players
required property bool playing
required property color accentColor
property string cachedArt: ""
property var cavaBars: Array(16).fill(0)
property int playerIdx: 0
signal playerSwitched(int idx)
// Album art - always 1:1, crossfades on session switch
Item {
@ -74,22 +66,23 @@ Column {
}
Connections {
target: root
target: S.MprisService
function onCachedArtChanged() {
if (!root.cachedArt) {
const art = S.MprisService.cachedArt;
if (!art) {
_artFadeIn.stop();
_prevFadeOut.stop();
_artImg._hasArt = false;
_artImg.opacity = 0;
_artImgPrev.opacity = 0;
_artImg.source = "";
} else if (root.cachedArt !== _artImg.source) {
} else if (art !== _artImg.source) {
_prevFadeOut.stop();
_artFadeIn.stop();
_artImgPrev.source = _artImg.source;
_artImgPrev.opacity = _artImg.opacity;
_artImg.opacity = 0;
_artImg.source = root.cachedArt;
_artImg.source = art;
}
}
}
@ -102,7 +95,7 @@ Column {
anchors.bottom: parent.bottom
height: parent.height * 0.6
spacing: 2
visible: root.playing
visible: S.MprisService.playing
opacity: 0.5
Repeater {
@ -168,7 +161,7 @@ Column {
Text {
width: parent.width
text: root.player?.trackTitle || "No track"
text: S.MprisService.player?.trackTitle || "No track"
color: S.Theme.base05
font.pixelSize: S.Theme.fontSize + 1
font.family: S.Theme.fontFamily
@ -179,7 +172,7 @@ Column {
Text {
width: parent.width
text: {
const p = root.player;
const p = S.MprisService.player;
if (!p)
return "";
const artist = Array.isArray(p.trackArtists) ? p.trackArtists.join(", ") : (p.trackArtists || "");
@ -199,8 +192,8 @@ Column {
width: root.width
height: 20
readonly property real pos: root.player?.position ?? 0
readonly property real dur: root.player?.length ?? 0
readonly property real pos: S.MprisService.player?.position ?? 0
readonly property real dur: S.MprisService.player?.length ?? 0
readonly property real frac: dur > 0 ? pos / dur : 0
function _fmtTime(ms) {
@ -259,7 +252,7 @@ Column {
Text {
text: "\uF048"
color: root.player?.canGoPrevious ? S.Theme.base05 : S.Theme.base03
color: S.MprisService.player?.canGoPrevious ? S.Theme.base05 : S.Theme.base03
font.pixelSize: S.Theme.fontSize + 4
font.family: S.Theme.iconFontFamily
anchors.verticalCenter: parent.verticalCenter
@ -267,13 +260,13 @@ Column {
cursorShape: Qt.PointingHandCursor
}
TapHandler {
enabled: root.player?.canGoPrevious ?? false
onTapped: root.player.previous()
enabled: S.MprisService.player?.canGoPrevious ?? false
onTapped: S.MprisService.player.previous()
}
}
Text {
text: root.playing ? "\uF04C" : "\uF04B"
text: S.MprisService.playing ? "\uF04C" : "\uF04B"
color: root.accentColor
font.pixelSize: S.Theme.fontSize + 8
font.family: S.Theme.iconFontFamily
@ -282,13 +275,13 @@ Column {
cursorShape: Qt.PointingHandCursor
}
TapHandler {
onTapped: root.player?.togglePlaying()
onTapped: S.MprisService.player?.togglePlaying()
}
}
Text {
text: "\uF051"
color: root.player?.canGoNext ? S.Theme.base05 : S.Theme.base03
color: S.MprisService.player?.canGoNext ? S.Theme.base05 : S.Theme.base03
font.pixelSize: S.Theme.fontSize + 4
font.family: S.Theme.iconFontFamily
anchors.verticalCenter: parent.verticalCenter
@ -296,8 +289,8 @@ Column {
cursorShape: Qt.PointingHandCursor
}
TapHandler {
enabled: root.player?.canGoNext ?? false
onTapped: root.player.next()
enabled: S.MprisService.player?.canGoNext ?? false
onTapped: S.MprisService.player.next()
}
}
}
@ -306,8 +299,8 @@ Column {
// Player switcher
Item {
width: root.width
height: root.players.length > 1 ? _playerFlow.implicitHeight + 6 : 0
visible: root.players.length > 1
height: S.MprisService.players.length > 1 ? _playerFlow.implicitHeight + 6 : 0
visible: S.MprisService.players.length > 1
Flow {
id: _playerFlow
@ -317,13 +310,13 @@ Column {
spacing: 6
Repeater {
model: root.players
model: S.MprisService.players
delegate: Rectangle {
required property var modelData
required property int index
readonly property bool _active: index === root.playerIdx
readonly property bool _active: index === S.MprisService.playerIdx
width: _pLabel.implicitWidth + 12
height: 18
@ -348,9 +341,7 @@ Column {
}
TapHandler {
onTapped: {
root.playerSwitched(index);
}
onTapped: S.MprisService.switchPlayer(index)
}
}
}