Skip to content

Commit

Permalink
feat: support hyprcursor (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: sgoudham <sgoudham@gmail.com>
  • Loading branch information
trowgundam and sgoudham committed May 31, 2024
1 parent 5fbec96 commit 28cb6d2
Show file tree
Hide file tree
Showing 55 changed files with 333 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build
run: nix build . -Lv
run: nix build . -L
- name: Add zips to release
run: gh release upload ${{ needs.release-please.outputs.tag_name }} result/*.zip
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
pngs/
releases/
result
hl/
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Build script:
Keefer Rourke <keefer.rourke@gmail.com>
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pkgs.catppuccin-cursors.mochaMauve
- [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 @@ -110,13 +112,15 @@ pkgs.catppuccin-cursors.mochaMauve
```

1. Run the following command(s) if you have just installed, if not then look
inside the [justfile](./justfile) to understand what commands are being run.
inside the [justfile](./justfile) to understand what commands are being run.

```bash
just all # Build all flavor-accent variants.
just flavor mocha # To build all variants under one single flavor.
just accents mocha blue # To build only the blue variant under mocha.
just accents mocha 'blue mauve peach' # To build only the blue, mauve, and peach variants under mocha.
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.
```

1. Extract built cursors in `./dist` to `$HOME/.icons` or `/usr/share/icons`.
Expand Down
101 changes: 93 additions & 8 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,79 @@ create_aliases() {
done <"$ALIASES"
}

create_hyprcursors() {
local src_dir="$1"
local out_dir="$2"
local theme_name="$3"
local hypr_dir="$out_dir/hyprcursors"
local filename dir cursor_dir base_name symlink target theme_comment

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

for file in "$src_dir"/*.svg; do
filename=$(basename -- "$file")

# hyprcursor doesn't care about sizes of svgs, can skip the '_24.svg' variant with no impact
if [[ "$filename" == *_24.svg ]]; then
continue
fi

# we want to put all of the `progress_01, progress_02, etc` into the same directory of `progress`
if [[ "$filename" == *-[0-9][0-9].svg ]]; then
dir="${filename%-[0-9][0-9].svg}"
else
dir="${filename%.svg}"
fi

cursor_dir="$hypr_dir/$dir"
[ -d "$cursor_dir" ] || mkdir -p "$cursor_dir"
cp -- "$file" "$cursor_dir"
done

for config in "$CONFIG_DIR"/*.hl; do
[ -f "$config" ] || continue

base_name="$(basename "$config" .hl)"
cursor_dir="$hypr_dir/$base_name"
[ -d "$cursor_dir" ] || continue
cp "$config" "$cursor_dir/meta.hl"
done

while read -r symlink target; do
cursor_dir="$out_dir/$target"
if [ -f "$cursor_dir"/meta.hl ]; then
echo "define_override = $symlink" >>"$cursor_dir"/meta.hl
fi
done <"$ALIASES"

theme_comment="$(grep Comment "$src_dir"/index.theme)"
cat >"$out_dir"/manifest.hl <<-EOM
name = ${theme_name%-cursors}
description = ${theme_comment#Comment=}
version = "v0.2.1" # x-release-please-version
cursors_directory = hyprcursors
EOM
}

compile_hyprcursors() {
local hl_dir="$1"
local out_dir="$2"
local theme_name="$(basename "$1")"
local compile_dir="$1/../theme_${theme_name%-cursors}"

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

hyprcursor-util -c "$hl_dir" >/dev/null
cp -a "$compile_dir/." "$out_dir/"
}

SCRIPT_DIR="$(dirname "$0")"
SRC_DIR="$SCRIPT_DIR/src"
OUT_DIR="$SCRIPT_DIR/dist"
PNG_DIR="$SCRIPT_DIR/pngs"
BUILD_DIR="$SCRIPT_DIR/build"
HL_DIR="$SCRIPT_DIR/hl"
CONFIG_DIR="$SRC_DIR/config"

AUTHORS="$SCRIPT_DIR/AUTHORS"
Expand All @@ -71,18 +139,18 @@ 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:v" option; do
while getopts "f:a:h" option; do
case $option in
f)
FLAVOR="$OPTARG"
;;
a)
ACCENTS="$OPTARG"
;;
v)
DEBUG=1
echo "[DEBUG] - Debug logging enabled"
h)
HYPRCURSOR=1
;;
\?)
echo "Invalid option: -$OPTARG"
Expand All @@ -92,12 +160,16 @@ while getopts "f:a:v" 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 inkscape commands..."
for accent in $ACCENTS; do
theme_name="catppuccin-$FLAVOR-$accent-cursors"
theme_src_dir="$SRC_DIR/$theme_name"
theme_build_dir="$BUILD_DIR/$theme_name"
theme_out_dir="$OUT_DIR/$theme_name"
theme_png_dir="$PNG_DIR/$theme_name"

Expand All @@ -106,14 +178,13 @@ done
echo "[INFO] - Generating inkscape commands complete"

echo "[INFO] - Converting SVGs to PNGs..."
inkscape --shell <<< ${INKSCAPE_COMMANDS} &> /dev/null
inkscape --shell <<<${INKSCAPE_COMMANDS} &>/dev/null
echo "[INFO] - Converting SVGs to PNGs complete"

echo "[INFO] - Converting to x11cursor & creating aliases..."
for accent in $ACCENTS; do
theme_name="catppuccin-$FLAVOR-$accent-cursors"
theme_src_dir="$SRC_DIR/$theme_name"
theme_build_dir="$BUILD_DIR/$theme_name"
theme_out_dir="$OUT_DIR/$theme_name"
theme_png_dir="$PNG_DIR/$theme_name"

Expand All @@ -125,3 +196,17 @@ for accent in $ACCENTS; do
cp -f "$LICENSE" "$theme_out_dir"
done
echo "[INFO] - Converting to x11cursor & creating aliases complete"

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

create_hyprcursors "$theme_src_dir" "$theme_hl_dir" "$theme_name"
compile_hyprcursors "$theme_hl_dir" "$theme_out_dir"
done
echo "[INFO] - Generating hyprcursor theme complete"
fi
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stdenvNoCC.mkDerivation {
runHook preBuild
patchShebangs .
just all
just all_with_hyprcursor
just zip
runHook postBuild
Expand Down
24 changes: 16 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ _default:

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

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

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

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

# Generate a single flavor with specific accents. E.g. "build mocha 'blue'"
accents f a:
# Generate a single flavor with accents, defaults to all accents
build f a=accents:
./build -f {{f}} -a '{{a}}'

# Generate a single flavor with all accents
flavor f:
./build -f {{f}} -a "{{accents}}"
# 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 (flavor "latte") (flavor "frappe") (flavor "macchiato") (flavor "mocha")
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")

3 changes: 2 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"release-type": "simple",
"draft-pull-request": true,
"extra-files": [
{ "type": "generic", "path": "README.md" }
{ "type": "generic", "path": "README.md" },
{ "type": "generic", "path": "build" }
]
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/config/alias.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, alias.svg
4 changes: 4 additions & 0 deletions src/config/all-scroll.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, all-scroll.svg
4 changes: 4 additions & 0 deletions src/config/bottom_left_corner.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.1875
hotspot_y = 0.78125
define_size = 64, bottom_left_corner.svg
4 changes: 4 additions & 0 deletions src/config/bottom_right_corner.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.78125
hotspot_y = 0.78125
define_size = 64, bottom_right_corner.svg
4 changes: 4 additions & 0 deletions src/config/bottom_side.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.65625
define_size = 64, bottom_side.svg
4 changes: 4 additions & 0 deletions src/config/cell.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, cell.svg
4 changes: 4 additions & 0 deletions src/config/center_ptr.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.21875
define_size = 64, center_ptr.svg
4 changes: 4 additions & 0 deletions src/config/col-resize.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, col-resize.svg
4 changes: 4 additions & 0 deletions src/config/color-picker.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.1875
hotspot_y = 0.78125
define_size = 64, color-picker.svg
4 changes: 4 additions & 0 deletions src/config/context-menu.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, context-menu.svg
4 changes: 4 additions & 0 deletions src/config/copy.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, copy.svg
4 changes: 4 additions & 0 deletions src/config/crosshair.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, crosshair.svg
4 changes: 4 additions & 0 deletions src/config/default.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, default.svg
4 changes: 4 additions & 0 deletions src/config/dnd-move.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, dnd-move.svg
4 changes: 4 additions & 0 deletions src/config/dnd-no-drop.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, dnd-no-drop.svg
4 changes: 4 additions & 0 deletions src/config/down-arrow.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.75
define_size = 64, down-arrow.svg
4 changes: 4 additions & 0 deletions src/config/draft.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.1875
hotspot_y = 0.46875
define_size = 64, draft.svg
4 changes: 4 additions & 0 deletions src/config/fleur.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, fleur.svg
4 changes: 4 additions & 0 deletions src/config/help.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, help.svg
4 changes: 4 additions & 0 deletions src/config/left-arrow.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.21875
hotspot_y = 0.46875
define_size = 64, left-arrow.svg
4 changes: 4 additions & 0 deletions src/config/left_side.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.28125
hotspot_y = 0.46875
define_size = 64, left_side.svg
4 changes: 4 additions & 0 deletions src/config/no-drop.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.0625
hotspot_y = 0.0625
define_size = 64, no-drop.svg
4 changes: 4 additions & 0 deletions src/config/not-allowed.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, not-allowed.svg
4 changes: 4 additions & 0 deletions src/config/openhand.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.46875
define_size = 64, openhand.svg
4 changes: 4 additions & 0 deletions src/config/pencil.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.1875
hotspot_y = 0.78125
define_size = 64, pencil.svg
4 changes: 4 additions & 0 deletions src/config/pirate.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.46875
hotspot_y = 0.3125
define_size = 64, pirate.svg
4 changes: 4 additions & 0 deletions src/config/pointer.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resize_algorithm = bilinear
hotspot_x = 0.40625
hotspot_y = 0.1875
define_size = 64, pointer.svg
Loading

0 comments on commit 28cb6d2

Please sign in to comment.