feat: wallpaper-driven theming + native wallpaper picker
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ZYoSQwwYWhJHLX6VBCGnF
This commit is contained in:
1 parent
0537615b96
commit
ace2860e7a
22 files changed
+594
-285
No files matched your search
@@ -1,122 +0,0 @@
|
||||
#!/usr/bin/env nu
|
||||
|
||||
def apply-theme [selected: string] {
|
||||
let choice = if $selected == "auto" {
|
||||
let mode = (try { darkman get | str trim } catch { "" })
|
||||
if $mode == "dark" {
|
||||
"mocha"
|
||||
} else if $mode == "light" {
|
||||
"latte"
|
||||
} else {
|
||||
let color_scheme = (bash -lc "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null || true" | str trim)
|
||||
|
||||
if ($color_scheme | str contains "prefer-dark") {
|
||||
"mocha"
|
||||
} else if ($color_scheme | str contains "prefer-light") {
|
||||
"latte"
|
||||
} else {
|
||||
let hour = (date now | format date "%H" | into int)
|
||||
if ($hour >= 19 or $hour < 7) { "mocha" } else { "latte" }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$selected
|
||||
}
|
||||
|
||||
let wanted_darkman = if $choice == "mocha" { "dark" } else { "light" }
|
||||
let current_darkman = (try { darkman get | str trim } catch { "" })
|
||||
if $current_darkman != "" and $current_darkman != $wanted_darkman {
|
||||
try {
|
||||
bash -c $"darkman set ($wanted_darkman) &"
|
||||
} catch {}
|
||||
}
|
||||
|
||||
let home = $env.HOME
|
||||
let base = $"($home)/.config/themes/catppuccin/($choice)"
|
||||
|
||||
if not ($base | path exists) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
let gtk_theme = (open $"($base)/gtk-theme-name" | str trim)
|
||||
|
||||
$choice | save -f $"($home)/.config/current-theme"
|
||||
|
||||
# Hypr palette. Configs must source ~/.config/hypr/theme.conf to use this.
|
||||
ln -sfn $"($base)/hypr.conf" $"($home)/.config/hypr/theme.conf"
|
||||
|
||||
# Quickshell singleton theme.
|
||||
cp -f $"($base)/quickshell/Theme.qml" $"($home)/.config/quickshell/Theme/Theme.qml"
|
||||
|
||||
# Wofi colors.
|
||||
if ($"($home)/.config/wofi" | path exists) {
|
||||
ln -sfn $"($base)/wofi.css" $"($home)/.config/wofi/style.css"
|
||||
}
|
||||
|
||||
# Mako colors, only if mako config dir exists.
|
||||
if ($"($home)/.config/mako" | path exists) {
|
||||
ln -sfn $"($base)/mako.conf" $"($home)/.config/mako/config"
|
||||
if (which makoctl | is-not-empty) { makoctl reload }
|
||||
}
|
||||
|
||||
# Btop theme
|
||||
if ($"($home)/.config/btop/btop.conf" | path exists) {
|
||||
bash -lc $"sed -i 's|color_theme = \".*\"|color_theme = \"($home)/.config/btop/themes/catppuccin_($choice).theme\"|' \"($home)/.config/btop/btop.conf\""
|
||||
if ($"($home)/.local/share/chezmoi/dot_config/btop/btop.conf" | path exists) {
|
||||
bash -lc $"sed -i 's|color_theme = \".*\"|color_theme = \"($home)/.config/btop/themes/catppuccin_($choice).theme\"|' \"($home)/.local/share/chezmoi/dot_config/btop/btop.conf\""
|
||||
}
|
||||
}
|
||||
|
||||
# Helix theme
|
||||
if ($"($home)/.config/helix/config.toml" | path exists) {
|
||||
bash -lc $"sed -i 's/theme = \"catppuccin_.*_transparent\"/theme = \"catppuccin_($choice)_transparent\"/' \"($home)/.config/helix/config.toml\""
|
||||
if ($"($home)/.local/share/chezmoi/dot_config/helix/config.toml" | path exists) {
|
||||
bash -lc $"sed -i 's/theme = \"catppuccin_.*_transparent\"/theme = \"catppuccin_($choice)_transparent\"/' \"($home)/.local/share/chezmoi/dot_config/helix/config.toml\""
|
||||
}
|
||||
}
|
||||
|
||||
# Yazi theme
|
||||
if ($"($home)/.config/yazi" | path exists) {
|
||||
$"[flavor]\nuse = \"catppuccin-($choice)\"\n" | save -f $"($home)/.config/yazi/theme.toml"
|
||||
}
|
||||
|
||||
# GTK theme, only if installed.
|
||||
try {
|
||||
bash -lc $"gsettings set org.gnome.desktop.interface gtk-theme ($gtk_theme)"
|
||||
let color_scheme = if $choice == "mocha" { "prefer-dark" } else { "prefer-light" }
|
||||
bash -lc $"gsettings set org.gnome.desktop.interface color-scheme ($color_scheme)"
|
||||
|
||||
try {
|
||||
mkdir $"($home)/.config/gtk-3.0"
|
||||
} catch {}
|
||||
let prefer_dark = if $choice == "mocha" { "1" } else { "0" }
|
||||
$"[Settings]\ngtk-theme-name=($gtk_theme)\ngtk-application-prefer-dark-theme=($prefer_dark)\n" | save -f $"($home)/.config/gtk-3.0/settings.ini"
|
||||
} catch {
|
||||
}
|
||||
|
||||
hyprctl reload
|
||||
bash -lc "pkill quickshell 2>/dev/null; setsid quickshell >/tmp/quickshell-theme-switch.log 2>&1 < /dev/null &"
|
||||
}
|
||||
|
||||
def main [
|
||||
mode?: string
|
||||
--auto
|
||||
--mocha
|
||||
--latte
|
||||
] {
|
||||
let valid = ["auto" "mocha" "latte"]
|
||||
let selected = if $auto {
|
||||
"auto"
|
||||
} else if $mocha {
|
||||
"mocha"
|
||||
} else if $latte {
|
||||
"latte"
|
||||
} else if $mode == null {
|
||||
($valid | str join "\n" | wofi --dmenu --prompt "Theme")
|
||||
} else {
|
||||
$mode
|
||||
}
|
||||
|
||||
if ($selected not-in $valid) { exit }
|
||||
apply-theme $selected
|
||||
}
|
||||
@@ -4,8 +4,8 @@ const image_exts = ["jpg" "jpeg" "png" "webp"]
|
||||
|
||||
def wallpaper-dirs [] {
|
||||
[
|
||||
($"($env.HOME)/Nextcloud/Wallpaper")
|
||||
($"($env.HOME)/Nextcloud/Wallpaper_32x9")
|
||||
($"($env.HOME)/ownCloud/Personal/Wallpaper")
|
||||
($"($env.HOME)/ownCloud/Personal/Wallpaper_32x9")
|
||||
] | where {|dir| $dir | path exists }
|
||||
}
|
||||
|
||||
@@ -14,39 +14,63 @@ def list-wallpapers [] {
|
||||
| each {|dir| ls $dir }
|
||||
| flatten
|
||||
| where type == file
|
||||
| where {|file| (($file.name | path parse | get extension | str downcase) in $image_exts) }
|
||||
| where {|file| (($file.name | path parse | get extension | str lowercase) in $image_exts) }
|
||||
| sort-by name
|
||||
}
|
||||
|
||||
const thumb_size = "480x640"
|
||||
|
||||
def thumbnail-dir [] {
|
||||
let dir = $"($env.HOME)/.cache/quickshell-wallpaper-thumbs"
|
||||
mkdir $dir
|
||||
$dir
|
||||
}
|
||||
|
||||
def thumbnail-path [src: string] {
|
||||
let hash = ($src | hash sha256 | str substring 0..24)
|
||||
$"(thumbnail-dir)/($hash).jpg"
|
||||
}
|
||||
|
||||
# Pre-rendered small JPEG cached in ~/.cache, so the picker never has to
|
||||
# decode a multi-megapixel wallpaper just to show a thumbnail.
|
||||
def ensure-thumbnail [src: string] {
|
||||
let thumb = (thumbnail-path $src)
|
||||
if not ($thumb | path exists) {
|
||||
try {
|
||||
magick $src -auto-orient -thumbnail $"($thumb_size)^" -gravity center -extent $thumb_size -quality 85 $thumb
|
||||
} catch {}
|
||||
}
|
||||
$thumb
|
||||
}
|
||||
|
||||
def list-wallpapers-with-thumbs [] {
|
||||
list-wallpapers | get name | par-each {|f| { path: $f, thumb: (ensure-thumbnail $f) } }
|
||||
}
|
||||
|
||||
def set-wallpaper [path: string] {
|
||||
if not ($path | path exists) {
|
||||
notify-send "Wallpaper not found" $path
|
||||
try { notify-send "Wallpaper not found" $path }
|
||||
exit 1
|
||||
}
|
||||
|
||||
awww img $path --transition-type grow --transition-duration 1
|
||||
try { awww img $path --transition-type grow --transition-duration 1 }
|
||||
$path | save -f $"($env.HOME)/.config/current-wallpaper"
|
||||
notify-send "Wallpaper applied" ($path | path basename)
|
||||
}
|
||||
|
||||
def choose-wallpaper [] {
|
||||
let files = (list-wallpapers)
|
||||
if ($files | is-empty) {
|
||||
notify-send "No wallpapers found" "~/Nextcloud/Wallpaper or ~/Nextcloud/Wallpaper_32x9"
|
||||
exit 1
|
||||
# An unhandled external-command failure aborts the rest of a nu script, so
|
||||
# this must not depend on awww/notify-send succeeding above.
|
||||
try {
|
||||
bash -lc $"nu ~/.dotfiles/config/nushell/scripts/wallpaper-theme.nu \"($path)\""
|
||||
} catch {|e|
|
||||
try { notify-send "Theme update failed" $e.msg }
|
||||
}
|
||||
|
||||
let choice = ($files | get name | path basename | str join "\n" | wofi --dmenu --prompt "Wallpaper")
|
||||
if ($choice == "") { exit }
|
||||
|
||||
let selected = ($files | where {|file| ($file.name | path basename) == $choice } | get name | first)
|
||||
set-wallpaper $selected
|
||||
try { notify-send "Wallpaper applied" ($path | path basename) }
|
||||
}
|
||||
|
||||
def random-wallpaper [] {
|
||||
let files = (list-wallpapers)
|
||||
if ($files | is-empty) {
|
||||
notify-send "No wallpapers found" "~/Nextcloud/Wallpaper or ~/Nextcloud/Wallpaper_32x9"
|
||||
notify-send "No wallpapers found" "~/ownCloud/Personal/Wallpaper or ~/ownCloud/Personal/Wallpaper_32x9"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -56,18 +80,23 @@ def random-wallpaper [] {
|
||||
|
||||
def current-wallpaper [] {
|
||||
let file = $"($env.HOME)/.config/current-wallpaper"
|
||||
if ($file | path exists) { open $file | str trim }
|
||||
if ($file | path exists) { open $file | str trim } else { "" }
|
||||
}
|
||||
|
||||
def main [
|
||||
path?: string
|
||||
--menu
|
||||
--random
|
||||
--set: string
|
||||
--current
|
||||
--list
|
||||
--list-with-current
|
||||
] {
|
||||
if $list {
|
||||
if $list_with_current {
|
||||
{
|
||||
wallpapers: (list-wallpapers-with-thumbs),
|
||||
current: (current-wallpaper)
|
||||
} | to json --raw
|
||||
} else if $list {
|
||||
list-wallpapers | get name | to json --raw
|
||||
} else if $current {
|
||||
current-wallpaper
|
||||
@@ -78,6 +107,6 @@ def main [
|
||||
} else if $path != null {
|
||||
set-wallpaper $path
|
||||
} else {
|
||||
choose-wallpaper
|
||||
notify-send "Wallpaper picker" "Use the mod+W wallpaper carousel instead"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#!/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.
|
||||
|
||||
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 rgb-to-hsl [rgb: record<r: int, g: int, b: int>] {
|
||||
let r = $rgb.r / 255
|
||||
let g = $rgb.g / 255
|
||||
let b = $rgb.b / 255
|
||||
let max = ([$r $g $b] | math max)
|
||||
let min = ([$r $g $b] | math min)
|
||||
let l = ($max + $min) / 2
|
||||
let delta = $max - $min
|
||||
|
||||
let s = if $delta == 0 {
|
||||
0
|
||||
} else {
|
||||
$delta / (1 - (($l * 2 - 1) | math abs))
|
||||
}
|
||||
|
||||
let h = if $delta == 0 {
|
||||
0
|
||||
} else if $max == $r {
|
||||
(60 * ((($g - $b) / $delta) mod 6))
|
||||
} else if $max == $g {
|
||||
(60 * ((($b - $r) / $delta) + 2))
|
||||
} else {
|
||||
(60 * ((($r - $g) / $delta) + 4))
|
||||
}
|
||||
let h = if $h < 0 { $h + 360 } else { $h }
|
||||
|
||||
{ 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
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
# Near-gray wallpapers don't carry a meaningful hue - fall back to mauve.
|
||||
if $wallpaper_hsl.s < 0.12 {
|
||||
return "mauve"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
def write-theme-colors [flavor: string, accent_name: string] {
|
||||
let p = (palette | get $flavor)
|
||||
let accent = ($p.accents | get $accent_name)
|
||||
let border = $"#1a($accent | str substring 1..)" # accent-tinted, ~10% opacity
|
||||
|
||||
let colors = [
|
||||
$" property color background: \"#e6($p.crust | str substring 1..)\""
|
||||
$" property color surface: \"#cc($p.mantle | str substring 1..)\""
|
||||
$" 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 alert: \"($p.red)\""
|
||||
$" property color success: \"($p.green)\""
|
||||
$" property color warning: \"($p.yellow)\""
|
||||
""
|
||||
$" property color text: \"($p.text)\""
|
||||
$" property color textMuted: \"($p.subtext0)\""
|
||||
""
|
||||
$" property color border: \"($border)\""
|
||||
]
|
||||
|
||||
let theme_path = $"($env.HOME)/.config/quickshell/components/Shared/Theme.qml"
|
||||
let lines = (open --raw $theme_path | lines)
|
||||
let begin = ($lines | enumerate | where item == " // GENERATED:COLORS:BEGIN" | get index.0)
|
||||
let end = ($lines | enumerate | where item == " // GENERATED:COLORS:END" | get index.0)
|
||||
|
||||
let new_lines = (
|
||||
($lines | take ($begin + 1))
|
||||
++ [" property QtObject colors: QtObject {"]
|
||||
++ $colors
|
||||
++ [" }"]
|
||||
++ ($lines | skip $end)
|
||||
)
|
||||
|
||||
($new_lines | str join "\n") + "\n" | save -f $theme_path
|
||||
}
|
||||
|
||||
def propagate [flavor: string] {
|
||||
let home = $env.HOME
|
||||
let base = $"($home)/.config/themes/catppuccin/($flavor)"
|
||||
let gtk_theme = (open $"($base)/gtk-theme-name" | str trim)
|
||||
|
||||
$flavor | save -f $"($home)/.config/current-theme"
|
||||
|
||||
let wanted_darkman = if $flavor == "mocha" { "dark" } else { "light" }
|
||||
let current_darkman = (try { darkman get | str trim } catch { "" })
|
||||
if $current_darkman != "" and $current_darkman != $wanted_darkman {
|
||||
try { bash -c $"darkman set ($wanted_darkman) &" } catch {}
|
||||
}
|
||||
|
||||
# Hypr palette. Configs must source ~/.config/hypr/theme.conf to use this.
|
||||
ln -sfn $"($base)/hypr.conf" $"($home)/.config/hypr/theme.conf"
|
||||
|
||||
# Mako colors, only if mako config dir exists.
|
||||
if ($"($home)/.config/mako" | path exists) {
|
||||
ln -sfn $"($base)/mako.conf" $"($home)/.config/mako/config"
|
||||
if (which makoctl | is-not-empty) { makoctl reload }
|
||||
}
|
||||
|
||||
# Btop theme
|
||||
if ($"($home)/.config/btop/btop.conf" | path exists) {
|
||||
bash -lc $"sed -i 's|color_theme = \".*\"|color_theme = \"($home)/.config/btop/themes/catppuccin_($flavor).theme\"|' \"($home)/.config/btop/btop.conf\""
|
||||
}
|
||||
|
||||
# Helix theme
|
||||
if ($"($home)/.config/helix/config.toml" | path exists) {
|
||||
bash -lc $"sed -i 's/theme = \"catppuccin_.*_transparent\"/theme = \"catppuccin_($flavor)_transparent\"/' \"($home)/.config/helix/config.toml\""
|
||||
}
|
||||
|
||||
# Yazi theme
|
||||
if ($"($home)/.config/yazi" | path exists) {
|
||||
$"[flavor]\nuse = \"catppuccin-($flavor)\"\n" | save -f $"($home)/.config/yazi/theme.toml"
|
||||
}
|
||||
|
||||
# GTK theme, only if installed.
|
||||
try {
|
||||
bash -lc $"gsettings set org.gnome.desktop.interface gtk-theme ($gtk_theme)"
|
||||
let color_scheme = if $flavor == "mocha" { "prefer-dark" } else { "prefer-light" }
|
||||
bash -lc $"gsettings set org.gnome.desktop.interface color-scheme ($color_scheme)"
|
||||
|
||||
try { mkdir $"($home)/.config/gtk-3.0" } catch {}
|
||||
let prefer_dark = if $flavor == "mocha" { "1" } else { "0" }
|
||||
$"[Settings]\ngtk-theme-name=($gtk_theme)\ngtk-application-prefer-dark-theme=($prefer_dark)\n" | save -f $"($home)/.config/gtk-3.0/settings.ini"
|
||||
} catch {}
|
||||
|
||||
hyprctl reload
|
||||
bash -lc "pkill quickshell 2>/dev/null; setsid quickshell >/tmp/quickshell-theme.log 2>&1 < /dev/null &"
|
||||
}
|
||||
|
||||
def main [wallpaper_path: string] {
|
||||
let rgb = (average-color $wallpaper_path)
|
||||
let flavor = (pick-flavor $rgb)
|
||||
let accent = (pick-accent $flavor $rgb)
|
||||
|
||||
write-theme-colors $flavor $accent
|
||||
propagate $flavor
|
||||
}
|
||||
Reference in new issue
Block a user