From 5b6db69dd60ee1c0fe96e6bc2386aeefb121b31c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Thu, 29 May 2025 22:24:39 +0200 Subject: [PATCH] media controls: use quickshell's color quantizer --- .../modules/mediaControls/PlayerControl.qml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.config/quickshell/modules/mediaControls/PlayerControl.qml b/.config/quickshell/modules/mediaControls/PlayerControl.qml index ea8bd2348..f2cb59a33 100644 --- a/.config/quickshell/modules/mediaControls/PlayerControl.qml +++ b/.config/quickshell/modules/mediaControls/PlayerControl.qml @@ -23,7 +23,7 @@ Item { // Player instance property string artDownloadLocation: Directories.coverArt property string artFileName: Qt.md5(artUrl) + ".jpg" property string artFilePath: `${artDownloadLocation}/${artFileName}` - property color artDominantColor: Appearance.m3colors.m3secondaryContainer + property color artDominantColor: colorQuantizer?.colors[0] || Appearance.m3colors.m3secondaryContainer property bool downloaded: false implicitWidth: widgetWidth @@ -76,21 +76,15 @@ Item { // Player instance property string targetFile: playerController.artUrl command: [ "bash", "-c", `[ -f ${artFilePath} ] || curl -sSL '${targetFile}' -o '${artFilePath}'` ] onExited: (exitCode, exitStatus) => { - colorQuantizer.targetFile = playerController.artUrl // Yes this binding break is intentional - colorQuantizer.running = true playerController.downloaded = true } } - Process { // Average Color Runner + ColorQuantizer { id: colorQuantizer - property string targetFile: playerController.artUrl - command: [ "sh", "-c", `magick '${targetFile}' -scale 1x1\\! -format '%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]' info: | sed 's/,/\\n/g' | xargs -L 1 printf '%02x' ; echo` ] - stdout: SplitParser { - onRead: data => { - playerController.artDominantColor = "#" + data - } - } + source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : "" + depth: 0 // 2^0 = 1 color + rescaleSize: 1 // Rescale to 1x1 pixel for faster processing } property QtObject blendedColors: QtObject { @@ -137,7 +131,6 @@ Item { // Player instance Image { id: blurredArt anchors.fill: parent - visible: true source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : "" sourceSize.width: background.width sourceSize.height: background.height @@ -149,7 +142,6 @@ Item { // Player instance layer.enabled: true layer.effect: MultiEffect { source: blurredArt - anchors.fill: blurredArt saturation: 0.2 blurEnabled: true blurMax: 100