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

View file

@ -372,13 +372,7 @@ PanelWindow {
C.MprisApplet { C.MprisApplet {
width: parent.width width: parent.width
player: S.MprisService.player
players: S.MprisService.players
playing: S.MprisService.playing
accentColor: root._accent accentColor: root._accent
cachedArt: S.MprisService.cachedArt
playerIdx: S.MprisService.playerIdx
onPlayerSwitched: idx => S.MprisService.switchPlayer(idx)
} }
} }

View file

@ -78,13 +78,7 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 8 anchors.topMargin: 8
player: S.MprisService.player
players: S.MprisService.players
playing: S.MprisService.playing
playerIdx: S.MprisService.playerIdx
accentColor: S.Theme.base0D accentColor: S.Theme.base0D
cachedArt: S.MprisService.player?.trackArtUrl ?? ""
onPlayerSwitched: idx => S.MprisService.switchPlayer(idx)
} }
} }

View file

@ -15,7 +15,8 @@ Item {
if (!scr) if (!scr)
return 0.5; return 0.5;
const gx = mapToGlobal(width / 2, 0).x - scr.x; const gx = mapToGlobal(width / 2, 0).x - scr.x;
return Math.max(0, Math.min(1, gx / scr.width)); const effectiveWidth = scr.width - (S.DockState.reservedWidth ?? 0);
return Math.max(0, Math.min(1, gx / (effectiveWidth > 0 ? effectiveWidth : scr.width)));
} }
property color borderColor: Qt.rgba(S.Theme.base0C.r + (S.Theme.base09.r - S.Theme.base0C.r) * _posFrac, S.Theme.base0C.g + (S.Theme.base09.g - S.Theme.base0C.g) * _posFrac, S.Theme.base0C.b + (S.Theme.base09.b - S.Theme.base0C.b) * _posFrac, 1) property color borderColor: Qt.rgba(S.Theme.base0C.r + (S.Theme.base09.r - S.Theme.base0C.r) * _posFrac, S.Theme.base0C.g + (S.Theme.base09.g - S.Theme.base0C.g) * _posFrac, S.Theme.base0C.b + (S.Theme.base09.b - S.Theme.base0C.b) * _posFrac, 1)
property bool leftEdge: false property bool leftEdge: false

View file

@ -9,32 +9,20 @@ import "../applets" as C
M.BarModule { M.BarModule {
id: root id: root
spacing: S.Theme.moduleSpacing spacing: S.Theme.moduleSpacing
opacity: S.Modules.mpris.enable && player !== null ? 1 : 0 opacity: S.Modules.mpris.enable && S.MprisService.player !== null ? 1 : 0
visible: opacity > 0 visible: opacity > 0
tooltip: player ? (player.trackTitle || player.identity || "Media") + (playing ? " (playing)" : " (paused)") : "Media" tooltip: S.MprisService.player ? (S.MprisService.player.trackTitle || S.MprisService.player.identity || "Media") + (S.MprisService.playing ? " (playing)" : " (paused)") : "Media"
panelNamespace: "nova-mpris" panelNamespace: "nova-mpris"
panelTitle: "Now Playing" panelTitle: "Now Playing"
panelContentWidth: 280 panelContentWidth: 280
panelComponent: Component { panelComponent: Component {
C.MprisApplet { C.MprisApplet {
width: parent.width width: parent.width
player: root.player
players: root._players
playing: root.playing
accentColor: root.accentColor accentColor: root.accentColor
cachedArt: S.MprisService.cachedArt
cavaBars: root._cavaBars cavaBars: root._cavaBars
playerIdx: S.MprisService.playerIdx
onPlayerSwitched: idx => {
S.MprisService.switchPlayer(idx);
root.keepPanelOpen(400);
}
} }
} }
readonly property var _players: S.MprisService.players
readonly property MprisPlayer player: S.MprisService.player
readonly property bool playing: S.MprisService.playing
// Cava visualizer - 16 bars, raw output mode // Cava visualizer - 16 bars, raw output mode
property var _cavaBars: Array(16).fill(0) property var _cavaBars: Array(16).fill(0)
property bool _cavaActive: false property bool _cavaActive: false
@ -56,7 +44,7 @@ M.BarModule {
Process { Process {
id: cavaProc id: cavaProc
running: root.playing && root._cavaActive running: S.MprisService.playing && root._cavaActive
command: ["sh", "-c", "cfg=$(mktemp /tmp/nova-cava-XXXXXX.conf);" + "cat > \"$cfg\" << 'CAVAEOF'\n" + "[general]\nbars=16\nframerate=30\n[output]\nmethod=raw\nraw_target=/dev/stdout\ndata_format=ascii\nascii_max_range=100\n" + "CAVAEOF\n" + "trap 'rm -f \"$cfg\"' EXIT;" + "exec cava -p \"$cfg\""] command: ["sh", "-c", "cfg=$(mktemp /tmp/nova-cava-XXXXXX.conf);" + "cat > \"$cfg\" << 'CAVAEOF'\n" + "[general]\nbars=16\nframerate=30\n[output]\nmethod=raw\nraw_target=/dev/stdout\ndata_format=ascii\nascii_max_range=100\n" + "CAVAEOF\n" + "trap 'rm -f \"$cfg\"' EXIT;" + "exec cava -p \"$cfg\""]
stdout: SplitParser { stdout: SplitParser {
splitMarker: "\n" splitMarker: "\n"
@ -71,11 +59,11 @@ M.BarModule {
required property var bar required property var bar
M.BarIcon { M.BarIcon {
icon: root.playing ? "\uF04B" : (root.player?.playbackState === MprisPlaybackState.Paused ? "\uDB80\uDFE4" : "\uDB81\uDCDB") icon: S.MprisService.playing ? "\uF04B" : (S.MprisService.player?.playbackState === MprisPlaybackState.Paused ? "\uDB80\uDFE4" : "\uDB81\uDCDB")
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
M.BarLabel { M.BarLabel {
label: root.player?.trackTitle || root.player?.identity || "" label: S.MprisService.player?.trackTitle || S.MprisService.player?.identity || ""
elide: Text.ElideRight elide: Text.ElideRight
width: Math.min(implicitWidth, 200) width: Math.min(implicitWidth, 200)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View file

@ -8,7 +8,7 @@ shell/applets/CpuApplet.qml: Unqualified access [unqualified]
shell/applets/DiskApplet.qml: Unqualified access [unqualified] shell/applets/DiskApplet.qml: Unqualified access [unqualified]
shell/applets/MemoryApplet.qml: Unqualified access [unqualified] shell/applets/MemoryApplet.qml: Unqualified access [unqualified]
shell/applets/MprisApplet.qml: Member "frac" not found on type "QQuickItem" [missing-property] shell/applets/MprisApplet.qml: Member "frac" not found on type "QQuickItem" [missing-property]
shell/applets/MprisApplet.qml: Member "spacing" not found on type "Repeater" [missing-property] shell/applets/MprisApplet.qml: Member "join" not found on type "QString" [missing-property]
shell/applets/MprisApplet.qml: Unqualified access [unqualified] shell/applets/MprisApplet.qml: Unqualified access [unqualified]
shell/applets/NetworkApplet.qml: Unqualified access [unqualified] shell/applets/NetworkApplet.qml: Unqualified access [unqualified]
shell/applets/NotifApplet.qml: Member "_notif" not found on type "QQuickItem" [missing-property] shell/applets/NotifApplet.qml: Member "_notif" not found on type "QQuickItem" [missing-property]