From d66f4ca0f37d585a86145c0a27e79e89c3a815c8 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 31 Aug 2025 14:34:22 +1000 Subject: plugin/cutils: add getAverageLuminance Fixes stutters in wallpaper list Also fix crash when saveItem target doesn't have a window --- services/Colours.qml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'services') diff --git a/services/Colours.qml b/services/Colours.qml index 8470cfa..ca78abc 100644 --- a/services/Colours.qml +++ b/services/Colours.qml @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound import qs.config import qs.utils +import Caelestia import Quickshell import Quickshell.Io import QtQuick @@ -21,7 +22,7 @@ Singleton { readonly property M3Palette current: M3Palette {} readonly property M3Palette preview: M3Palette {} readonly property Transparency transparency: Transparency {} - readonly property color wallColour: quantizer.colors[0] ?? "black" + property real wallLuminance function getLuminance(c: color): real { if (c.r == 0 && c.g == 0 && c.b == 0) @@ -30,7 +31,6 @@ Singleton { } function alterColour(c: color, a: real, layer: int): color { - const wallLuminance = getLuminance(wallColour); const luminance = getLuminance(c); const offset = (!light || layer == 1 ? 1 : -layer / 2) * (light ? 0.2 : 0.3) * (1 - transparency.base) * (1 + wallLuminance * (light ? (layer == 1 ? 3 : 1) : 2.5)); @@ -85,12 +85,16 @@ Singleton { onLoaded: root.load(text(), false) } - ColorQuantizer { - id: quantizer + Connections { + target: Wallpapers - source: Qt.resolvedUrl(Wallpapers.current) - depth: 0 - rescaleSize: 128 + function onCurrentChanged(): void { + const current = Wallpapers.current; + CUtils.getAverageLuminance(current, l => { + if (Wallpapers.current == current) + root.wallLuminance = l; + }); + } } component Transparency: QtObject { -- cgit v1.2.3-freya