Skip to content

Commit

Permalink
fix: build hyprcursor with svgs (again) (#55)
Browse files Browse the repository at this point in the history
* feat: build hyprcursor with svgs

as mentioned in #53 (comment).

Effectively rewrite the hyprcursor build system to be data driven, reflecting the other formats. As a result dependency on `hyprcursor-util` & `xcur2png` is gone.

* scripts: remove hyprcursor specific commands

#55 (comment)

* fix: properly calculate hyprcursor hotspot

* chore: cleanup

removed unused items
fixed indents

* feat: generate manifest.hl from a template
  • Loading branch information
Covkie authored Dec 3, 2024
1 parent 652fa31 commit fc88cfb
Show file tree
Hide file tree
Showing 57 changed files with 147 additions and 370 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ cursor SVGs.
- [xcursorgen](https://wiki.archlinux.org/title/Xcursorgen) to generate the
cursors.
- [inkscape](https://wiki.inkscape.org/wiki/Inkscape) to convert SVGs to PNGs.
- **(Optional)** [hyprcursor](https://github.com/hyprwm/hyprcursor) to include
hyprcursor variants.
- **(Optional)** [just](https://github.com/casey/just) to easily run development
commands.

Expand All @@ -120,9 +118,7 @@ cursor SVGs.

```bash
just all # Build all flavor-accent variants.
just all_with_hyprcursor # Build all flavor-accent variants with hyprcursor support
just build mocha # To build all variants under one single flavor.
just build_with_hyprcursor mocha # To build all variants under one single flavor with hyprcursor support
just build mocha blue # To build only the blue variant under mocha.
just build mocha 'blue mauve peach' # To build only the blue, mauve, and peach variants under mocha.
```
Expand Down
69 changes: 6 additions & 63 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@ build_svgs() {
done
}

create_hyprcursors() {
local src_dir="$1"
local out_dir="$2"
local hypr_dir="$out_dir/hyprcursors"

[ -d "$out_dir" ] || mkdir -p "$out_dir"
[ -d "$hypr_dir" ] || mkdir -p "$hypr_dir"

hyprcursor-util -x "$src_dir" -o "$out_dir" >/dev/null
}

compile_hyprcursors() {
local hl_dir="$1"
local out_dir="$2"
local src_dir="$3"
local theme_name="$(basename "$1" | sed 's/extracted_//')"

[ -d "$hl_dir" ] || return 1
[ -d "$out_dir" ] || mkdir -p "$out_dir"

hyprcursor-util -c "$hl_dir" -o "$out_dir" >/dev/null
# For whatever reason, hyprcursor appends "Extracted Theme" to the end so we have to work around it
mv "$out_dir/theme_Extracted Theme/hyprcursors" "$out_dir/hyprcursors"
rm -rf "$out_dir/theme_Extracted Theme"

local theme_comment="$(grep Comment "$src_dir"/index.theme)"

cat >"$out_dir"/manifest.hl <<-EOM
name = ${theme_name%-cursors}
description = ${theme_comment#Comment=}
version = "v1.0.1" # x-release-please-version
cursors_directory = hyprcursors
EOM
}

SCRIPT_DIR="$(dirname "$0")"
SRC_DIR="$SCRIPT_DIR/src"
OUT_DIR="$SCRIPT_DIR/dist"
Expand All @@ -63,22 +28,17 @@ HL_DIR="$SCRIPT_DIR/hl"

AUTHORS="$SCRIPT_DIR/AUTHORS"
LICENSE="$SCRIPT_DIR/LICENSE"
ALIASES="$SRC_DIR/cursorList"

ACCENTS="blue dark flamingo green lavender light maroon mauve peach pink red rosewater sapphire sky teal yellow"
HYPRCURSOR=0

while getopts "f:a:h" option; do
while getopts "f:a:" option; do
case $option in
f)
FLAVOR="$OPTARG"
;;
a)
ACCENTS="$OPTARG"
;;
h)
HYPRCURSOR=1
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
Expand All @@ -87,41 +47,24 @@ while getopts "f:a:h" option; do
done
echo "[INFO] - Flavor: '$FLAVOR'"
echo "[INFO] - Accent(s): '$ACCENTS'"
if [ $HYPRCURSOR -eq 1 ]; then
echo "[INFO] - Building with hyprcursor: TRUE"
else
echo "[INFO] - Building with hyprcursor: FALSE"
fi

echo "[INFO] - Generating SVGs..."
build_svgs $SRC_DIR $FLAVOR
echo "[INFO] - Generating SVGs complete."

echo "[INFO] - Converting to xcursor & creating plasma svg cursors..."
echo "[INFO] - Building cursor formats; xcursor, hyprcursor, plasmasvg..."
for accent in $ACCENTS; do
theme_name="catppuccin-$FLAVOR-$accent-cursors"
theme_src_dir="$SVGS_DIR/$theme_name"
theme_out_dir="$OUT_DIR/$theme_name"
theme_png_dir="$PNG_DIR/$theme_name"
theme_hl_dir="$HL_DIR/$theme_name"

scripts/build-xcursor-plasmasvg "$theme_src_dir" "$theme_png_dir" "$theme_out_dir"
scripts/build-cursors "$theme_src_dir" "$theme_png_dir" "$theme_hl_dir" "$theme_out_dir"

cp -f "$AUTHORS" "$theme_out_dir"
cp -f "$LICENSE" "$theme_out_dir"
cp -f "$theme_src_dir/index.theme" "$theme_out_dir"
cp -f "$theme_hl_dir/manifest.hl" "$theme_out_dir"
done
echo "[INFO] - Converting to xcursor & creating plasma svg cursors complete"

if [[ $HYPRCURSOR == 1 ]]; then
echo "[INFO] - Generating hyprcursor theme..."
for accent in $ACCENTS; do
theme_name="catppuccin-$FLAVOR-$accent-cursors"
theme_src_dir="$OUT_DIR/$theme_name"
theme_hl_dir="$HL_DIR/extracted_$theme_name"
theme_out_dir="$OUT_DIR/$theme_name"

create_hyprcursors "$theme_src_dir" "$HL_DIR" "$theme_name"
compile_hyprcursors "$theme_hl_dir" "$theme_out_dir" "$theme_src_dir"
done
echo "[INFO] - Generating hyprcursor theme complete"
fi
echo "[INFO] - Finished building cursor formats; xcursor, hyprcursor, plasmasvg"
6 changes: 1 addition & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
inkscape,
just,
xcursorgen,
xcur2png,
hyprcursor,
zip,
catppuccin-whiskers,
python3,
Expand All @@ -30,9 +28,7 @@ stdenvNoCC.mkDerivation {
nativeBuildInputs = [
just
xcursorgen
xcur2png
inkscape
hyprcursor
zip
catppuccin-whiskers
python3
Expand All @@ -43,7 +39,7 @@ stdenvNoCC.mkDerivation {
runHook preBuild
patchShebangs .
just all_with_hyprcursor
just all
just zip
runHook postBuild
Expand Down
12 changes: 0 additions & 12 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ accents := "blue dark flamingo green lavender light maroon mauve peach pink red
clean:
rm -rf pngs/ hl/ dist/ releases/ svgs/

# Remove all hyprcursor related files
clean_hl:
rm -rf hl/

# Zip all directories inside of "./dist"
zip:
./scripts/create_zips
Expand All @@ -19,13 +15,5 @@ zip:
build f a=accents:
./build -f {{f}} -a '{{a}}'

# Generate a single flavor with accents with hyprcursor support, defaults to all accents
build_with_hyprcursor f a=accents: clean_hl
./build -f {{f}} -a '{{a}}' -h

# Generate all flavors with their accents
all: clean (build "latte") (build "frappe") (build "macchiato") (build "mocha")

# Generate all flavors with their accents with hyprcursor support
all_with_hyprcursor: clean (build_with_hyprcursor "latte") (build_with_hyprcursor "frappe") (build_with_hyprcursor "macchiato") (build_with_hyprcursor "mocha")

2 changes: 1 addition & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"draft-pull-request": true,
"extra-files": [
{ "type": "generic", "path": "README.md" },
{ "type": "generic", "path": "build" }
{ "type": "generic", "path": "src/templates/manifest.hl.tera" }
]
}
},
Expand Down
97 changes: 97 additions & 0 deletions scripts/build-cursors
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash

set -euo pipefail

BIN_DIR="$(dirname "${BASH_SOURCE[0]}")"
SRC_DIR="src"
HL_DIR="$3"
BUILD_DIR="$2"
RAWSVG_DIR="$1"
ALIASES="$SRC_DIR/cursorList"

NOMINAL_SIZE=24
REAL_SIZE=32
FRAME_TIME=30
SCALES="50 75 100 125 150 175 200 225 250 275 300"

# Make folders
for scale in $SCALES; do
mkdir -p "$BUILD_DIR/x$scale"
done
mkdir -p "$BUILD_DIR/config"

# Generate pixmaps
genPixmaps=""
for RAWSVG in ${RAWSVG_DIR}/*.svg; do
BASENAME=${RAWSVG##*/}
BASENAME=${BASENAME%.*}
genPixmaps+="file-open:${RAWSVG};"

for scale in $SCALES; do
DIR="$BUILD_DIR/x${scale}"
if [[ "${DIR}/${BASENAME}.png" -ot ${RAWSVG} ]]; then
genPixmaps+=" export-width:$((${REAL_SIZE} * scale / 100)); export-height:$((${REAL_SIZE} * scale / 100)); export-filename:${DIR}/${BASENAME}.png; export-do;"
fi
done
genPixmaps+=" file-close; "

done

inkscape --shell <<<${genPixmaps} &>/dev/null

# Generate cursor theme
OUTPUT=$4
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT/cursors"
mkdir -p "$OUTPUT/cursors_scalable"
mkdir -p "$HL_DIR"
$BIN_DIR/generate-metadata ${RAWSVG_DIR} "$BUILD_DIR" "$OUTPUT/cursors" "$OUTPUT/cursors_scalable" "$HL_DIR" ${NOMINAL_SIZE} ${REAL_SIZE} ${FRAME_TIME} ${SCALES}

# Generate shortcuts
while read ALIAS; do
FROM=${ALIAS% *}
TO=${ALIAS#* }

if [[ -e "$OUTPUT/cursors/$FROM" ]]; then
continue
fi

ln -s "$TO" "$OUTPUT/cursors/$FROM"
done <$ALIASES

while read ALIAS; do
FROM=${ALIAS% *}
TO=${ALIAS#* }

if [[ -e "$OUTPUT/cursors_scalable/$FROM" ]]; then
continue
fi

ln -s "$TO" "$OUTPUT/cursors_scalable/$FROM"
done <$ALIASES

while read ALIAS; do
FROM=${ALIAS% *}
TO=${ALIAS#* }

if [[ -e "$HL_DIR/$FROM" ]]; then
continue
fi

if [ -f "$HL_DIR/$TO/meta.hl" ]; then # need to ensure $TO is not a mapping itself
echo -ne "\ndefine_override = $FROM" >>$HL_DIR/$TO/meta.hl
else
grep=$(grep -m 1 "^$TO " $ALIASES)
TO=${grep#* }
echo -ne "\ndefine_override = $FROM" >>$HL_DIR/$TO/meta.hl
fi
done <$ALIASES

#zip up hyprcursor
mkdir -p "$OUTPUT/hyprcursors"
for dir in $HL_DIR/*; do
if [ -d "$dir" ]; then
dir_name=$(basename "$dir")
zip -qr "$OUTPUT/hyprcursors/$dir_name.hlc" -j "$dir/"
fi
done
69 changes: 0 additions & 69 deletions scripts/build-xcursor-plasmasvg

This file was deleted.

1 change: 0 additions & 1 deletion scripts/create_zips
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ for dir in */; do
zip -ry "../releases/$theme_name" "$theme_name"
done
cd ..

Loading

0 comments on commit fc88cfb

Please sign in to comment.