quickshell: split media cards per MPRIS source, add per-stream volume

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
rope 2026-06-17 11:43:45 +01:00
parent 6977568bf2
commit 2f51d2b4f1

View file

@ -2214,13 +2214,27 @@ in
return "thunderstorm"; return "thunderstorm";
} }
// --- Media: prefer the actively playing MPRIS player --- // --- Media: one card per MPRIS player so Spotify, a
property var player: { // browser tab, etc. stay separate instead of collapsing
let ps = Mpris.players.values; // into a single combined player. ---
for (let i = 0; i < ps.length; i++) { property var players: Mpris.players.values.filter(
if (ps[i].playbackState === MprisPlaybackState.Playing) return ps[i]; p => p.trackTitle || p.playbackState === MprisPlaybackState.Playing)
// Best-effort link from an MPRIS player to its Pipewire
// audio stream (matched by app name), so a card can carry a
// volume slider via the same per-app path as the volume
// widget. null when no stream matches.
function streamFor(player) {
if (!player) return null;
let id = (player.identity || "").toLowerCase();
let ns = Pipewire.nodes.values;
for (let i = 0; i < ns.length; i++) {
let n = ns[i];
if (!n.isStream || !n.audio) continue;
let an = (n.properties["application.name"] || "").toLowerCase();
if (an && (an === id || an.includes(id) || id.includes(an))) return n;
} }
return ps.length > 0 ? ps[0] : null; return null;
} }
Row { Row {
@ -2405,17 +2419,33 @@ in
width: 300 width: 300
spacing: 8 spacing: 8
// Media player card // Media player cards one per active MPRIS source,
// so Spotify and a browser tab stay separate.
Repeater {
model: calPopup.players
Rectangle { Rectangle {
id: mediaCard
required property var modelData
property var pwNode: calPopup.streamFor(modelData)
width: parent.width width: parent.width
height: 64 height: mediaCol.height + 16
radius: Theme.radius radius: Theme.radius
color: Theme.cardBg color: Theme.cardBg
visible: calPopup.player !== null
PwObjectTracker { objects: mediaCard.pwNode ? [mediaCard.pwNode] : [] }
Column {
id: mediaCol
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 8
spacing: 8
Row { Row {
anchors.fill: parent width: parent.width
anchors.margins: 8 height: 48
spacing: 10 spacing: 10
Rectangle { Rectangle {
@ -2435,7 +2465,7 @@ in
id: albumArt id: albumArt
anchors.fill: parent anchors.fill: parent
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
source: calPopup.player ? calPopup.player.trackArtUrl : "" source: mediaCard.modelData.trackArtUrl
} }
} }
@ -2445,7 +2475,7 @@ in
spacing: 2 spacing: 2
SText { SText {
width: parent.width width: parent.width
text: calPopup.player ? calPopup.player.trackTitle : "" text: mediaCard.modelData.trackTitle
color: Theme.base05 color: Theme.base05
font.pixelSize: 12 font.pixelSize: 12
font.weight: Font.Medium font.weight: Font.Medium
@ -2453,7 +2483,7 @@ in
} }
SText { SText {
width: parent.width width: parent.width
text: calPopup.player ? calPopup.player.trackArtist : "" text: mediaCard.modelData.trackArtist
color: Theme.base04 color: Theme.base04
font.pixelSize: 11 font.pixelSize: 11
elide: Text.ElideRight elide: Text.ElideRight
@ -2466,7 +2496,7 @@ in
Repeater { Repeater {
model: [ model: [
{ glyph: "skip_previous", act: "prev" }, { glyph: "skip_previous", act: "prev" },
{ glyph: calPopup.player && calPopup.player.playbackState === MprisPlaybackState.Playing ? "pause" : "play_arrow", act: "toggle" }, { glyph: mediaCard.modelData.playbackState === MprisPlaybackState.Playing ? "pause" : "play_arrow", act: "toggle" },
{ glyph: "skip_next", act: "next" } { glyph: "skip_next", act: "next" }
] ]
Rectangle { Rectangle {
@ -2487,7 +2517,7 @@ in
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
let p = calPopup.player; let p = mediaCard.modelData;
if (!p) return; if (!p) return;
if (mediaBtn.modelData.act === "prev") p.previous(); if (mediaBtn.modelData.act === "prev") p.previous();
else if (mediaBtn.modelData.act === "next") p.next(); else if (mediaBtn.modelData.act === "next") p.next();
@ -2498,6 +2528,44 @@ in
} }
} }
} }
// Per-source volume same per-app path
// as the volume widget. Shown when the
// player's Pipewire stream is matched.
Row {
width: parent.width
spacing: 8
visible: mediaCard.pwNode !== null && mediaCard.pwNode.audio !== null
SIcon {
anchors.verticalCenter: parent.verticalCenter
text: "volume_up"
color: Theme.base04
font.pixelSize: 15
}
PillSlider {
width: parent.width - 22 - mediaVolLabel.width - 16
anchors.verticalCenter: parent.verticalCenter
height: 16
trackH: 4
value: mediaCard.pwNode && mediaCard.pwNode.audio ? Math.min(1, mediaCard.pwNode.audio.volume) : 0
fillColor: Theme.base0C
onMoved: (v) => { if (mediaCard.pwNode && mediaCard.pwNode.audio) mediaCard.pwNode.audio.volume = v; }
}
SText {
id: mediaVolLabel
width: 36
text: mediaCard.pwNode && mediaCard.pwNode.audio ? Math.round(mediaCard.pwNode.audio.volume * 100) + "%" : "0%"
color: Theme.base04
font.pixelSize: 10
horizontalAlignment: Text.AlignRight
anchors.verticalCenter: parent.verticalCenter
}
}
}
}
} }
// Notifications card // Notifications card