diff --git a/.gitignore b/.gitignore index 25fc5844..29f82c58 100644 --- a/.gitignore +++ b/.gitignore @@ -250,3 +250,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +hyprcursor-build/ diff --git a/build.sh b/build.sh index 76894148..2fdf28f6 100755 --- a/build.sh +++ b/build.sh @@ -97,3 +97,5 @@ cd .. # Copying License File for 'bitmaps' cp LICENSE bitmaps/ zip -rv bin/bitmaps.zip bitmaps + +source ./hyprcursor-build.sh diff --git a/hyprcursor-build.sh b/hyprcursor-build.sh new file mode 100755 index 00000000..07f79492 --- /dev/null +++ b/hyprcursor-build.sh @@ -0,0 +1,37 @@ +# !/bin/bash + +rm -rf hyprcursor-build + +mkdir -p hyprcursor-build + +for theme in $(find ./themes -maxdepth 1 -type d | grep "Bibata-*"); do + theme_name=$(basename "$theme") + hyprcursor-util --extract "$theme" --output "hyprcursor-build" +done + +python3 recolor-svgs.py + +for theme in $(find ./hyprcursor-build -maxdepth 1 -type d | grep "extracted_Bibata-*"); do + theme_name=$(basename "$theme") + for shape in $(find "$theme/hyprcursors" -maxdepth 2 -type d); do + shape_name=$(basename "$shape") + svg_file=$(find "./hyprcursor-build/recolored_svgs/$theme_base" -name "$shape_name.svg" | grep "$shape_name") + theme_base=$(echo "$theme_name" | cut -d'_' -f2) + if [ -z "$svg_file" ]; then + if [ "$shape_name" == "wait" ]; then + svg_file=$(find "./hyprcursor-build/recolored_svgs/$theme_base/wait/" -name "*.svg") + elif [ "$shape_name" == "left_ptr_watch" ]; then + svg_file=$(find "./hyprcursor-build/recolored_svgs/$theme_namebase/left_ptr_watch/" -name "*.svg") + fi + fi + echo "$theme_base: $shape_name -> $svg_file" + if [ -z "$svg_file" ]; then + echo "No SVG file found for $theme_base: $shape_name" + exit 1 + fi + + # TODO: edit the meta.hl file + # TODO: copy the svg files to the extracted hyprcursor + + done +done \ No newline at end of file diff --git a/recolor-svgs.py b/recolor-svgs.py new file mode 100644 index 00000000..d10eda74 --- /dev/null +++ b/recolor-svgs.py @@ -0,0 +1,83 @@ +import os + + +class Renderer: + theme_name = None + input_folder = None + output_folder = None + colors = [] + + def __init__(self, input_folder, output_folder, theme_name, colors): + self.theme_name = theme_name + self.input_folder = input_folder + self.output_folder = output_folder + self.colors = colors + + +def main(): + render_file = "render.json" + renderers = [] + + with open(render_file, "r") as f: + lines = f.readlines() + for i in range(0, len(lines)): + if lines[i].strip().startswith("\"") and lines[i].strip().endswith("\": {"): + theme_name = lines[i].strip().strip("\"").strip("\": {") + if not theme_name.endswith("-Right"): + svgs_dir = lines[i + 1].replace("\"dir\": \"", "").replace("\",", "").strip() + output = "hyprcursor-build/recolored_svgs/" + theme_name + os.system("mkdir -p " + output) + colors = [] + color_1_match = lines[i+4].replace("{ \"match\": \"", "").split("\", \"replace\": \"")[0].strip() + color_1_replace = lines[i+4].split("\", \"replace\": \"")[1].replace('" },\n', "") + color_2_match = lines[i+4].replace("{ \"match\": \"", "").split("\", \"replace\": \"")[0].strip() + color_2_replace = lines[i+4].split("\", \"replace\": \"")[1].replace('" },\n', "") + color_3_match = lines[i+4].replace("{ \"match\": \"", "").split("\", \"replace\": \"")[0].strip() + color_3_replace = lines[i+4].split("\", \"replace\": \"")[1].replace('" },\n', "") + colors.append((color_1_match, color_1_replace)) + colors.append((color_2_match, color_2_replace)) + colors.append((color_3_match, color_3_replace)) + theme_type = theme_name.split("-")[2] + if theme_type == "Ice": + colors.append(("\"#0000FF\"", "\"#000000\"")) + else: + colors.append(("\"#0000FF\"", "\"#FFFFFF\"")) + renderers.append(Renderer(svgs_dir, output, theme_name, colors)) + + for renderer in renderers: + for root, dirsn, filesn in os.walk(renderer.input_folder): + for file in filesn: + if file.endswith(".svg"): + with open(os.path.join(root, file), "r") as f: + content = f.read() + for color in renderer.colors: + content = content.replace(color[0], color[1]) + with open(os.path.join(renderer.output_folder, file), "w") as f: + f.write(content) + for root, dirsn, filesn in os.walk(renderer.input_folder + "/wait"): + for file in filesn: + if file.endswith(".svg"): + os.system("mkdir -p " + renderer.output_folder + "/wait") + with open(os.path.join(root, file), "r") as f: + content = f.read() + for color in renderer.colors: + content = content.replace(color[0], color[1]) + with open(os.path.join(renderer.output_folder + "/wait", file), "w") as f: + f.write(content) + for root, dirsn, filesn in os.walk(renderer.input_folder + "/left_ptr_watch"): + for file in filesn: + if file.endswith(".svg"): + os.system("mkdir -p " + renderer.output_folder + "/left_ptr_watch") + with open(os.path.join(root, file), "r") as f: + content = f.read() + for color in renderer.colors: + content = content.replace(color[0], color[1]) + with open(os.path.join(renderer.output_folder + "/left_ptr_watch", file), "w") as f: + f.write(content) + + + + + +if __name__ == "__main__": + main() \ No newline at end of file