forked from Shinonome/dots-hyprland
media controls: use quickshell's color quantizer
This commit is contained in:
@@ -23,7 +23,7 @@ Item { // Player instance
|
|||||||
property string artDownloadLocation: Directories.coverArt
|
property string artDownloadLocation: Directories.coverArt
|
||||||
property string artFileName: Qt.md5(artUrl) + ".jpg"
|
property string artFileName: Qt.md5(artUrl) + ".jpg"
|
||||||
property string artFilePath: `${artDownloadLocation}/${artFileName}`
|
property string artFilePath: `${artDownloadLocation}/${artFileName}`
|
||||||
property color artDominantColor: Appearance.m3colors.m3secondaryContainer
|
property color artDominantColor: colorQuantizer?.colors[0] || Appearance.m3colors.m3secondaryContainer
|
||||||
property bool downloaded: false
|
property bool downloaded: false
|
||||||
|
|
||||||
implicitWidth: widgetWidth
|
implicitWidth: widgetWidth
|
||||||
@@ -76,21 +76,15 @@ Item { // Player instance
|
|||||||
property string targetFile: playerController.artUrl
|
property string targetFile: playerController.artUrl
|
||||||
command: [ "bash", "-c", `[ -f ${artFilePath} ] || curl -sSL '${targetFile}' -o '${artFilePath}'` ]
|
command: [ "bash", "-c", `[ -f ${artFilePath} ] || curl -sSL '${targetFile}' -o '${artFilePath}'` ]
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
colorQuantizer.targetFile = playerController.artUrl // Yes this binding break is intentional
|
|
||||||
colorQuantizer.running = true
|
|
||||||
playerController.downloaded = true
|
playerController.downloaded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Process { // Average Color Runner
|
ColorQuantizer {
|
||||||
id: colorQuantizer
|
id: colorQuantizer
|
||||||
property string targetFile: playerController.artUrl
|
source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : ""
|
||||||
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` ]
|
depth: 0 // 2^0 = 1 color
|
||||||
stdout: SplitParser {
|
rescaleSize: 1 // Rescale to 1x1 pixel for faster processing
|
||||||
onRead: data => {
|
|
||||||
playerController.artDominantColor = "#" + data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property QtObject blendedColors: QtObject {
|
property QtObject blendedColors: QtObject {
|
||||||
@@ -137,7 +131,6 @@ Item { // Player instance
|
|||||||
Image {
|
Image {
|
||||||
id: blurredArt
|
id: blurredArt
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: true
|
|
||||||
source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : ""
|
source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : ""
|
||||||
sourceSize.width: background.width
|
sourceSize.width: background.width
|
||||||
sourceSize.height: background.height
|
sourceSize.height: background.height
|
||||||
@@ -149,7 +142,6 @@ Item { // Player instance
|
|||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
layer.effect: MultiEffect {
|
layer.effect: MultiEffect {
|
||||||
source: blurredArt
|
source: blurredArt
|
||||||
anchors.fill: blurredArt
|
|
||||||
saturation: 0.2
|
saturation: 0.2
|
||||||
blurEnabled: true
|
blurEnabled: true
|
||||||
blurMax: 100
|
blurMax: 100
|
||||||
|
|||||||
Reference in New Issue
Block a user