add now playing info
This commit is contained in:
43
quickshell/services/NowPlayingService.qml
Normal file
43
quickshell/services/NowPlayingService.qml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import Quickshell.Io
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string artist: ""
|
||||||
|
property string title: ""
|
||||||
|
property string artUrl: ""
|
||||||
|
property bool isPlaying: false
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: playerctlProc
|
||||||
|
// we need a separator, so use |||
|
||||||
|
command: ["playerctl", "metadata", "--format", "{{artist}}|||{{title}}|||{{mpris:artUrl}}|||{{status}}"]
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
var text = this.text.trim();
|
||||||
|
if (!text) {
|
||||||
|
root.artist = "";
|
||||||
|
root.title = "";
|
||||||
|
root.artUrl = "";
|
||||||
|
root.isPlaying = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var parts = text.split("|||");
|
||||||
|
root.artist = parts[0] || "";
|
||||||
|
root.title = parts[1] || "";
|
||||||
|
root.artUrl = parts[2] || "";
|
||||||
|
root.isPlaying = (parts[3] || "").trim() === "Playing";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 2000
|
||||||
|
running: true
|
||||||
|
repeat: true
|
||||||
|
onTriggered: playerctlProc.running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: playerctlProc.running = true
|
||||||
|
}
|
||||||
@@ -18,6 +18,10 @@ ShellRoot {
|
|||||||
id: stats
|
id: stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NowPlayingService {
|
||||||
|
id: nowPlayingService
|
||||||
|
}
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
model: Quickshell.screens
|
model: Quickshell.screens
|
||||||
|
|
||||||
@@ -49,6 +53,9 @@ ShellRoot {
|
|||||||
cpuUsage: stats.cpuUsage
|
cpuUsage: stats.cpuUsage
|
||||||
memUsage: stats.memUsage
|
memUsage: stats.memUsage
|
||||||
gpuUsage: stats.gpuUsage
|
gpuUsage: stats.gpuUsage
|
||||||
|
nowPlayingArtist: nowPlayingService.artist
|
||||||
|
nowPlayingTitle: nowPlayingService.title
|
||||||
|
nowPlayingArtUrl: nowPlayingService.artUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
quickshell/ui/NowPlaying.qml
Normal file
33
quickshell/ui/NowPlaying.qml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Layouts
|
||||||
|
|
||||||
|
import "../constants"
|
||||||
|
|
||||||
|
Row {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string artist: ""
|
||||||
|
property string title: ""
|
||||||
|
property string artUrl: ""
|
||||||
|
|
||||||
|
visible: title !== ""
|
||||||
|
spacing: 6
|
||||||
|
|
||||||
|
Image {
|
||||||
|
width: 18
|
||||||
|
height: 18
|
||||||
|
source: root.artUrl
|
||||||
|
fillMode: Image.PreserveAspectCrop
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: root.artist !== "" ? (root.artist + " - " + root.title) : root.title
|
||||||
|
color: Colors.md3.primary
|
||||||
|
font.family: Constants.fontFamily
|
||||||
|
font.pixelSize: Constants.fontSize
|
||||||
|
elide: Text.ElideRight
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,9 @@ Item {
|
|||||||
property int cpuUsage: 0
|
property int cpuUsage: 0
|
||||||
property int memUsage: 0
|
property int memUsage: 0
|
||||||
property int gpuUsage: 0
|
property int gpuUsage: 0
|
||||||
|
property string nowPlayingArtist: ""
|
||||||
|
property string nowPlayingTitle: ""
|
||||||
|
property string nowPlayingArtUrl: ""
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -32,12 +35,22 @@ Item {
|
|||||||
id: workspacesList
|
id: workspacesList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// small spacer
|
||||||
|
Item {
|
||||||
|
anchors.leftMargin: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
NowPlaying {
|
||||||
|
artist: root.nowPlayingArtist
|
||||||
|
title: root.nowPlayingTitle
|
||||||
|
artUrl: root.nowPlayingArtUrl
|
||||||
|
}
|
||||||
|
|
||||||
// Spacer
|
// Spacer
|
||||||
Item {
|
Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =====================
|
// =====================
|
||||||
// RIGHT: System info
|
// RIGHT: System info
|
||||||
// =====================
|
// =====================
|
||||||
|
|||||||
Reference in New Issue
Block a user