Verified Commit ad177571 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

desktoppackage: use `dominant` color instead of `highlight` color

Only fallback to highlight color if the dominant color is too light or
too dark.
parent e1d0084d
Pipeline #186715 passed with stage
in 2 minutes and 45 seconds
......@@ -276,6 +276,45 @@ Item {
Binding {
target: desktop
property: "accentColor"
value: wallpaperColors.highlight
value: {
if (isCandidateColor(wallpaperColors.dominant)) {
return wallpaperColors.dominant;
}
// If the color is too light or too dark, use highlight instead
if (isCandidateColor(wallpaperColors.highlight)) {
return wallpaperColors.highlight
}
// Neither is suitable, check average color.
if (isCandidateColor(wallpaperColors.average)) {
return wallpaperColors.average;
}
// Adjust the lightness of the average color
if (lightness(wallpaperColors.average) >= 0.8) {
return Qt.darker(wallpaperColors.average, 1.25);
} else {
return Qt.lighter(wallpaperColors.average, 1.25);
}
}
/**
* Converts RGB color to HSL, and only returns the lightness value (0-1)
*/
function lightness(color) {
const r = color.r, g = color.g, b = color.b;
const l = Math.max(r, g, b);
const s = l - Math.min(r, g, b);
return (2 * l - s) / 2;
}
/**
* Checks the color is suitable as an accent color
*/
function isCandidateColor(color) {
const l = lightness(color);
return l > 0.2 && l < 0.8;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment