feat: print scheme command

Generates and prints a scheme for an image (or the current wallpaper if not given)
Also record use hevc codec
This commit is contained in:
2 * r + 2 * t
2025-05-05 13:36:01 +10:00
parent bb83c57308
commit 7fa09fa52f
4 changed files with 53 additions and 11 deletions
+11 -9
View File
@@ -45,34 +45,36 @@ complete -c caelestia -n $not_seen -a 'stop' -d 'Stop media'
# Toggles
set -l commands communication music specialws sysmon todo
complete -c caelestia -n "$seen toggle && not $seen $commands" -a "$commands"
complete -c caelestia -n "$seen toggle && not $seen $commands" -a "$commands" -d 'toggle'
# Workspace action
set -l commands workspace workspacegroup movetoworkspace movetoworkspacegroup
complete -c caelestia -n "$seen workspace-action && not $seen $commands" -a "$commands"
complete -c caelestia -n "$seen workspace-action && not $seen $commands" -a "$commands" -d 'action'
# Scheme
set -q XDG_DATA_HOME && set -l data_dir $XDG_DATA_HOME || set -l data_dir $HOME/.local/share
set -l scheme_dir $data_dir/caelestia/scripts/data/schemes
set -l commands (basename -a (find $scheme_dir/ -mindepth 1 -maxdepth 1 -type d))
complete -c caelestia -n "$seen scheme && not $seen $commands" -a "$commands"
for scheme in $commands
set -l schemes (basename -a (find $scheme_dir/ -mindepth 1 -maxdepth 1 -type d))
set -l commands 'print' $schemes
complete -c caelestia -n "$seen scheme && not $seen $commands" -a 'print' -d 'Generate and print a colour scheme for an image'
complete -c caelestia -n "$seen scheme && not $seen $commands" -a "$schemes" -d 'scheme'
for scheme in $schemes
set -l flavours (basename -a (find $scheme_dir/$scheme/ -mindepth 1 -maxdepth 1 -type d) 2> /dev/null)
set -l modes (basename -s .txt (find $scheme_dir/$scheme/ -mindepth 1 -maxdepth 1 -type f) 2> /dev/null)
if test -n "$modes"
complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $modes" -a "$modes"
complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $modes" -a "$modes" -d 'mode'
else
complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $flavours" -a "$flavours"
complete -c caelestia -n "$seen scheme && $seen $scheme && not $seen $flavours" -a "$flavours" -d 'flavour'
for flavour in $flavours
set -l modes (basename -s .txt (find $scheme_dir/$scheme/$flavour/ -mindepth 1 -maxdepth 1 -type f))
complete -c caelestia -n "$seen scheme && $seen $scheme && $seen $flavour && not $seen $modes" -a "$modes"
complete -c caelestia -n "$seen scheme && $seen $scheme && $seen $flavour && not $seen $modes" -a "$modes" -d 'mode'
end
end
end
# Variant
set -l commands vibrant tonalspot expressive fidelity fruitsalad rainbow neutral content monochrome
complete -c caelestia -n "$seen variant && not $seen $commands" -a "$commands"
complete -c caelestia -n "$seen variant && not $seen $commands" -a "$commands" -d 'variant'
# Record
set -l not_seen "$seen record && not $has_opt -s h help"
+4
View File
@@ -40,7 +40,11 @@ if test "$argv[1]" = workspace-action
end
if test "$argv[1]" = scheme
if test "$argv[2]" = print
$src/scheme/gen-print-scheme.fish $argv[3..]
else
$src/scheme/main.fish $argv[2..]
end
exit
end
+1 -1
View File
@@ -91,7 +91,7 @@ else
# No hardware accel
set -q _flag_n && set -l hwaccel --no-hw
wl-screenrec $region $audio $hwaccel -f $recording_path & disown
wl-screenrec $region $audio $hwaccel --codec hevc -f $recording_path & disown
notify-send 'Recording started' 'Recording...' -i 'video-x-generic' -a 'caelestia-record' -p > $notif_id_path
end
+36
View File
@@ -0,0 +1,36 @@
#!/bin/fish
set -l src (dirname (status filename))
. $src/../util.fish
test -f "$argv[1]" && set -l img (realpath "$argv[1]") || set -l img $C_STATE/wallpaper/thumbnail.jpg
# Thumbnail image if not already thumbnail
if test $img != $C_STATE/wallpaper/thumbnail.jpg
set -l thumb_path $C_CACHE/thumbnails/(sha1sum $img | cut -d ' ' -f 1).jpg
if ! test -f $thumb_path
magick -define jpeg:size=256x256 $img -thumbnail 128x128\> $thumb_path
end
set img $thumb_path
end
set -l variants vibrant tonalspot expressive fidelity fruitsalad rainbow neutral content monochrome
contains -- "$argv[2]" $variants && set -l variant $argv[2] || set -l variant (cat $C_STATE/scheme/current-variant.txt 2> /dev/null)
contains -- "$variant" $variants || set -l variant tonalspot
set -l hash (sha1sum $img | cut -d ' ' -f 1)
# Cache scheme
if ! test -d $C_CACHE/schemes/$hash/$variant
set -l colours ($src/score.py $img)
$src/autoadjust.py dark $variant $colours $C_CACHE/schemes/$hash
$src/autoadjust.py light $variant $colours $C_CACHE/schemes/$hash
end
# Get mode from image
set -l lightness (magick $img -format '%[fx:int(mean*100)]' info:)
test $lightness -ge 60 && set -l mode light || set -l mode dark
# Print scheme
cat $C_CACHE/schemes/$hash/$variant/default/$mode.txt