From 92c7b0654cce1ade622c8675cb37e522d0f13acf Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 7 Mar 2025 23:44:21 +1100 Subject: scheme: allow choosing material scheme Also actually monochrome monochrome scheme --- completions/caelestia.fish | 3 ++- main.fish | 7 +++++++ scheme/autoadjust.py | 29 ++++++++++++++++++++++------- scheme/gen-scheme.fish | 11 ++++++++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/completions/caelestia.fish b/completions/caelestia.fish index b2a2916..2dc5675 100644 --- a/completions/caelestia.fish +++ b/completions/caelestia.fish @@ -1,6 +1,6 @@ set -l seen '__fish_seen_subcommand_from' set -l has_opt '__fish_contains_opt' -set -l commands help install shell toggle workspace-action scheme screenshot record clipboard clipboard-delete emoji-picker wallpaper pip +set -l commands help install shell toggle workspace-action scheme dynamic-scheme screenshot record clipboard clipboard-delete emoji-picker wallpaper pip set -l not_seen "not $seen $commands" # Disable file completions @@ -13,6 +13,7 @@ complete -c caelestia -n $not_seen -a 'shell' -d 'Start the shell or message it' complete -c caelestia -n $not_seen -a 'toggle' -d 'Toggle a special workspace' complete -c caelestia -n $not_seen -a 'workspace-action' -d 'Exec a dispatcher in the current group' complete -c caelestia -n $not_seen -a 'scheme' -d 'Switch the current colour scheme' +complete -c caelestia -n $not_seen -a 'dynamic-scheme' -d 'Change the dynamic colour scheme' complete -c caelestia -n $not_seen -a 'screenshot' -d 'Take a screenshot' complete -c caelestia -n $not_seen -a 'record' -d 'Take a screen recording' complete -c caelestia -n $not_seen -a 'clipboard' -d 'Open clipboard history' diff --git a/main.fish b/main.fish index bf27d6c..ee126c6 100755 --- a/main.fish +++ b/main.fish @@ -34,6 +34,12 @@ if test "$argv[1]" = scheme exit end +if test "$argv[1]" = dynamic-scheme + echo -n "$argv[2]" > $C_STATE/scheme/dynamic-scheme.txt + $src/wallpaper.fish -f $C_STATE/wallpaper/current + exit +end + if test "$argv[1]" = install set -l valid_modules scripts discord firefox fish foot fuzzel hypr safeeyes shell gtk vscode if test "$argv[2]" = all @@ -66,6 +72,7 @@ echo ' shell: start the shell or message it' echo ' toggle: toggle a special workspace' echo ' workspace-action: execute a Hyprland workspace dispatcher in the current group' echo ' scheme: change the current colour scheme' +echo ' dynamic-scheme: change the current dynamic material colour scheme' echo ' screenshot: take a screenshot' echo ' record: take a screen recording' echo ' clipboard: open clipboard history' diff --git a/scheme/autoadjust.py b/scheme/autoadjust.py index 03ca248..45b92d5 100755 --- a/scheme/autoadjust.py +++ b/scheme/autoadjust.py @@ -53,6 +53,8 @@ colour_names = [ "sapphire", "blue", "lavender", + "success", + "error" ] @@ -69,12 +71,18 @@ def rgb_to_hex(rgb: tuple[float, float, float]) -> str: def hex_to_hls(hex: str) -> tuple[float, float, float]: return rgb_to_hls(*hex_to_rgb(hex)) +def hls_to_hex(h: str, l: str, s: str) -> str: + return rgb_to_hex(hls_to_rgb(h, l, s)) + def adjust(hex: str, light: float = 0, sat: float = 0) -> str: h, l, s = hex_to_hls(hex) - l = max(0, min(1, l + light)) - s = max(0, min(1, s + sat)) - return rgb_to_hex(hls_to_rgb(h, l, s)) + return hls_to_hex(h, max(0, min(1, l + light)), max(0, min(1, s + sat))) + + +def grayscale(hex: str, light: bool) -> str: + h, l, s = hex_to_hls(hex) + return hls_to_hex(h, min(0.5, l) if light else max(0.5, l), 0) def distance(colour: str, base: str) -> float: @@ -124,21 +132,28 @@ def mix_colours(colours: list[str], base: list[str], amount: float) -> list[str] if __name__ == "__main__": light = sys.argv[1] == "light" + scheme = sys.argv[2] + colours_in = sys.argv[3] if scheme == "monochrome" else sys.argv[4] added_sat = 0.5 if light else 0.1 base = light_colours if light else dark_colours colours = [] - for colour in sys.argv[3].split(" "): + for colour in colours_in.split(" "): colours.append(adjust(colour, sat=added_sat)) # TODO: optional adjust colours = smart_sort(colours, base) # TODO: optional smart sort mix_colours(colours, base, 0) # TODO: customize mixing from config + # Success and error colours # TODO: customize mixing + colours.append(mix(colours[8], base[8], 0.9)) # Success (green) + colours.append(mix(colours[4], base[4], 0.9)) # Error (red) + + if scheme == "monochrome": + for i, colour in enumerate(colours): + colours[i] = grayscale(colour, light) + for i, colour in enumerate(colours): print(f"{colour_names[i]} {colour}") - # Success and error colours # TODO: customize mixing - print(f"success {mix(colours[8], base[8], 0.9)}") # Success (green) - print(f"error {mix(colours[4], base[4], 0.9)}") # Error (red) diff --git a/scheme/gen-scheme.fish b/scheme/gen-scheme.fish index ae807cb..7ac0d0e 100755 --- a/scheme/gen-scheme.fish +++ b/scheme/gen-scheme.fish @@ -7,10 +7,15 @@ set -l src (dirname (status filename)) test -f "$argv[1]" && set -l img "$argv[1]" || set -l img $C_STATE/wallpaper/current set -l img (realpath $img) contains -- "$argv[2]" light dark && set -l theme $argv[2] || set -l theme dark +test -n "$argv[3]" && set -l scheme $argv[3] || set -l scheme (cat $C_STATE/scheme/dynamic-scheme.txt 2> /dev/null || echo 'vibrant') # Generate colours -test $theme = light && set -l lightness 50 || set -l lightness 70 -$src/autoadjust.py $theme (okolors $img -k 14 -w 0 -l $lightness) +if test $scheme = 'monochrome' + $src/autoadjust.py $theme $scheme (okolors $img -k 14) +else + test $theme = light && set -l lightness 50 || set -l lightness 70 + $src/autoadjust.py $theme $scheme (okolors $img -k 14 -w 0 -l $lightness) +end # Generate layers and accents -$src/genmaterial.py $img $theme | head -c -1 # Trim trailing newline +$src/genmaterial.py $img $theme $scheme | head -c -1 # Trim trailing newline -- cgit v1.2.3-freya