feat: colorful multi-accent quickshell design system
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A8TNMgnEa7Kia5Wcz2kyDx
This commit is contained in:
1 parent
b8255db11a
commit
e818b1c1ea
23 files changed
+1073
-577
No files matched your search
@@ -1,19 +1,16 @@
|
||||
#!/usr/bin/env nu
|
||||
# Derives a Catppuccin flavor + accent from a wallpaper's average color and
|
||||
# applies it system-wide. No manual override - the wallpaper is the source of truth.
|
||||
# Derives a Catppuccin flavor + a trio of accents from a wallpaper's dominant
|
||||
# colors and applies it system-wide. No manual override - the wallpaper is
|
||||
# the source of truth. Colors are always Catppuccin swatches - we only ever
|
||||
# change *which* swatches get used, never introduce outside colors.
|
||||
|
||||
def palette [] {
|
||||
open ($"($env.HOME)/.dotfiles/config/themes/catppuccin/palette.json")
|
||||
}
|
||||
|
||||
def average-color [path: string] {
|
||||
let out = (magick $path -resize 1x1 txt:- | lines | skip 1 | first)
|
||||
let matches = ($out | parse --regex '\((?P<r>\d+),(?P<g>\d+),(?P<b>\d+)\)')
|
||||
if ($matches | is-empty) {
|
||||
error make { msg: $"could not read average color from ($path)" }
|
||||
}
|
||||
let m = ($matches | first)
|
||||
{ r: ($m.r | into int), g: ($m.g | into int), b: ($m.b | into int) }
|
||||
def hex-byte [] {
|
||||
# "into int -r 16" misreads byte pairs like "0b" as a binary literal prefix.
|
||||
$"0x($in)" | into int
|
||||
}
|
||||
|
||||
def rgb-to-hsl [rgb: record<r: int, g: int, b: int>] {
|
||||
@@ -45,49 +42,106 @@ def rgb-to-hsl [rgb: record<r: int, g: int, b: int>] {
|
||||
{ h: $h, s: $s, l: $l }
|
||||
}
|
||||
|
||||
def hex-byte [] {
|
||||
# "into int -r 16" misreads byte pairs like "0b" as a binary literal prefix.
|
||||
$"0x($in)" | into int
|
||||
}
|
||||
|
||||
def hue-dist [a: float, b: float] {
|
||||
let diff = (($a - $b) | math abs)
|
||||
[$diff, 360 - $diff] | math min
|
||||
}
|
||||
|
||||
# Wallpaper's dominant colors, ranked by pixel count (descending). Replaces
|
||||
# the old single 1x1-resize average-color sample, which always produced one
|
||||
# flat blend no matter how many distinct colors the wallpaper actually had.
|
||||
def dominant-colors [path: string, n: int] {
|
||||
let out = (magick $path -resize 100x100 -colors $n +dither -format %c histogram:info:-)
|
||||
$out
|
||||
| lines
|
||||
| parse --regex '(?P<count>\d+):.*#(?P<hex>[0-9A-Fa-f]{6})'
|
||||
| insert count_n { |row| $row.count | into int }
|
||||
| sort-by count_n --reverse
|
||||
| each { |row|
|
||||
let r = ($row.hex | str substring 0..1 | hex-byte)
|
||||
let g = ($row.hex | str substring 2..3 | hex-byte)
|
||||
let b = ($row.hex | str substring 4..5 | hex-byte)
|
||||
{ r: $r, g: $g, b: $b, hsl: (rgb-to-hsl { r: $r, g: $g, b: $b }) }
|
||||
}
|
||||
}
|
||||
|
||||
def accent-list [flavor: string] {
|
||||
let accents = (palette | get $flavor | get accents)
|
||||
$accents
|
||||
| columns
|
||||
| each {|name|
|
||||
let hex = ($accents | get $name)
|
||||
let r = ($hex | str substring 1..2 | hex-byte)
|
||||
let g = ($hex | str substring 3..4 | hex-byte)
|
||||
let b = ($hex | str substring 5..6 | hex-byte)
|
||||
{ name: $name, hsl: (rgb-to-hsl { r: $r, g: $g, b: $b }) }
|
||||
}
|
||||
}
|
||||
|
||||
def pick-flavor [rgb: record<r: int, g: int, b: int>] {
|
||||
let luma = (0.299 * $rgb.r + 0.587 * $rgb.g + 0.114 * $rgb.b) / 255
|
||||
if $luma < 0.5 { "mocha" } else { "latte" }
|
||||
}
|
||||
|
||||
def pick-accent [flavor: string, rgb: record<r: int, g: int, b: int>] {
|
||||
let wallpaper_hsl = (rgb-to-hsl $rgb)
|
||||
# Maps up to `want` of the wallpaper's dominant swatches onto distinct
|
||||
# Catppuccin accent swatches (at least `min_sep` degrees of hue apart), so
|
||||
# the shell gets a coherent multi-accent palette instead of one flat color.
|
||||
# Near-gray swatches (no meaningful hue) are skipped. If the wallpaper
|
||||
# doesn't carry enough distinct hues, remaining slots are filled from a
|
||||
# fixed, pleasant fallback order so the palette never collapses to
|
||||
# monochrome.
|
||||
def pick-accents [flavor: string, swatches: list, want: int, min_sep: float] {
|
||||
let accents = (accent-list $flavor)
|
||||
mut chosen_names = []
|
||||
mut chosen_hues = []
|
||||
|
||||
# Near-gray wallpapers don't carry a meaningful hue - fall back to mauve.
|
||||
if $wallpaper_hsl.s < 0.12 {
|
||||
return "mauve"
|
||||
for sw in $swatches {
|
||||
if ($chosen_names | length) >= $want { continue }
|
||||
if $sw.hsl.s < 0.12 { continue }
|
||||
|
||||
let names_snapshot = $chosen_names
|
||||
let hues_snapshot = $chosen_hues
|
||||
|
||||
let candidates = (
|
||||
$accents
|
||||
| where {|a| not ($names_snapshot | any {|c| $c == $a.name }) }
|
||||
| each {|a|
|
||||
let dists_to_chosen = ($hues_snapshot | each {|ch| hue-dist $a.hsl.h $ch })
|
||||
let min_dist_to_chosen = if ($dists_to_chosen | is-empty) { 999.0 } else { $dists_to_chosen | math min }
|
||||
{ name: $a.name, dist_to_swatch: (hue-dist $sw.hsl.h $a.hsl.h), min_dist_to_chosen: $min_dist_to_chosen }
|
||||
}
|
||||
| where min_dist_to_chosen >= $min_sep
|
||||
| sort-by dist_to_swatch
|
||||
)
|
||||
|
||||
if ($candidates | is-empty) { continue }
|
||||
let pick = ($candidates | first)
|
||||
$chosen_names = ($chosen_names | append $pick.name)
|
||||
$chosen_hues = ($chosen_hues | append (($accents | where name == $pick.name | first).hsl.h))
|
||||
}
|
||||
|
||||
let accents = (palette | get $flavor | get accents)
|
||||
$accents
|
||||
| columns
|
||||
| each {|name|
|
||||
let hex = ($accents | get $name)
|
||||
let r = ($hex | str substring 1..2 | hex-byte)
|
||||
let g = ($hex | str substring 3..4 | hex-byte)
|
||||
let b = ($hex | str substring 5..6 | hex-byte)
|
||||
let accent_hsl = (rgb-to-hsl { r: $r, g: $g, b: $b })
|
||||
{ name: $name, dist: (hue-dist $wallpaper_hsl.h $accent_hsl.h) }
|
||||
}
|
||||
| sort-by dist
|
||||
| first
|
||||
| get name
|
||||
let fallback_order = ["mauve" "sapphire" "peach" "green" "pink" "yellow" "teal" "blue" "flamingo"]
|
||||
for fb in $fallback_order {
|
||||
if ($chosen_names | length) >= $want { continue }
|
||||
if ($chosen_names | any {|c| $c == $fb }) { continue }
|
||||
$chosen_names = ($chosen_names | append $fb)
|
||||
}
|
||||
|
||||
$chosen_names
|
||||
}
|
||||
|
||||
def write-theme-colors [flavor: string, accent_name: string] {
|
||||
def container-tint [hex: string] {
|
||||
# accent-tinted, ~14% opacity - a soft fill for badges/containers
|
||||
$"#24($hex | str substring 1..)"
|
||||
}
|
||||
|
||||
def write-theme-colors [flavor: string, accent_names: list] {
|
||||
let p = (palette | get $flavor)
|
||||
let accent = ($p.accents | get $accent_name)
|
||||
let border = $"#1a($accent | str substring 1..)" # accent-tinted, ~10% opacity
|
||||
let primary = ($p.accents | get $accent_names.0)
|
||||
let secondary = ($p.accents | get $accent_names.1)
|
||||
let tertiary = ($p.accents | get $accent_names.2)
|
||||
let info = $p.accents.sapphire
|
||||
let border = $"#1a($primary | str substring 1..)" # accent-tinted, ~10% opacity
|
||||
|
||||
let colors = [
|
||||
$" property color background: \"#e6($p.crust | str substring 1..)\""
|
||||
@@ -95,15 +149,27 @@ def write-theme-colors [flavor: string, accent_name: string] {
|
||||
$" property color surfaceHover: \"#f2($p.surface0 | str substring 1..)\""
|
||||
$" property color overlay: \"#60($p.crust | str substring 1..)\""
|
||||
""
|
||||
$" property color primary: \"($accent)\""
|
||||
$" property color secondary: \"($p.accents.lavender)\""
|
||||
$" property color accent: \"($accent)\""
|
||||
$" property color primary: \"($primary)\""
|
||||
$" property color secondary: \"($secondary)\""
|
||||
$" property color tertiary: \"($tertiary)\""
|
||||
$" property color accent: \"($primary)\""
|
||||
""
|
||||
$" property color primaryContainer: \"(container-tint $primary)\""
|
||||
$" property color secondaryContainer: \"(container-tint $secondary)\""
|
||||
$" property color tertiaryContainer: \"(container-tint $tertiary)\""
|
||||
""
|
||||
$" property color alert: \"($p.red)\""
|
||||
$" property color alertContainer: \"(container-tint $p.red)\""
|
||||
$" property color success: \"($p.green)\""
|
||||
$" property color successContainer: \"(container-tint $p.green)\""
|
||||
$" property color warning: \"($p.yellow)\""
|
||||
$" property color warningContainer: \"(container-tint $p.yellow)\""
|
||||
$" property color info: \"($info)\""
|
||||
$" property color infoContainer: \"(container-tint $info)\""
|
||||
""
|
||||
$" property color text: \"($p.text)\""
|
||||
$" property color textMuted: \"($p.subtext0)\""
|
||||
$" property color textOnAccent: \"#e6($p.crust | str substring 1..)\""
|
||||
""
|
||||
$" property color border: \"($border)\""
|
||||
]
|
||||
@@ -177,10 +243,11 @@ def propagate [flavor: string] {
|
||||
}
|
||||
|
||||
def main [wallpaper_path: string] {
|
||||
let rgb = (average-color $wallpaper_path)
|
||||
let flavor = (pick-flavor $rgb)
|
||||
let accent = (pick-accent $flavor $rgb)
|
||||
let swatches = (dominant-colors $wallpaper_path 8)
|
||||
let top = ($swatches | first)
|
||||
let flavor = (pick-flavor { r: $top.r, g: $top.g, b: $top.b })
|
||||
let accent_names = (pick-accents $flavor $swatches 3 40.0)
|
||||
|
||||
write-theme-colors $flavor $accent
|
||||
write-theme-colors $flavor $accent_names
|
||||
propagate $flavor
|
||||
}
|
||||
Reference in new issue
Block a user