From d44bde166782928db85242e86df6190e9bcfa92a Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 20:37:37 +1000 Subject: feat: theme hypr and terminals --- src/caelestia/utils/theme.py | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/caelestia/utils/theme.py (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py new file mode 100644 index 0000000..7774472 --- /dev/null +++ b/src/caelestia/utils/theme.py @@ -0,0 +1,86 @@ +import json +import subprocess +from pathlib import Path + +from caelestia.utils.paths import config_dir + + +def gen_conf(colours: dict[str, str]) -> str: + conf = "" + for name, colour in colours.items(): + conf += f"${name} = {colour}\n" + return conf + + +def gen_scss(colours: dict[str, str]) -> str: + scss = "" + for name, colour in colours.items(): + scss += f"${name}: {colour};\n" + return scss + + +def c2s(c: str, *i: list[int]) -> str: + """Hex to ANSI sequence (e.g. ffffff, 11 -> \x1b]11;rgb:ff/ff/ff\x1b\\)""" + return f"\x1b]{';'.join(map(str, i))};rgb:{c[0:2]}/{c[2:4]}/{c[4:6]}\x1b\\" + + +def gen_sequences(colours: dict[str, str]) -> str: + """ + 10: foreground + 11: background + 12: cursor + 17: selection + 4: + 0 - 7: normal colours + 8 - 15: bright colours + 16+: 256 colours + """ + return ( + c2s(colours["onSurface"], 10) + + c2s(colours["surface"], 11) + + c2s(colours["secondary"], 12) + + c2s(colours["secondary"], 17) + + c2s(colours["surfaceContainer"], 4, 0) + + c2s(colours["red"], 4, 1) + + c2s(colours["green"], 4, 2) + + c2s(colours["yellow"], 4, 3) + + c2s(colours["blue"], 4, 4) + + c2s(colours["pink"], 4, 5) + + c2s(colours["teal"], 4, 6) + + c2s(colours["onSurfaceVariant"], 4, 7) + + c2s(colours["surfaceContainer"], 4, 8) + + c2s(colours["red"], 4, 9) + + c2s(colours["green"], 4, 10) + + c2s(colours["yellow"], 4, 11) + + c2s(colours["blue"], 4, 12) + + c2s(colours["pink"], 4, 13) + + c2s(colours["teal"], 4, 14) + + c2s(colours["onSurfaceVariant"], 4, 15) + + c2s(colours["primary"], 4, 16) + + c2s(colours["secondary"], 4, 17) + + c2s(colours["tertiary"], 4, 18) + ) + + +def try_write(path: Path, content: str) -> None: + try: + path.write_text(content) + except FileNotFoundError: + pass + + +def apply_terms(sequences: str) -> None: + pts_path = Path("/dev/pts") + for pt in pts_path.iterdir(): + if pt.name.isdigit(): + with pt.open("a") as f: + f.write(sequences) + + +def apply_hypr(conf: str) -> None: + try_write(config_dir / "hypr/scheme/current.conf", conf) + + +def apply_colours(colours: dict[str, str]) -> None: + apply_terms(gen_sequences(colours)) + apply_hypr(gen_conf(colours)) -- cgit v1.2.3-freya From 6f7beecdc6de14cf1fd6be9038a86528d2ba52f0 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 21:42:13 +1000 Subject: feat: theme discord --- src/caelestia/data/config.json | 51 --------- src/caelestia/data/templates/discord.scss | 174 ++++++++++++++++++++++++++++++ src/caelestia/utils/paths.py | 5 +- src/caelestia/utils/theme.py | 15 ++- 4 files changed, 191 insertions(+), 54 deletions(-) delete mode 100644 src/caelestia/data/config.json create mode 100644 src/caelestia/data/templates/discord.scss (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/data/config.json b/src/caelestia/data/config.json deleted file mode 100644 index 47f61e5..0000000 --- a/src/caelestia/data/config.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "toggles": { - "communication": { - "apps": [ - { - "selector": ".class == \"discord\"", - "spawn": "discord", - "action": "spawn move" - }, - { - "selector": ".class == \"whatsapp\"", - "spawn": "firefox --name whatsapp -P whatsapp 'https://web.whatsapp.com'", - "action": "move", - "extraCond": "grep -q 'Name=whatsapp' ~/.mozilla/firefox/profiles.ini" - } - ] - }, - "music": { - "apps": [ - { - "selector": ".class == \"Spotify\" or .initialTitle == \"Spotify\" or .initialTitle == \"Spotify Free\"", - "spawn": "spicetify watch -s", - "action": "spawn move" - }, - { - "selector": ".class == \"feishin\"", - "spawn": "feishin", - "action": "move" - } - ] - }, - "sysmon": { - "apps": [ - { - "selector": ".class == \"btop\" and .title == \"btop\" and .workspace.name == \"special:sysmon\"", - "spawn": "foot -a 'btop' -T 'btop' -- btop", - "action": "spawn" - } - ] - }, - "todo": { - "apps": [ - { - "selector": ".class == \"Todoist\"", - "spawn": "todoist", - "action": "spawn move" - } - ] - } - } -} diff --git a/src/caelestia/data/templates/discord.scss b/src/caelestia/data/templates/discord.scss new file mode 100644 index 0000000..34220d5 --- /dev/null +++ b/src/caelestia/data/templates/discord.scss @@ -0,0 +1,174 @@ +/** + * @name Midnight (Caelestia) + * @description A dark, rounded discord theme. Caelestia scheme colours. + * @author refact0r, esme, anubis + * @version 1.6.2 + * @invite nz87hXyvcy + * @website https://github.com/refact0r/midnight-discord + * @authorId 508863359777505290 + * @authorLink https://www.refact0r.dev +*/ + +@use "sass:color"; +@use "colours" as c; + +@import url("https://refact0r.github.io/midnight-discord/build/midnight.css"); + +body { + /* font, change to '' for default discord font */ + --font: "figtree"; + + /* sizes */ + --gap: 12px; /* spacing between panels */ + --divider-thickness: 4px; /* thickness of unread messages divider and highlighted message borders */ + --border-thickness: 1px; /* thickness of borders around main panels. DOES NOT AFFECT OTHER BORDERS */ + + /* animation/transition options */ + --animations: on; /* turn off to disable all midnight animations/transitions */ + --list-item-transition: 0.2s ease; /* transition for list items */ + --dms-icon-svg-transition: 0.4s ease; /* transition for the dms icon */ + + /* top bar options */ + --top-bar-height: var( + --gap + ); /* height of the titlebar/top bar (discord default is 36px, 24px recommended if moving/hiding top bar buttons) */ + --top-bar-button-position: hide; /* off: default position, hide: hide inbox/support buttons completely, serverlist: move inbox button to server list, titlebar: move inbox button to titlebar (will hide title) */ + --top-bar-title-position: hide; /* off: default centered position, hide: hide title completely, left: left align title (like old discord) */ + --subtle-top-bar-title: off; /* off: default, on: hide the icon and use subtle text color (like old discord) */ + + /* window controls */ + --custom-window-controls: on; /* turn off to use discord default window controls */ + --window-control-size: 14px; /* size of custom window controls */ + + /* dms button icon options */ + --custom-dms-icon: custom; /* off: use default discord icon, hide: remove icon entirely, custom: use custom icon */ + --dms-icon-svg-url: url("https://upload.wikimedia.org/wikipedia/commons/c/c4/Font_Awesome_5_solid_moon.svg"); /* icon svg url. MUST BE A SVG. */ + --dms-icon-svg-size: 90%; /* size of the svg (css mask-size) */ + --dms-icon-color-before: var(--icon-secondary); /* normal icon color */ + --dms-icon-color-after: var(--white); /* icon color when button is hovered/selected */ + + /* dms button background options */ + --custom-dms-background: off; /* off to disable, image to use a background image (must set url variable below), color to use a custom color/gradient */ + --dms-background-image-url: url(""); /* url of the background image */ + --dms-background-image-size: cover; /* size of the background image (css background-size) */ + --dms-background-color: linear-gradient( + 70deg, + var(--blue-2), + var(--purple-2), + var(--red-2) + ); /* fixed color/gradient (css background) */ + + /* background image options */ + --background-image: off; /* turn on to use a background image */ + --background-image-url: url(""); /* url of the background image */ + + /* transparency/blur options */ + /* NOTE: TO USE TRANSPARENCY/BLUR, YOU MUST HAVE TRANSPARENT BG COLORS. FOR EXAMPLE: --bg-4: hsla(220, 15%, 10%, 0.7); */ + --transparency-tweaks: off; /* turn on to remove some elements for better transparency */ + --remove-bg-layer: off; /* turn on to remove the base --bg-3 layer for use with window transparency (WILL OVERRIDE BACKGROUND IMAGE) */ + --panel-blur: off; /* turn on to blur the background of panels */ + --blur-amount: 12px; /* amount of blur */ + --bg-floating: #{c.$surface}; /* you can set this to a more opaque color if floating panels look too transparent */ + + /* chatbar options */ + --custom-chatbar: aligned; /* off: default chatbar, aligned: chatbar aligned with the user panel, separated: chatbar separated from chat */ + --chatbar-height: 47px; /* height of the chatbar (52px by default, 47px recommended for aligned, 56px recommended for separated) */ + --chatbar-padding: 8px; /* padding of the chatbar. only applies in aligned mode. */ + + /* other options */ + --small-user-panel: off; /* turn on to make the user panel smaller like in old discord */ +} + +/* color options */ +:root { + --colors: on; /* turn off to use discord default colors */ + + /* text colors */ + --text-0: #{c.$onPrimary}; /* text on colored elements */ + --text-1: #{color.scale(c.$onSurface, $lightness: 10%)}; /* bright text on colored elements */ + --text-2: #{color.scale(c.$onSurface, $lightness: 5%)}; /* headings and important text */ + --text-3: #{c.$onSurface}; /* normal text */ + --text-4: #{c.$outline}; /* icon buttons and channels */ + --text-5: #{c.$outline}; /* muted channels/chats and timestamps */ + + /* background and dark colors */ + --bg-1: #{c.$surfaceContainerHighest}; /* dark buttons when clicked */ + --bg-2: #{c.$surfaceContainerHigh}; /* dark buttons */ + --bg-3: #{c.$surface}; /* spacing, secondary elements */ + --bg-4: #{c.$surfaceContainer}; /* main background color */ + --hover: #{color.change(c.$onSurface, $alpha: 0.08)}; /* channels and buttons when hovered */ + --active: #{color.change(c.$onSurface, $alpha: 0.1)}; /* channels and buttons when clicked or selected */ + --active-2: #{color.change(c.$onSurface, $alpha: 0.2)}; /* extra state for transparent buttons */ + --message-hover: #{color.change(c.$onSurface, $alpha: 0.08)}; /* messages when hovered */ + + /* accent colors */ + --accent-1: var(--blue-1); /* links and other accent text */ + --accent-2: var(--blue-2); /* small accent elements */ + --accent-3: var(--blue-3); /* accent buttons */ + --accent-4: var(--blue-4); /* accent buttons when hovered */ + --accent-5: var(--blue-5); /* accent buttons when clicked */ + --accent-new: #{c.$error}; /* stuff that's normally red like mute/deafen buttons */ + --mention: linear-gradient( + to right, + color-mix(in hsl, var(--blue-2), transparent 90%) 40%, + transparent + ); /* background of messages that mention you */ + --mention-hover: linear-gradient( + to right, + color-mix(in hsl, var(--blue-2), transparent 95%) 40%, + transparent + ); /* background of messages that mention you when hovered */ + --reply: linear-gradient( + to right, + color-mix(in hsl, var(--text-3), transparent 90%) 40%, + transparent + ); /* background of messages that reply to you */ + --reply-hover: linear-gradient( + to right, + color-mix(in hsl, var(--text-3), transparent 95%) 40%, + transparent + ); /* background of messages that reply to you when hovered */ + + /* status indicator colors */ + --online: var(--green-2); /* change to #43a25a for default */ + --dnd: var(--red-2); /* change to #d83a42 for default */ + --idle: var(--yellow-2); /* change to #ca9654 for default */ + --streaming: var(--purple-2); /* change to #593695 for default */ + --offline: var(--text-4); /* change to #83838b for default offline color */ + + /* border colors */ + --border-light: #{color.change(c.$outline, $alpha: 0)}; /* light border color */ + --border: #{color.change(c.$outline, $alpha: 0)}; /* normal border color */ + --button-border: #{color.change(c.$outline, $alpha: 0)}; /* neutral border color of buttons */ + + /* base colors */ + --red-1: #{c.$error}; + --red-2: #{color.scale(c.$error, $lightness: -5%)}; + --red-3: #{color.scale(c.$error, $lightness: -10%)}; + --red-4: #{color.scale(c.$error, $lightness: -15%)}; + --red-5: #{color.scale(c.$error, $lightness: -20%)}; + + --green-1: #{c.$green}; + --green-2: #{color.scale(c.$green, $lightness: -5%)}; + --green-3: #{color.scale(c.$green, $lightness: -10%)}; + --green-4: #{color.scale(c.$green, $lightness: -15%)}; + --green-5: #{color.scale(c.$green, $lightness: -20%)}; + + --blue-1: #{c.$primary}; + --blue-2: #{color.scale(c.$primary, $lightness: -5%)}; + --blue-3: #{color.scale(c.$primary, $lightness: -10%)}; + --blue-4: #{color.scale(c.$primary, $lightness: -15%)}; + --blue-5: #{color.scale(c.$primary, $lightness: -20%)}; + + --yellow-1: #{c.$yellow}; + --yellow-2: #{color.scale(c.$yellow, $lightness: -5%)}; + --yellow-3: #{color.scale(c.$yellow, $lightness: -10%)}; + --yellow-4: #{color.scale(c.$yellow, $lightness: -15%)}; + --yellow-5: #{color.scale(c.$yellow, $lightness: -20%)}; + + --purple-1: #{c.$mauve}; + --purple-2: #{color.scale(c.$mauve, $lightness: -5%)}; + --purple-3: #{color.scale(c.$mauve, $lightness: -10%)}; + --purple-4: #{color.scale(c.$mauve, $lightness: -15%)}; + --purple-5: #{color.scale(c.$mauve, $lightness: -20%)}; +} diff --git a/src/caelestia/utils/paths.py b/src/caelestia/utils/paths.py index aff6ea0..dfb57d9 100644 --- a/src/caelestia/utils/paths.py +++ b/src/caelestia/utils/paths.py @@ -9,5 +9,8 @@ c_config_dir = config_dir / "caelestia" c_data_dir = data_dir / "caelestia" c_state_dir = state_dir / "caelestia" +cli_data_dir = Path(__file__).parent.parent / "data" +templates_dir = cli_data_dir / "templates" + scheme_path = c_state_dir / "scheme.json" -scheme_data_path = Path(__file__).parent.parent / "data/schemes" +scheme_data_path = cli_data_dir / "schemes" diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index 7774472..7940547 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -1,8 +1,9 @@ import json import subprocess +import tempfile from pathlib import Path -from caelestia.utils.paths import config_dir +from caelestia.utils.paths import config_dir, templates_dir def gen_conf(colours: dict[str, str]) -> str: @@ -15,7 +16,7 @@ def gen_conf(colours: dict[str, str]) -> str: def gen_scss(colours: dict[str, str]) -> str: scss = "" for name, colour in colours.items(): - scss += f"${name}: {colour};\n" + scss += f"${name}: #{colour};\n" return scss @@ -81,6 +82,16 @@ def apply_hypr(conf: str) -> None: try_write(config_dir / "hypr/scheme/current.conf", conf) +def apply_discord(scss: str) -> None: + with tempfile.TemporaryDirectory("w") as tmp_dir: + (Path(tmp_dir) / "_colours.scss").write_text(scss) + conf = subprocess.check_output(["sass", "-I", tmp_dir, templates_dir / "discord.scss"], text=True) + + for client in "Equicord", "Vencord", "BetterDiscord", "equicord", "vesktop", "legcord": + try_write(config_dir / client / "themes/caelestia.theme.css", conf) + + def apply_colours(colours: dict[str, str]) -> None: apply_terms(gen_sequences(colours)) apply_hypr(gen_conf(colours)) + apply_discord(gen_scss(colours)) -- cgit v1.2.3-freya From 09f01bfd1dfebea92c2931e617fbc634e03d2b2c Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 21:59:23 +1000 Subject: feat: theme spicetify --- src/caelestia/data/templates/spicetify.ini | 17 +++++++++++++++++ src/caelestia/utils/theme.py | 11 ++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/caelestia/data/templates/spicetify.ini (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/data/templates/spicetify.ini b/src/caelestia/data/templates/spicetify.ini new file mode 100644 index 0000000..839f30d --- /dev/null +++ b/src/caelestia/data/templates/spicetify.ini @@ -0,0 +1,17 @@ +[caelestia] +text = $text ; Main text colour +subtext = $subtext0 ; Subtext colour +main = $base ; Panel backgrounds +highlight = $primary ; Doesn't seem to do anything +misc = $primary ; Doesn't seem to do anything +notification = $overlay0 ; Notifications probably +notification-error = $error ; Error notifications probably +shadow = $mantle ; Shadow for covers, context menu, also affects playlist/artist banners +card = $surface0 ; Context menu and tooltips +player = $base ; Doesn't seem to do anything +sidebar = $mantle ; Background +main-elevated = $surface0 ; Higher layers than main, e.g. search bar +selected-row = $text ; Selections, hover, other coloured text and slider background +button = $primary ; Slider and text buttons +button-active = $primary ; Background buttons +button-disabled = $overlay0 ; Disabled buttons diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index 7940547..acca868 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -1,4 +1,3 @@ -import json import subprocess import tempfile from pathlib import Path @@ -91,7 +90,17 @@ def apply_discord(scss: str) -> None: try_write(config_dir / client / "themes/caelestia.theme.css", conf) +def apply_spicetify(colours: dict[str, str]) -> None: + template = (templates_dir / "spicetify.ini").read_text() + + for name, colour in colours.items(): + template = template.replace(f"${name}", colour) + + try_write(config_dir / "spicetify/Themes/caelestia/color.ini", template) + + def apply_colours(colours: dict[str, str]) -> None: apply_terms(gen_sequences(colours)) apply_hypr(gen_conf(colours)) apply_discord(gen_scss(colours)) + apply_spicetify(colours) -- cgit v1.2.3-freya From 63040f68b7098ba2cf7b83ab878420debe75cfb1 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 22:09:44 +1000 Subject: feat: theme fuzzel --- src/caelestia/data/templates/fuzzel.ini | 41 +++++++++++++++++++++++++++++++++ src/caelestia/utils/theme.py | 17 ++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/caelestia/data/templates/fuzzel.ini (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/data/templates/fuzzel.ini b/src/caelestia/data/templates/fuzzel.ini new file mode 100644 index 0000000..d4eaafe --- /dev/null +++ b/src/caelestia/data/templates/fuzzel.ini @@ -0,0 +1,41 @@ +font=JetBrains Mono NF:size=17 +terminal=foot -e +prompt="> " +layer=overlay +lines=15 +width=60 +dpi-aware=no +inner-pad=10 +horizontal-pad=40 +vertical-pad=15 +match-counter=yes + +[colors] +background=282c34dd +text=abb2bfdd +prompt=d19a66ff +placeholder=666e7cff +input=abb2bfff +match=be5046ff +selection=d19a6687 +selection-text=abb2bfff +selection-match=be5046ff +counter=666e7cff +border=d19a6677 + +[border] +radius=10 +width=2 + +[colors] +background=$surfacedd +text=$onSurfacedd +prompt=$primaryff +placeholder=$outlineff +input=$onSurfaceff +match=$tertiaryff +selection=$primary87 +selection-text=$onSurfaceff +selection-match=$tertiaryff +counter=$outlineff +border=$primary77 diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index acca868..c4e9899 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -19,6 +19,13 @@ def gen_scss(colours: dict[str, str]) -> str: return scss +def gen_replace(colours: dict[str, str], template: Path) -> str: + template = template.read_text() + for name, colour in colours.items(): + template = template.replace(f"${name}", colour) + return template + + def c2s(c: str, *i: list[int]) -> str: """Hex to ANSI sequence (e.g. ffffff, 11 -> \x1b]11;rgb:ff/ff/ff\x1b\\)""" return f"\x1b]{';'.join(map(str, i))};rgb:{c[0:2]}/{c[2:4]}/{c[4:6]}\x1b\\" @@ -91,12 +98,13 @@ def apply_discord(scss: str) -> None: def apply_spicetify(colours: dict[str, str]) -> None: - template = (templates_dir / "spicetify.ini").read_text() + template = gen_replace(colours, templates_dir / "spicetify.ini") + try_write(config_dir / "spicetify/Themes/caelestia/color.ini", template) - for name, colour in colours.items(): - template = template.replace(f"${name}", colour) - try_write(config_dir / "spicetify/Themes/caelestia/color.ini", template) +def apply_fuzzel(colours: dict[str, str]) -> None: + template = gen_replace(colours, templates_dir / "fuzzel.ini") + try_write(config_dir / "fuzzel/fuzzel.ini", template) def apply_colours(colours: dict[str, str]) -> None: @@ -104,3 +112,4 @@ def apply_colours(colours: dict[str, str]) -> None: apply_hypr(gen_conf(colours)) apply_discord(gen_scss(colours)) apply_spicetify(colours) + apply_fuzzel(colours) -- cgit v1.2.3-freya From b08858191cf6e3acda33afbd532b743ad6d0f808 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 22:25:03 +1000 Subject: feat: theme btop Also change template replacement format --- src/caelestia/data/templates/btop.theme | 83 ++++++++++++++++++++++++++++++ src/caelestia/data/templates/fuzzel.ini | 22 ++++---- src/caelestia/data/templates/spicetify.ini | 32 ++++++------ src/caelestia/utils/theme.py | 11 +++- 4 files changed, 119 insertions(+), 29 deletions(-) create mode 100644 src/caelestia/data/templates/btop.theme (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/data/templates/btop.theme b/src/caelestia/data/templates/btop.theme new file mode 100644 index 0000000..9e63bce --- /dev/null +++ b/src/caelestia/data/templates/btop.theme @@ -0,0 +1,83 @@ +# Main background, empty for terminal default, need to be empty if you want transparent background +theme[main_bg]={{ $surface }} + +# Main text color +theme[main_fg]={{ $onSurface }} + +# Title color for boxes +theme[title]={{ $onSurface }} + +# Highlight color for keyboard shortcuts +theme[hi_fg]={{ $primary }} + +# Background color of selected item in processes box +theme[selected_bg]={{ $surfaceContainer }} + +# Foreground color of selected item in processes box +theme[selected_fg]={{ $primary }} + +# Color of inactive/disabled text +theme[inactive_fg]={{ $outline }} + +# Color of text appearing on top of graphs, i.e uptime and current network graph scaling +theme[graph_text]={{ $tertiary }} + +# Background color of the percentage meters +theme[meter_bg]={{ $outline }} + +# Misc colors for processes box including mini cpu graphs, details memory graph and details status text +theme[proc_misc]={{ $tertiary }} + +# CPU, Memory, Network, Proc box outline colors +theme[cpu_box]={{ $mauve }} +theme[mem_box]={{ $green }} +theme[net_box]={{ $maroon }} +theme[proc_box]={{ $blue }} + +# Box divider line and small boxes line color +theme[div_line]={{ $outlineVariant }} + +# Temperature graph color (Green -> Yellow -> Red) +theme[temp_start]={{ $green }} +theme[temp_mid]={{ $yellow }} +theme[temp_end]={{ $red }} + +# CPU graph colors (Teal -> Sapphire -> Lavender) +theme[cpu_start]={{ $teal }} +theme[cpu_mid]={{ $sapphire }} +theme[cpu_end]={{ $lavender }} + +# Mem/Disk free meter (Mauve -> Lavender -> Blue) +theme[free_start]={{ $mauve }} +theme[free_mid]={{ $lavender }} +theme[free_end]={{ $blue }} + +# Mem/Disk cached meter (Sapphire -> Blue -> Lavender) +theme[cached_start]={{ $sapphire }} +theme[cached_mid]={{ $blue }} +theme[cached_end]={{ $lavender }} + +# Mem/Disk available meter (Peach -> Maroon -> Red) +theme[available_start]={{ $peach }} +theme[available_mid]={{ $maroon }} +theme[available_end]={{ $red }} + +# Mem/Disk used meter (Green -> Teal -> Sky) +theme[used_start]={{ $green }} +theme[used_mid]={{ $teal }} +theme[used_end]={{ $sky }} + +# Download graph colors (Peach -> Maroon -> Red) +theme[download_start]={{ $peach }} +theme[download_mid]={{ $maroon }} +theme[download_end]={{ $red }} + +# Upload graph colors (Green -> Teal -> Sky) +theme[upload_start]={{ $green }} +theme[upload_mid]={{ $teal }} +theme[upload_end]={{ $sky }} + +# Process box color gradient for threads, mem and cpu usage (Sapphire -> Lavender -> Mauve) +theme[process_start]={{ $sapphire }} +theme[process_mid]={{ $lavender }} +theme[process_end]={{ $mauve }} diff --git a/src/caelestia/data/templates/fuzzel.ini b/src/caelestia/data/templates/fuzzel.ini index d4eaafe..d61f208 100644 --- a/src/caelestia/data/templates/fuzzel.ini +++ b/src/caelestia/data/templates/fuzzel.ini @@ -28,14 +28,14 @@ radius=10 width=2 [colors] -background=$surfacedd -text=$onSurfacedd -prompt=$primaryff -placeholder=$outlineff -input=$onSurfaceff -match=$tertiaryff -selection=$primary87 -selection-text=$onSurfaceff -selection-match=$tertiaryff -counter=$outlineff -border=$primary77 +background={{ $surface }}dd +text={{ $onSurface }}dd +prompt={{ $primary }}ff +placeholder={{ $outline }}ff +input={{ $onSurface }}ff +match={{ $tertiary }}ff +selection={{ $primary }}87 +selection-text={{ $onSurface }}ff +selection-match={{ $tertiary }}ff +counter={{ $outline }}ff +border={{ $primary }}77 diff --git a/src/caelestia/data/templates/spicetify.ini b/src/caelestia/data/templates/spicetify.ini index 839f30d..976a0c9 100644 --- a/src/caelestia/data/templates/spicetify.ini +++ b/src/caelestia/data/templates/spicetify.ini @@ -1,17 +1,17 @@ [caelestia] -text = $text ; Main text colour -subtext = $subtext0 ; Subtext colour -main = $base ; Panel backgrounds -highlight = $primary ; Doesn't seem to do anything -misc = $primary ; Doesn't seem to do anything -notification = $overlay0 ; Notifications probably -notification-error = $error ; Error notifications probably -shadow = $mantle ; Shadow for covers, context menu, also affects playlist/artist banners -card = $surface0 ; Context menu and tooltips -player = $base ; Doesn't seem to do anything -sidebar = $mantle ; Background -main-elevated = $surface0 ; Higher layers than main, e.g. search bar -selected-row = $text ; Selections, hover, other coloured text and slider background -button = $primary ; Slider and text buttons -button-active = $primary ; Background buttons -button-disabled = $overlay0 ; Disabled buttons +text = {{ $text }} ; Main text colour +subtext = {{ $subtext0 }} ; Subtext colour +main = {{ $base }} ; Panel backgrounds +highlight = {{ $primary }} ; Doesn't seem to do anything +misc = {{ $primary }} ; Doesn't seem to do anything +notification = {{ $overlay0 }} ; Notifications probably +notification-error = {{ $error }} ; Error notifications probably +shadow = {{ $mantle }} ; Shadow for covers, context menu, also affects playlist/artist banners +card = {{ $surface0 }} ; Context menu and tooltips +player = {{ $base }} ; Doesn't seem to do anything +sidebar = {{ $mantle }} ; Background +main-elevated = {{ $surface0 }} ; Higher layers than main, e.g. search bar +selected-row = {{ $text }} ; Selections, hover, other coloured text and slider background +button = {{ $primary }} ; Slider and text buttons +button-active = {{ $primary }} ; Background buttons +button-disabled = {{ $overlay0 }} ; Disabled buttons diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index c4e9899..7f29637 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -19,10 +19,10 @@ def gen_scss(colours: dict[str, str]) -> str: return scss -def gen_replace(colours: dict[str, str], template: Path) -> str: +def gen_replace(colours: dict[str, str], template: Path, hash: bool = False) -> str: template = template.read_text() for name, colour in colours.items(): - template = template.replace(f"${name}", colour) + template = template.replace(f"{{{{ ${name} }}}}", f"#{colour}" if hash else colour) return template @@ -107,9 +107,16 @@ def apply_fuzzel(colours: dict[str, str]) -> None: try_write(config_dir / "fuzzel/fuzzel.ini", template) +def apply_btop(colours: dict[str, str]) -> None: + template = gen_replace(colours, templates_dir / "btop.theme", hash=True) + try_write(config_dir / "btop/themes/caelestia.theme", template) + subprocess.run(["killall", "-USR2", "btop"]) + + def apply_colours(colours: dict[str, str]) -> None: apply_terms(gen_sequences(colours)) apply_hypr(gen_conf(colours)) apply_discord(gen_scss(colours)) apply_spicetify(colours) apply_fuzzel(colours) + apply_btop(colours) -- cgit v1.2.3-freya From 2161e3ee6b61c0ebd56142ccd9502404d3ee1314 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 11 Jun 2025 22:48:09 +1000 Subject: theme: better spicetify colours --- src/caelestia/data/templates/spicetify-dark.ini | 19 +++++++++++++++++++ src/caelestia/data/templates/spicetify-light.ini | 19 +++++++++++++++++++ src/caelestia/data/templates/spicetify.ini | 17 ----------------- src/caelestia/subcommands/scheme.py | 2 +- src/caelestia/utils/theme.py | 8 ++++---- 5 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 src/caelestia/data/templates/spicetify-dark.ini create mode 100644 src/caelestia/data/templates/spicetify-light.ini delete mode 100644 src/caelestia/data/templates/spicetify.ini (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/data/templates/spicetify-dark.ini b/src/caelestia/data/templates/spicetify-dark.ini new file mode 100644 index 0000000..4bf85eb --- /dev/null +++ b/src/caelestia/data/templates/spicetify-dark.ini @@ -0,0 +1,19 @@ +[caelestia] +text = {{ $onSurface }} ; Main text colour +subtext = {{ $onSurfaceVariant }} ; Subtext colour +main = {{ $surfaceContainer }} ; Panel backgrounds +highlight = {{ $primary }} ; Doesn't seem to do anything +misc = {{ $primary }} ; Doesn't seem to do anything +notification = {{ $outline }} ; Notifications probably +notification-error = {{ $error }} ; Error notifications probably +shadow = {{ $shadow }} ; Shadow for covers, context menu, also affects playlist/artist banners +card = {{ $surfaceContainerHigh }} ; Context menu and tooltips +player = {{ $secondaryContainer }} ; Background for top result in search +sidebar = {{ $surface }} ; Background +main-elevated = {{ $surfaceContainerHigh }} ; Higher layers than main, e.g. search bar +highlight-elevated = {{ $surfaceContainerHighest }} ; Home button and search bar accelerator +selected-row = {{ $onSurface }} ; Selections, hover, other coloured text and slider background +button = {{ $primary }} ; Slider and text buttons +button-active = {{ $primary }} ; Background buttons +button-disabled = {{ $outline }} ; Disabled buttons +tab-active = {{ $surfaceContainerHigh }} ; Profile fallbacks in search diff --git a/src/caelestia/data/templates/spicetify-light.ini b/src/caelestia/data/templates/spicetify-light.ini new file mode 100644 index 0000000..a8b361b --- /dev/null +++ b/src/caelestia/data/templates/spicetify-light.ini @@ -0,0 +1,19 @@ +[caelestia] +text = {{ $onSurface }} ; Main text colour +subtext = {{ $onSurfaceVariant }} ; Subtext colour +main = {{ $surface }} ; Panel backgrounds +highlight = {{ $primary }} ; Doesn't seem to do anything +misc = {{ $primary }} ; Doesn't seem to do anything +notification = {{ $outline }} ; Notifications probably +notification-error = {{ $error }} ; Error notifications probably +shadow = {{ $shadow }} ; Shadow for covers, context menu, also affects playlist/artist banners +card = {{ $surfaceContainer }} ; Context menu and tooltips +player = {{ $secondaryContainer }} ; Background for top result in search +sidebar = {{ $surfaceContainer }} ; Background +main-elevated = {{ $surfaceContainerHigh }} ; Higher layers than main, e.g. search bar +highlight-elevated = {{ $surfaceContainerHighest }} ; Home button and search bar accelerator +selected-row = {{ $onSurface }} ; Selections, hover, other coloured text and slider background +button = {{ $primary }} ; Slider and text buttons +button-active = {{ $primary }} ; Background buttons +button-disabled = {{ $outline }} ; Disabled buttons +tab-active = {{ $surfaceContainer }} ; Profile fallbacks in search diff --git a/src/caelestia/data/templates/spicetify.ini b/src/caelestia/data/templates/spicetify.ini deleted file mode 100644 index 976a0c9..0000000 --- a/src/caelestia/data/templates/spicetify.ini +++ /dev/null @@ -1,17 +0,0 @@ -[caelestia] -text = {{ $text }} ; Main text colour -subtext = {{ $subtext0 }} ; Subtext colour -main = {{ $base }} ; Panel backgrounds -highlight = {{ $primary }} ; Doesn't seem to do anything -misc = {{ $primary }} ; Doesn't seem to do anything -notification = {{ $overlay0 }} ; Notifications probably -notification-error = {{ $error }} ; Error notifications probably -shadow = {{ $mantle }} ; Shadow for covers, context menu, also affects playlist/artist banners -card = {{ $surface0 }} ; Context menu and tooltips -player = {{ $base }} ; Doesn't seem to do anything -sidebar = {{ $mantle }} ; Background -main-elevated = {{ $surface0 }} ; Higher layers than main, e.g. search bar -selected-row = {{ $text }} ; Selections, hover, other coloured text and slider background -button = {{ $primary }} ; Slider and text buttons -button-active = {{ $primary }} ; Background buttons -button-disabled = {{ $overlay0 }} ; Disabled buttons diff --git a/src/caelestia/subcommands/scheme.py b/src/caelestia/subcommands/scheme.py index fa1f49a..e149d13 100644 --- a/src/caelestia/subcommands/scheme.py +++ b/src/caelestia/subcommands/scheme.py @@ -22,6 +22,6 @@ class Command: scheme.flavour = self.args.flavour if self.args.mode: scheme.mode = self.args.mode - apply_colours(scheme.colours) + apply_colours(scheme.colours, scheme.mode) else: print(scheme) diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index 7f29637..3250ea3 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -97,8 +97,8 @@ def apply_discord(scss: str) -> None: try_write(config_dir / client / "themes/caelestia.theme.css", conf) -def apply_spicetify(colours: dict[str, str]) -> None: - template = gen_replace(colours, templates_dir / "spicetify.ini") +def apply_spicetify(colours: dict[str, str], mode: str) -> None: + template = gen_replace(colours, templates_dir / f"spicetify-{mode}.ini") try_write(config_dir / "spicetify/Themes/caelestia/color.ini", template) @@ -113,10 +113,10 @@ def apply_btop(colours: dict[str, str]) -> None: subprocess.run(["killall", "-USR2", "btop"]) -def apply_colours(colours: dict[str, str]) -> None: +def apply_colours(colours: dict[str, str], mode: str) -> None: apply_terms(gen_sequences(colours)) apply_hypr(gen_conf(colours)) apply_discord(gen_scss(colours)) - apply_spicetify(colours) + apply_spicetify(colours, mode) apply_fuzzel(colours) apply_btop(colours) -- cgit v1.2.3-freya From 194826efaa95480bfe1799f889ca5c02571b3e36 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:48:02 +1000 Subject: feat: generate dynamic schemes --- src/caelestia/utils/material/__init__.py | 52 ++++++++ src/caelestia/utils/material/generator.py | 192 ++++++++++++++++++++++++++++++ src/caelestia/utils/material/score.py | 129 ++++++++++++++++++++ src/caelestia/utils/paths.py | 19 ++- src/caelestia/utils/scheme.py | 19 ++- src/caelestia/utils/theme.py | 2 +- 6 files changed, 405 insertions(+), 8 deletions(-) create mode 100644 src/caelestia/utils/material/__init__.py create mode 100755 src/caelestia/utils/material/generator.py create mode 100755 src/caelestia/utils/material/score.py (limited to 'src/caelestia/utils/theme.py') diff --git a/src/caelestia/utils/material/__init__.py b/src/caelestia/utils/material/__init__.py new file mode 100644 index 0000000..8adab1f --- /dev/null +++ b/src/caelestia/utils/material/__init__.py @@ -0,0 +1,52 @@ +import json +from pathlib import Path + +from materialyoucolor.hct import Hct + +from caelestia.utils.material.generator import gen_scheme +from caelestia.utils.material.score import score +from caelestia.utils.paths import compute_hash, scheme_cache_dir, wallpaper_thumbnail_path + + +def get_score_for_image(image: str, cache_base: Path) -> tuple[list[Hct], list[Hct]]: + cache = cache_base / "score.json" + + try: + with cache.open("r") as f: + return [[Hct.from_int(c) for c in li] for li in json.load(f)] + except (IOError, json.JSONDecodeError): + pass + + s = score(image) + + cache.parent.mkdir(parents=True, exist_ok=True) + with cache.open("w") as f: + json.dump([[c.to_int() for c in li] for li in s], f) + + return s + + +def get_colours_for_image(image: str = str(wallpaper_thumbnail_path), scheme=None) -> dict[str, str]: + if scheme is None: + from caelestia.utils.scheme import get_scheme + + scheme = get_scheme() + + cache_base = scheme_cache_dir / compute_hash(image) + cache = (cache_base / scheme.variant / scheme.flavour / scheme.mode).with_suffix(".json") + + try: + with cache.open("r") as f: + return json.load(f) + except (IOError, json.JSONDecodeError): + pass + + primaries, colours = get_score_for_image(image, cache_base) + i = ["default", "alt1", "alt2"].index(scheme.flavour) + scheme = gen_scheme(scheme, primaries[i], colours) + + cache.parent.mkdir(parents=True, exist_ok=True) + with cache.open("w") as f: + json.dump(scheme, f) + + return scheme diff --git a/src/caelestia/utils/material/generator.py b/src/caelestia/utils/material/generator.py new file mode 100755 index 0000000..33ff0e8 --- /dev/null +++ b/src/caelestia/utils/material/generator.py @@ -0,0 +1,192 @@ +from materialyoucolor.blend import Blend +from materialyoucolor.dynamiccolor.material_dynamic_colors import ( + DynamicScheme, + MaterialDynamicColors, +) +from materialyoucolor.hct import Hct +from materialyoucolor.hct.cam16 import Cam16 +from materialyoucolor.scheme.scheme_content import SchemeContent +from materialyoucolor.scheme.scheme_expressive import SchemeExpressive +from materialyoucolor.scheme.scheme_fidelity import SchemeFidelity +from materialyoucolor.scheme.scheme_fruit_salad import SchemeFruitSalad +from materialyoucolor.scheme.scheme_monochrome import SchemeMonochrome +from materialyoucolor.scheme.scheme_neutral import SchemeNeutral +from materialyoucolor.scheme.scheme_rainbow import SchemeRainbow +from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot +from materialyoucolor.scheme.scheme_vibrant import SchemeVibrant + + +def hex_to_hct(hex: str) -> Hct: + return Hct.from_int(int(f"0xFF{hex}", 16)) + + +light_colours = [ + hex_to_hct("dc8a78"), + hex_to_hct("dd7878"), + hex_to_hct("ea76cb"), + hex_to_hct("8839ef"), + hex_to_hct("d20f39"), + hex_to_hct("e64553"), + hex_to_hct("fe640b"), + hex_to_hct("df8e1d"), + hex_to_hct("40a02b"), + hex_to_hct("179299"), + hex_to_hct("04a5e5"), + hex_to_hct("209fb5"), + hex_to_hct("1e66f5"), + hex_to_hct("7287fd"), +] + +dark_colours = [ + hex_to_hct("f5e0dc"), + hex_to_hct("f2cdcd"), + hex_to_hct("f5c2e7"), + hex_to_hct("cba6f7"), + hex_to_hct("f38ba8"), + hex_to_hct("eba0ac"), + hex_to_hct("fab387"), + hex_to_hct("f9e2af"), + hex_to_hct("a6e3a1"), + hex_to_hct("94e2d5"), + hex_to_hct("89dceb"), + hex_to_hct("74c7ec"), + hex_to_hct("89b4fa"), + hex_to_hct("b4befe"), +] + +colour_names = [ + "rosewater", + "flamingo", + "pink", + "mauve", + "red", + "maroon", + "peach", + "yellow", + "green", + "teal", + "sky", + "sapphire", + "blue", + "lavender", + "success", + "error", +] + + +def grayscale(colour: Hct, light: bool) -> None: + colour.chroma = 0 + + +def mix(a: Hct, b: Hct, w: float) -> Hct: + return Hct.from_int(Blend.cam16_ucs(a.to_int(), b.to_int(), w)) + + +def harmonize(a: Hct, b: Hct) -> Hct: + return Hct.from_int(Blend.harmonize(a.to_int(), b.to_int())) + + +def lighten(colour: Hct, amount: float) -> Hct: + diff = (100 - colour.tone) * amount + return Hct.from_hct(colour.hue, colour.chroma + diff / 2, colour.tone + diff) + + +def darken(colour: Hct, amount: float) -> Hct: + diff = colour.tone * amount + return Hct.from_hct(colour.hue, colour.chroma + diff / 2, colour.tone - diff) + + +def distance(colour: Cam16, base: Cam16) -> float: + return colour.distance(base) + + +def smart_sort(colours: list[Hct], base: list[Hct]) -> dict[str, Hct]: + sorted_colours = [None] * len(colours) + distances = {} + + cams = [(c, Cam16.from_int(c.to_int())) for c in colours] + base_cams = [Cam16.from_int(c.to_int()) for c in base] + + for colour, cam in cams: + dist = [(i, distance(cam, b)) for i, b in enumerate(base_cams)] + dist.sort(key=lambda x: x[1]) + distances[colour] = dist + + for colour in colours: + while len(distances[colour]) > 0: + i, dist = distances[colour][0] + + if sorted_colours[i] is None: + sorted_colours[i] = colour, dist + break + elif sorted_colours[i][1] > dist: + old = sorted_colours[i][0] + sorted_colours[i] = colour, dist + colour = old + + distances[colour].pop(0) + + return {colour_names[i]: c[0] for i, c in enumerate(sorted_colours)} + + +def get_scheme(scheme: str) -> DynamicScheme: + if scheme == "content": + return SchemeContent + if scheme == "expressive": + return SchemeExpressive + if scheme == "fidelity": + return SchemeFidelity + if scheme == "fruitsalad": + return SchemeFruitSalad + if scheme == "monochrome": + return SchemeMonochrome + if scheme == "neutral": + return SchemeNeutral + if scheme == "rainbow": + return SchemeRainbow + if scheme == "tonalspot": + return SchemeTonalSpot + return SchemeVibrant + + +def gen_scheme(scheme, primary: Hct, colours: list[Hct]) -> dict[str, str]: + light = scheme.mode == "light" + base = light_colours if light else dark_colours + + # Sort colours and turn into dict + colours = smart_sort(colours, base) + + # Harmonize colours + for name, hct in colours.items(): + if scheme.variant == "monochrome": + grayscale(hct, light) + else: + harmonized = harmonize(hct, primary) + colours[name] = darken(harmonized, 0.35) if light else lighten(harmonized, 0.65) + + # Material colours + primary_scheme = get_scheme(scheme.variant)(primary, not light, 0) + for colour in vars(MaterialDynamicColors).keys(): + colour_name = getattr(MaterialDynamicColors, colour) + if hasattr(colour_name, "get_hct"): + colours[colour] = colour_name.get_hct(primary_scheme) + + # FIXME: deprecated stuff + colours["text"] = colours["onBackground"] + colours["subtext1"] = colours["onSurfaceVariant"] + colours["subtext0"] = colours["outline"] + colours["overlay2"] = mix(colours["surface"], colours["outline"], 0.86) + colours["overlay1"] = mix(colours["surface"], colours["outline"], 0.71) + colours["overlay0"] = mix(colours["surface"], colours["outline"], 0.57) + colours["surface2"] = mix(colours["surface"], colours["outline"], 0.43) + colours["surface1"] = mix(colours["surface"], colours["outline"], 0.29) + colours["surface0"] = mix(colours["surface"], colours["outline"], 0.14) + colours["base"] = colours["surface"] + colours["mantle"] = darken(colours["surface"], 0.03) + colours["crust"] = darken(colours["surface"], 0.05) + colours["success"] = harmonize(base[8], primary) + + # For debugging + print("\n".join(["{}: \x1b[48;2;{};{};{}m \x1b[0m".format(n, *c.to_rgba()[:3]) for n, c in colours.items()])) + + return {k: hex(v.to_int())[4:] for k, v in colours.items()} diff --git a/src/caelestia/utils/material/score.py b/src/caelestia/utils/material/score.py new file mode 100755 index 0000000..da8b062 --- /dev/null +++ b/src/caelestia/utils/material/score.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python + +import sys + +from materialyoucolor.dislike.dislike_analyzer import DislikeAnalyzer +from materialyoucolor.hct import Hct +from materialyoucolor.quantize import ImageQuantizeCelebi +from materialyoucolor.utils.math_utils import difference_degrees, sanitize_degrees_int + + +class Score: + TARGET_CHROMA = 48.0 + WEIGHT_PROPORTION = 0.7 + WEIGHT_CHROMA_ABOVE = 0.3 + WEIGHT_CHROMA_BELOW = 0.1 + CUTOFF_CHROMA = 5.0 + CUTOFF_EXCITED_PROPORTION = 0.01 + + def __init__(self): + pass + + @staticmethod + def score(colors_to_population: dict) -> tuple[list[Hct], list[Hct]]: + desired = 14 + filter_enabled = True + dislike_filter = True + + colors_hct = [] + hue_population = [0] * 360 + population_sum = 0 + + for rgb, population in colors_to_population.items(): + hct = Hct.from_int(rgb) + colors_hct.append(hct) + hue = int(hct.hue) + hue_population[hue] += population + population_sum += population + + hue_excited_proportions = [0.0] * 360 + + for hue in range(360): + proportion = hue_population[hue] / population_sum + for i in range(hue - 14, hue + 16): + neighbor_hue = int(sanitize_degrees_int(i)) + hue_excited_proportions[neighbor_hue] += proportion + + # Score colours + scored_hct = [] + for hct in colors_hct: + hue = int(sanitize_degrees_int(round(hct.hue))) + proportion = hue_excited_proportions[hue] + + if filter_enabled and (hct.chroma < Score.CUTOFF_CHROMA or proportion <= Score.CUTOFF_EXCITED_PROPORTION): + continue + + proportion_score = proportion * 100.0 * Score.WEIGHT_PROPORTION + chroma_weight = Score.WEIGHT_CHROMA_BELOW if hct.chroma < Score.TARGET_CHROMA else Score.WEIGHT_CHROMA_ABOVE + chroma_score = (hct.chroma - Score.TARGET_CHROMA) * chroma_weight + score = proportion_score + chroma_score + scored_hct.append({"hct": hct, "score": score}) + + scored_hct.sort(key=lambda x: x["score"], reverse=True) + + # Choose distinct colours + chosen_colors = [] + for difference_degrees_ in range(90, 0, -1): + chosen_colors.clear() + for item in scored_hct: + hct = item["hct"] + duplicate_hue = any( + difference_degrees(hct.hue, chosen_hct.hue) < difference_degrees_ for chosen_hct in chosen_colors + ) + if not duplicate_hue: + chosen_colors.append(hct) + if len(chosen_colors) >= desired: + break + if len(chosen_colors) >= desired: + break + + # Get primary colour + primary = None + for cutoff in range(20, 0, -1): + for item in scored_hct: + if item["hct"].chroma > cutoff and item["hct"].tone > cutoff * 3: + primary = item["hct"] + break + if primary: + break + + # Choose distinct primaries + chosen_primaries = [primary] + for difference_degrees_ in range(90, 14, -1): + chosen_primaries = [primary] + for item in scored_hct: + hct = item["hct"] + duplicate_hue = any( + difference_degrees(hct.hue, chosen_hct.hue) < difference_degrees_ for chosen_hct in chosen_primaries + ) + if not duplicate_hue: + chosen_primaries.append(hct) + if len(chosen_primaries) >= 3: + break + if len(chosen_primaries) >= 3: + break + + # Fix disliked colours + if dislike_filter: + for i, chosen_hct in enumerate(chosen_primaries): + chosen_primaries[i] = DislikeAnalyzer.fix_if_disliked(chosen_hct) + for i, chosen_hct in enumerate(chosen_colors): + chosen_colors[i] = DislikeAnalyzer.fix_if_disliked(chosen_hct) + + return chosen_primaries, chosen_colors + + +def score(image: str) -> tuple[list[Hct], list[Hct]]: + return Score.score(ImageQuantizeCelebi(image, 1, 128)) + + +if __name__ == "__main__": + img = sys.argv[1] + mode = sys.argv[2] if len(sys.argv) > 2 else "hex" + + colours = Score.score(ImageQuantizeCelebi(img, 1, 128)) + for t in colours: + if mode != "hex": + print("".join(["\x1b[48;2;{};{};{}m \x1b[0m".format(*c.to_rgba()[:3]) for c in t])) + if mode != "swatch": + print(" ".join(["{:02X}{:02X}{:02X}".format(*c.to_rgba()[:3]) for c in t])) diff --git a/src/caelestia/utils/paths.py b/src/caelestia/utils/paths.py index dfb57d9..6a6e0a8 100644 --- a/src/caelestia/utils/paths.py +++ b/src/caelestia/utils/paths.py @@ -1,16 +1,33 @@ +import hashlib import os from pathlib import Path config_dir = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config")) data_dir = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local/share")) state_dir = Path(os.getenv("XDG_STATE_HOME", Path.home() / ".local/state")) +cache_dir = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) c_config_dir = config_dir / "caelestia" c_data_dir = data_dir / "caelestia" c_state_dir = state_dir / "caelestia" +c_cache_dir = cache_dir / "caelestia" cli_data_dir = Path(__file__).parent.parent / "data" templates_dir = cli_data_dir / "templates" scheme_path = c_state_dir / "scheme.json" -scheme_data_path = cli_data_dir / "schemes" +scheme_data_dir = cli_data_dir / "schemes" +scheme_cache_dir = c_cache_dir / "schemes" + +last_wallpaper_path = c_state_dir / "wallpaper/last.txt" +wallpaper_thumbnail_path = c_state_dir / "wallpaper/thumbnail.jpg" + + +def compute_hash(path: str) -> str: + sha = hashlib.sha256() + + with open(path, "rb") as f: + while chunk := f.read(8192): + sha.update(chunk) + + return sha.hexdigest() diff --git a/src/caelestia/utils/scheme.py b/src/caelestia/utils/scheme.py index c26d2f8..66cd697 100644 --- a/src/caelestia/utils/scheme.py +++ b/src/caelestia/utils/scheme.py @@ -1,7 +1,8 @@ import json from pathlib import Path -from caelestia.utils.paths import scheme_data_path, scheme_path +from caelestia.utils.material import get_colours_for_image +from caelestia.utils.paths import scheme_data_dir, scheme_path class Scheme: @@ -89,7 +90,7 @@ class Scheme: return self._colours def get_colours_path(self) -> Path: - return (scheme_data_path / self.name / self.flavour / self.mode).with_suffix(".txt") + return (scheme_data_dir / self.name / self.flavour / self.mode).with_suffix(".txt") def save(self) -> None: scheme_path.parent.mkdir(parents=True, exist_ok=True) @@ -118,7 +119,10 @@ class Scheme: self._mode = get_scheme_modes()[0] def _update_colours(self) -> None: - self._colours = read_colours_from_file(self.get_colours_path()) + if self.name == "dynamic": + self._colours = get_colours_for_image() + else: + self._colours = read_colours_from_file(self.get_colours_path()) def __str__(self) -> str: return f"Scheme(name={self.name}, flavour={self.flavour}, mode={self.mode}, variant={self.variant})" @@ -168,7 +172,7 @@ def get_scheme_names() -> list[str]: global scheme_names if scheme_names is None: - scheme_names = [f.name for f in scheme_data_path.iterdir() if f.is_dir()] + scheme_names = [f.name for f in scheme_data_dir.iterdir() if f.is_dir()] scheme_names.append("dynamic") return scheme_names @@ -182,7 +186,7 @@ def get_scheme_flavours() -> list[str]: if name == "dynamic": scheme_flavours = ["default", "alt1", "alt2"] else: - scheme_flavours = [f.name for f in (scheme_data_path / name).iterdir() if f.is_dir()] + scheme_flavours = [f.name for f in (scheme_data_dir / name).iterdir() if f.is_dir()] return scheme_flavours @@ -192,6 +196,9 @@ def get_scheme_modes() -> list[str]: if scheme_modes is None: scheme = get_scheme() - scheme_modes = [f.stem for f in (scheme_data_path / scheme.name / scheme.flavour).iterdir() if f.is_file()] + if scheme.name == "dynamic": + scheme_modes = ["light", "dark"] + else: + scheme_modes = [f.stem for f in (scheme_data_dir / scheme.name / scheme.flavour).iterdir() if f.is_file()] return scheme_modes diff --git a/src/caelestia/utils/theme.py b/src/caelestia/utils/theme.py index 3250ea3..d205fb1 100644 --- a/src/caelestia/utils/theme.py +++ b/src/caelestia/utils/theme.py @@ -115,7 +115,7 @@ def apply_btop(colours: dict[str, str]) -> None: def apply_colours(colours: dict[str, str], mode: str) -> None: apply_terms(gen_sequences(colours)) - apply_hypr(gen_conf(colours)) + apply_hypr(gen_conf(colours)) # FIXME: LAGGY apply_discord(gen_scss(colours)) apply_spicetify(colours, mode) apply_fuzzel(colours) -- cgit v1.2.3-freya