Skip to content

Commit

Permalink
feat!: use breeze scripts to build xcursors & plasma scalable SVGs (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: isabel <[email protected]>
Co-authored-by: sgoudham <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2024
1 parent 6ed521a commit 3c9b12e
Show file tree
Hide file tree
Showing 241 changed files with 617 additions and 3,258 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ jobs:
- name: Set outputs
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Upload artifacts
- name: Upload artifacts (Latte)
uses: actions/upload-artifact@v4
with:
name: 'catppuccin-cursors-${{ steps.vars.outputs.sha_short }}'
path: result/*.zip
name: 'catppuccin-latte-cursors-${{ steps.vars.outputs.sha_short }}'
path: result/catppuccin-latte-*.zip
- name: Upload artifacts (Frappe)
uses: actions/upload-artifact@v4
with:
name: 'catppuccin-frappe-cursors-${{ steps.vars.outputs.sha_short }}'
path: result/catppuccin-frappe-*.zip
- name: Upload artifacts (Macchiato)
uses: actions/upload-artifact@v4
with:
name: 'catppuccin-macchiato-cursors-${{ steps.vars.outputs.sha_short }}'
path: result/catppuccin-macchiato-*.zip
- name: Upload artifacts (Mocha)
uses: actions/upload-artifact@v4
with:
name: 'catppuccin-mocha-cursors-${{ steps.vars.outputs.sha_short }}'
path: result/catppuccin-mocha-*.zip
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Cursors:
Alexey varfolomeev <[email protected]> - volantes-cursors
Kylie <https://github.com/covkie> - whiskers template conversion & optimizations

Colors:
elkrien <https://github.com/elkrien> - coloring cursors with Catppuccin palette
Expand All @@ -10,3 +11,4 @@ Build script:
Moded by Efus10n & jnzhng from https://github.com/keeferrourke/capitaine-cursors
Goudham Suresh <https://github.com/sgoudham> - script performance improvements
Jeffrey Geer <https://github.com/trowgundam> - hyprcursor support
Breeze script authors @ <https://invent.kde.org/plasma/breeze/-/blob/master/cursors/src/> build.sh #05b7c781f8bc7c167364a0278ab7d6861a8124c0 & generate_cursors #79402e44ca482dfff1bd348c0b3a895a5d485f33
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pkgs.catppuccin-cursors.mochaMauve

### Requirements

- [python3](https://www.python.org/downloads/) to execute scripts in the
codebase.
- [whiskers](https://github.com/catppuccin/whiskers) to generate the
cursor SVGs.
- [xcursorgen](https://wiki.archlinux.org/title/Xcursorgen) to generate the
Expand Down
103 changes: 4 additions & 99 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

set -eu

INKSCAPE_VERSION=$(inkscape --version 2>/dev/null | awk '/Inkscape[ ]/ {print $2; exit}')

build_svgs() {
local src_dir="$1"

Expand All @@ -21,79 +19,6 @@ build_svgs() {
done
}

# Generates the commands required for SVG -> PNG conversion
# These commands are to be used within inkscape's "shell" mode which allows for batch processing in a single inkscape process
generate_inkscape_commands() {
local src_dir="$1"
local out_dir="$2"
local file size bitmap_file

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

# shellcheck disable=SC2016
for file in "$src_dir"/*.svg; do
[ -f "$file" ] || continue
for size in 24 32 48 64; do
bitmap_file="${out_dir%/}/$(basename "$file" .svg)_${size}.png"
INKSCAPE_COMMANDS+="file-open:$file; export-filename:$bitmap_file; export-height:$size; export-width:$size; export-do; file-close;"
done
done
}

convert_to_x11cursor() {
local src_dir="$1"
local out_dir="$2"
local config base_name

[ -d "$src_dir" ] || return 1

if [ -d "$out_dir" ]; then
rm -rf "$out_dir"
fi

mkdir -p "$out_dir"

for config in "$CONFIG_DIR"/*.cursor; do
[ -f "$config" ] || continue
base_name="$(basename "$config" .cursor)"
xcursorgen -p "$src_dir" "$config" "$out_dir/$base_name"
done
}

write_scalable() {
local src_dir="$1"
local out_dir="$2"
local config base_name

[ -d "$src_dir" ] || return 1

if [ -d "$out_dir" ]; then
rm -rf "$out_dir"
fi

mkdir -p "$out_dir"

for config in "$CONFIG_DIR"/*.json; do
[ -f "$config" ] || continue
base_name="$(basename "$config" .json)"
cursor_out="$out_dir/$base_name"
mkdir "$cursor_out"
find "$src_dir" -type f \( -name "$base_name-??.svg" -o -name "$base_name.svg" \) ! -name "*_24.svg" -exec cp {} "$cursor_out" \;
cp "$config" "$cursor_out/metadata.json"
done
}

create_aliases() {
local out_dir="$1"
local symlink target

while read -r symlink target; do
[ -e "$out_dir/$symlink" ] && continue
ln -sf "$target" "$out_dir/$symlink"
done <"$ALIASES"
}

create_hyprcursors() {
local src_dir="$1"
local out_dir="$2"
Expand Down Expand Up @@ -135,14 +60,12 @@ OUT_DIR="$SCRIPT_DIR/dist"
PNG_DIR="$SCRIPT_DIR/pngs"
SVGS_DIR="$SCRIPT_DIR/svgs"
HL_DIR="$SCRIPT_DIR/hl"
CONFIG_DIR="$SRC_DIR/config"

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"
INKSCAPE_COMMANDS=""
HYPRCURSOR=0

while getopts "f:a:h" option; do
Expand Down Expand Up @@ -174,38 +97,20 @@ echo "[INFO] - Generating SVGs..."
build_svgs $SRC_DIR $FLAVOR
echo "[INFO] - Generating SVGs complete."

echo "[INFO] - Generating inkscape commands..."
echo "[INFO] - Converting to xcursor & creating plasma svg cursors..."
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"

generate_inkscape_commands "$theme_src_dir" "$theme_png_dir"
done
echo "[INFO] - Generating inkscape commands complete"

echo "[INFO] - Converting SVGs to PNGs..."
inkscape --shell <<<${INKSCAPE_COMMANDS} &>/dev/null
echo "[INFO] - Converting SVGs to PNGs complete"
scripts/build-xcursor-plasmasvg "$theme_src_dir" "$theme_png_dir" "$theme_out_dir"

echo "[INFO] - Converting to x11cursor & creating aliases..."
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"

convert_to_x11cursor "$theme_png_dir" "$theme_out_dir/cursors"
write_scalable "$theme_src_dir" "$theme_out_dir/cursors_scalable"
create_aliases "$theme_out_dir/cursors"
create_aliases "$theme_out_dir/cursors_scalable"

cp -f "$theme_src_dir/index.theme" "$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"
done
echo "[INFO] - Converting to x11cursor & creating aliases complete"
echo "[INFO] - Converting to xcursor & creating plasma svg cursors complete"

if [[ $HYPRCURSOR == 1 ]]; then
echo "[INFO] - Generating hyprcursor theme..."
Expand Down
6 changes: 5 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
hyprcursor,
zip,
catppuccin-whiskers,
python3,
python3Packages,
}:
stdenvNoCC.mkDerivation {
name = "catppuccin-cursors";
Expand All @@ -16,9 +18,9 @@ stdenvNoCC.mkDerivation {
fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) (
lib.fileset.unions [
./src
./scripts
./justfile
./build
./create_zips
./AUTHORS
./LICENSE
]
Expand All @@ -33,6 +35,8 @@ stdenvNoCC.mkDerivation {
hyprcursor
zip
catppuccin-whiskers
python3
python3Packages.pyside6
];

buildPhase = ''
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ _default:

accents := "blue dark flamingo green lavender light maroon mauve peach pink red rosewater sapphire sky teal yellow"

# Remove all files in the ".pngs/", ".hl/", "./dist" and "./releases" directories
# Remove all files in the ".pngs/", ".hl/", "./dist", "./releases" and "./svgs" directories
clean:
rm -rf pngs/ hl/ dist/ releases/
rm -rf pngs/ hl/ dist/ releases/ svgs/

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

# Zip all directories inside of "./dist"
zip:
./create_zips
./scripts/create_zips

# Generate a single flavor with accents, defaults to all accents
build f a=accents:
Expand Down
68 changes: 68 additions & 0 deletions scripts/build-xcursor-plasmasvg
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

set -euo pipefail

BIN_DIR="$( dirname "${BASH_SOURCE[0]}" )"
SRC_DIR="src"
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
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="${genPixmaps} export-width:$((${REAL_SIZE}*scale/100)); export-height:$((${REAL_SIZE}*scale/100)); export-filename:${DIR}/${BASENAME}.png; export-do;"
fi
done
if [ "$genPixmaps" != "file-open:${RAWSVG};" ]; then
inkscape --shell <<<${genPixmaps} &>/dev/null
fi

done

# Generate cursor theme
OUTPUT=$3
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT/cursors"
mkdir -p "$OUTPUT/cursors_scalable"
$BIN_DIR/generate-xcursor-plasmasvg ${RAWSVG_DIR} "$BUILD_DIR" "$OUTPUT/cursors" "$OUTPUT/cursors_scalable" ${NOMINAL_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
7 changes: 4 additions & 3 deletions create_zips → scripts/create_zips
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
set -eu

SCRIPT_DIR="$(dirname "$0")"
SRC_DIR="$SCRIPT_DIR/src"
OUT_DIR="$SCRIPT_DIR/dist"
ZIPS_DIR="$SCRIPT_DIR/releases"
ROOT="$(dirname $SCRIPT_DIR)"
SRC_DIR="$ROOT/src"
OUT_DIR="$ROOT/dist"
ZIPS_DIR="$ROOT/releases"

[ -d "$ZIPS_DIR" ] || mkdir -p "$ZIPS_DIR"

Expand Down
Loading

0 comments on commit 3c9b12e

Please sign in to comment.