Update theme engine
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,2 +0,0 @@
|
|||||||
**/wallpapers/*.jpg filter=lfs diff=lfs merge=lfs -text
|
|
||||||
**/wallpapers/*.png filter=lfs diff=lfs merge=lfs -text
|
|
@@ -11,6 +11,7 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
hmConfig = config.home-manager.users.${user};
|
hmConfig = config.home-manager.users.${user};
|
||||||
|
|
||||||
themeSwww = lib.meta.getExe (
|
themeSwww = lib.meta.getExe (
|
||||||
pkgs.writeShellApplication {
|
pkgs.writeShellApplication {
|
||||||
name = "theme-swww";
|
name = "theme-swww";
|
||||||
@@ -18,7 +19,13 @@ let
|
|||||||
coreutils
|
coreutils
|
||||||
swww
|
swww
|
||||||
];
|
];
|
||||||
text = "exec swww img \"${hmConfig.theme.configDir}/wallpaper\"";
|
text = ''
|
||||||
|
if [[ -L "${hmConfig.theme.configDir}"/wallpaper ]]; then
|
||||||
|
exec swww img "${hmConfig.theme.configDir}"/wallpaper
|
||||||
|
elif [[ -f "${hmConfig.theme.configDir}"/color ]]; then
|
||||||
|
exec swww clear "$(<"${hmConfig.theme.configDir}"/color)"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
|
@@ -8,20 +8,24 @@
|
|||||||
let
|
let
|
||||||
cfg = config.theme;
|
cfg = config.theme;
|
||||||
|
|
||||||
wallpaper = pkgs.copyPathToStore cfg.wallpaper;
|
|
||||||
|
|
||||||
init = pkgs.writeShellApplication {
|
init = pkgs.writeShellApplication {
|
||||||
name = "theme-init";
|
name = "theme-init";
|
||||||
runtimeInputs = with pkgs; [ matugen ];
|
runtimeInputs = with pkgs; [ matugen ];
|
||||||
text = ''
|
text = ''
|
||||||
[[ ! -d "${cfg.configDir}" ]] && mkdir -p "${cfg.configDir}"
|
mkdir -p "${cfg.configDir}"
|
||||||
[[ ! -L "${cfg.configDir}"/wallpaper ]] && ln -sf "${wallpaper}" "${cfg.configDir}"/wallpaper
|
|
||||||
[[ ! -f "${cfg.configDir}"/mode ]] && echo "${cfg.mode}" > "${cfg.configDir}"/mode
|
|
||||||
|
|
||||||
matugen image "${cfg.configDir}/wallpaper" \
|
[[ ! -L "${cfg.configDir}"/wallpaper ]] && [[ ! -f "${cfg.configDir}"/color ]] && echo "#000000" > "${cfg.configDir}"/color
|
||||||
--type scheme-${cfg.flavour} \
|
[[ ! -f "${cfg.configDir}"/mode ]] && echo "dark" > "${cfg.configDir}"/mode
|
||||||
--mode "$(cat "${cfg.configDir}/mode")" \
|
[[ ! -f "${cfg.configDir}"/flavor ]] && echo "tonal-spot" > "${cfg.configDir}"/flavor
|
||||||
--contrast ${builtins.toString cfg.contrast}
|
[[ ! -f "${cfg.configDir}"/contrast ]] && echo "0" > "${cfg.configDir}"/contrast
|
||||||
|
|
||||||
|
flags=(--mode "$(<"${cfg.configDir}/mode")" --type "scheme-$(<"${cfg.configDir}/flavor")" --contrast "$(<"${cfg.configDir}/contrast")")
|
||||||
|
|
||||||
|
if [[ -L "${cfg.configDir}"/wallpaper ]]; then
|
||||||
|
matugen image "${cfg.configDir}"/wallpaper "''${flags[@]}"
|
||||||
|
elif [[ -f "${cfg.configDir}"/color ]]; then
|
||||||
|
matugen color hex "$(<"${cfg.configDir}"/color)" "''${flags[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
${cfg.initExtraConfig}
|
${cfg.initExtraConfig}
|
||||||
wait
|
wait
|
||||||
@@ -41,8 +45,6 @@ let
|
|||||||
runtimeInputs = with pkgs; [ coreutils ];
|
runtimeInputs = with pkgs; [ coreutils ];
|
||||||
runtimeEnv = {
|
runtimeEnv = {
|
||||||
CONFIG = cfg.configDir;
|
CONFIG = cfg.configDir;
|
||||||
DEFAULT_WALLPAPER = wallpaper;
|
|
||||||
DEFAULT_MODE = cfg.mode;
|
|
||||||
INIT = lib.meta.getExe init;
|
INIT = lib.meta.getExe init;
|
||||||
RELOAD = lib.meta.getExe reload;
|
RELOAD = lib.meta.getExe reload;
|
||||||
};
|
};
|
||||||
@@ -63,11 +65,6 @@ in
|
|||||||
description = "The path to the theme config directory.";
|
description = "The path to the theme config directory.";
|
||||||
};
|
};
|
||||||
|
|
||||||
wallpaper = mkOption {
|
|
||||||
type = path;
|
|
||||||
description = "The path to the default wallpaper";
|
|
||||||
};
|
|
||||||
|
|
||||||
pkg = mkOption {
|
pkg = mkOption {
|
||||||
type = package;
|
type = package;
|
||||||
default = theme;
|
default = theme;
|
||||||
@@ -120,36 +117,6 @@ in
|
|||||||
description = "Templates to fill with theme colors.";
|
description = "Templates to fill with theme colors.";
|
||||||
};
|
};
|
||||||
|
|
||||||
flavour = mkOption {
|
|
||||||
type = enum [
|
|
||||||
"content"
|
|
||||||
"expressive"
|
|
||||||
"fidelity"
|
|
||||||
"fruit-salad"
|
|
||||||
"monochrome"
|
|
||||||
"neutral"
|
|
||||||
"rainbow"
|
|
||||||
"tonal-spot"
|
|
||||||
];
|
|
||||||
default = "tonal-spot";
|
|
||||||
description = "The flavour of the theme.";
|
|
||||||
};
|
|
||||||
|
|
||||||
mode = mkOption {
|
|
||||||
type = enum [
|
|
||||||
"dark"
|
|
||||||
"light"
|
|
||||||
];
|
|
||||||
default = "dark";
|
|
||||||
description = "The default mode of the theme.";
|
|
||||||
};
|
|
||||||
|
|
||||||
contrast = mkOption {
|
|
||||||
type = numbers.between (-1) 1;
|
|
||||||
default = 0;
|
|
||||||
description = "Use a modified contrast.";
|
|
||||||
};
|
|
||||||
|
|
||||||
opacity = mkOption {
|
opacity = mkOption {
|
||||||
type = numbers.between 0 1;
|
type = numbers.between 0 1;
|
||||||
default = 1;
|
default = 1;
|
||||||
@@ -506,8 +473,6 @@ in
|
|||||||
percentageToHex = percentage: zeroPad (lib.trivial.toHexString (builtins.floor (percentage * 255)));
|
percentageToHex = percentage: zeroPad (lib.trivial.toHexString (builtins.floor (percentage * 255)));
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flavour = cfg.flavour;
|
|
||||||
contrast = builtins.toString cfg.contrast;
|
|
||||||
radius = builtins.toString cfg.radius;
|
radius = builtins.toString cfg.radius;
|
||||||
padding = builtins.toString cfg.padding;
|
padding = builtins.toString cfg.padding;
|
||||||
padding_double = builtins.toString (cfg.padding * 2);
|
padding_double = builtins.toString (cfg.padding * 2);
|
||||||
|
@@ -2,6 +2,9 @@ _theme_completion() {
|
|||||||
local options=(
|
local options=(
|
||||||
'-m[Set mode: 'light', 'dark', or 'toggle']:mode:(light dark toggle)'
|
'-m[Set mode: 'light', 'dark', or 'toggle']:mode:(light dark toggle)'
|
||||||
'-w[Set wallpaper file]:file:_files'
|
'-w[Set wallpaper file]:file:_files'
|
||||||
|
'-h[Set plain color (hex)]:hex color:'
|
||||||
|
'-f[Set flavor]:flavor:(content expressive fidelity fruit-salad monochrome neutral rainbow tonal-spot)'
|
||||||
|
'-c[Set contrast (-1 to 1)]:contrast:'
|
||||||
)
|
)
|
||||||
local curcontext="$curcontext" state line
|
local curcontext="$curcontext" state line
|
||||||
typeset -A opt_args
|
typeset -A opt_args
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
wallpaper=""
|
wallpaper=""
|
||||||
|
color=""
|
||||||
mode=""
|
mode=""
|
||||||
|
flavor=""
|
||||||
|
contrast=""
|
||||||
|
|
||||||
set_wallpaper() {
|
set_wallpaper() {
|
||||||
if [[ -f "$1" ]]; then
|
if [[ -f "$1" ]]; then
|
||||||
@@ -12,6 +15,37 @@ set_wallpaper() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_color() {
|
||||||
|
local re='^#?([A-Fa-f0-9]{6})$'
|
||||||
|
if [[ "$1" =~ $re ]]; then
|
||||||
|
color="$1"
|
||||||
|
else
|
||||||
|
echo "Invalid color format: $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_flavor() {
|
||||||
|
case "$1" in
|
||||||
|
content|expressive|fidelity|fruit-salad|monochrome|neutral|rainbow|tonal-spot)
|
||||||
|
flavor="$1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid flavor: $1"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
set_contrast() {
|
||||||
|
if [[ "$1" =~ ^-?[0-1](\.[0-9]+)?$ ]]; then
|
||||||
|
contrast="$1"
|
||||||
|
else
|
||||||
|
echo "Invalid contrast value: $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
toggle_mode() {
|
toggle_mode() {
|
||||||
if [[ "$(cat "$CONFIG"/mode)" = "light" ]]; then
|
if [[ "$(cat "$CONFIG"/mode)" = "light" ]]; then
|
||||||
mode="dark"
|
mode="dark"
|
||||||
@@ -21,37 +55,48 @@ toggle_mode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 [-m {light|dark|toggle}] [-w <file>]"
|
echo "Usage: $0 [-m {light|dark|toggle}] [-w <file>] [-h <hexcolor>] [-f <flavor>] [-c <contrast>]"
|
||||||
|
echo " Only one of -w (wallpaper) or -h (hex color) can be used."
|
||||||
|
echo " Valid flavors: content, expressive, fidelity, fruit-salad, monochrome, neutral, rainbow, tonal-spot"
|
||||||
|
echo " Contrast must be a number between -1 and 1"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
finish() {
|
finish() {
|
||||||
[[ -n "$wallpaper" ]] && ln -sf "$wallpaper" "$CONFIG"/wallpaper
|
[[ -n "$wallpaper" ]] && rm -f "$CONFIG"/color && ln -sf "$wallpaper" "$CONFIG"/wallpaper
|
||||||
|
[[ -n "$color" ]] && rm -f "$CONFIG"/wallpaper && echo "$color" > "$CONFIG"/color
|
||||||
[[ -n "$mode" ]] && echo "$mode" > "$CONFIG"/mode
|
[[ -n "$mode" ]] && echo "$mode" > "$CONFIG"/mode
|
||||||
|
[[ -n "$flavor" ]] && echo "$flavor" > "$CONFIG"/flavor
|
||||||
|
[[ -n "$contrast" ]] && echo "$contrast" > "$CONFIG"/contrast
|
||||||
|
|
||||||
"$INIT" > /dev/null
|
"$INIT" > /dev/null
|
||||||
"$RELOAD" > /dev/null
|
"$RELOAD" > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while getopts "m:w:" opt; do
|
while getopts "m:w:h:f:c:" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
m)
|
m)
|
||||||
case "$OPTARG" in
|
case "$OPTARG" in
|
||||||
light|dark)
|
light|dark) mode="$OPTARG" ;;
|
||||||
mode="$OPTARG"
|
toggle) toggle_mode ;;
|
||||||
;;
|
*) usage ;;
|
||||||
toggle)
|
|
||||||
toggle_mode
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
w)
|
w)
|
||||||
|
[[ -n "$color" ]] && usage
|
||||||
set_wallpaper "$OPTARG"
|
set_wallpaper "$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
h)
|
||||||
|
[[ -n "$wallpaper" ]] && usage
|
||||||
|
set_color "$OPTARG"
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
set_flavor "$OPTARG"
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
set_contrast "$OPTARG"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
user ? throw "user argument is required",
|
|
||||||
home ? throw "home argument is required",
|
|
||||||
}:
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
home-manager.users.${user}.theme.wallpaper = ../../../../../../../static/wallpapers/clouds.png;
|
|
||||||
}
|
|
@@ -87,7 +87,6 @@ in
|
|||||||
(import ./configs/console/syncthing { inherit user home; })
|
(import ./configs/console/syncthing { inherit user home; })
|
||||||
|
|
||||||
(import ./configs/gui/obsidian { inherit user home; })
|
(import ./configs/gui/obsidian { inherit user home; })
|
||||||
(import ./configs/gui/theme { inherit user home; })
|
|
||||||
(import ./configs/gui/vscode { inherit user home; })
|
(import ./configs/gui/vscode { inherit user home; })
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
user ? throw "user argument is required",
|
|
||||||
home ? throw "home argument is required",
|
|
||||||
}:
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
home-manager.users.${user}.theme.wallpaper = ../../../../../../../static/wallpapers/snow.jpg;
|
|
||||||
}
|
|
@@ -87,7 +87,6 @@ in
|
|||||||
(import ./configs/console/viya4-orders-cli { inherit user home; })
|
(import ./configs/console/viya4-orders-cli { inherit user home; })
|
||||||
|
|
||||||
(import ./configs/gui/obsidian { inherit user home; })
|
(import ./configs/gui/obsidian { inherit user home; })
|
||||||
(import ./configs/gui/theme { inherit user home; })
|
|
||||||
(import ./configs/gui/vscode { inherit user home; })
|
(import ./configs/gui/vscode { inherit user home; })
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:a02be2cc6471cbb35f1a0ec657581578fe2e9fc2c8f2e1b0769b21f65dcfadec
|
|
||||||
size 4656195
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:63d92b63e616073e074684d756779b4491245ebc4c6fad63d87a02def12880a1
|
|
||||||
size 319291
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:eab8229ea4b6d29c3ee2ad601b09f883bc1d4b2ca555a411cb7b9b48fa0153d4
|
|
||||||
size 2446726
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:435df84b9561fd8453ec0790f500a7c8035da8a3618aa12c1c9ef065358f88a3
|
|
||||||
size 4160621
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:4972b203699c641c43876b464962ac0934a6cdd521d33b33365afecfa760e4bb
|
|
||||||
size 1005842
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:1a2962ac70c824d6f1baa3d642490454b1be7fa4e3c91742c75238d72713c7b4
|
|
||||||
size 5570903
|
|
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:f965bd8e58c02d3ddebfe87e129ebe7934bc169bdfc723ae61fe6a67c1b00860
|
|
||||||
size 944602
|
|
Reference in New Issue
Block a user