-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcursor_converter.sh
More file actions
178 lines (144 loc) · 5.88 KB
/
cursor_converter.sh
File metadata and controls
178 lines (144 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\
# ( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )
# > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ <
#!/bin/bash
# Script to convert cursor SETS with PROPER HOTSPOT positioning
CURSOR_SOURCE="$HOME/Pictures/Cursors"
OUTPUT_DIR="$HOME/.icons"
TEMP_DIR="/tmp/cursor_conversion"
echo "========================================="
echo "Converting YOUR Cursor Sets to Themes"
echo "WITH AUTO-SCALING & PROPER HOTSPOTS"
echo "========================================="
if ! command -v xcursorgen &> /dev/null; then
echo "Installing xcursorgen..."
sudo pacman -S xorg-xcursorgen --noconfirm || {
echo "Please install xcursorgen manually:"
echo " sudo pacman -S xorg-xcursorgen"
exit 1
}
fi
if ! command -v convert &> /dev/null; then
echo "Installing ImageMagick (for image scaling)..."
sudo pacman -S imagemagick --noconfirm || {
echo "Please install ImageMagick manually:"
echo " sudo pacman -S imagemagick"
exit 1
}
fi
mkdir -p "$TEMP_DIR"
declare -A themes
for png_file in "$CURSOR_SOURCE"/*-default.png "$CURSOR_SOURCE"/*-hand.png; do
[ -f "$png_file" ] || continue
basename=$(basename "$png_file")
theme_name=$(echo "$basename" | sed -E 's/-(default|hand)\.png$//')
themes["$theme_name"]=1
done
if [ ${#themes[@]} -eq 0 ]; then
echo "ERROR: No cursor pairs found!"
echo ""
echo "Expected file naming:"
echo " themename-default.png (the arrow/pointer)"
echo " themename-hand.png (the clicking hand)"
exit 1
fi
echo "Found ${#themes[@]} cursor theme(s)"
echo ""
create_scaled_cursors() {
local source_png="$1"
local output_prefix="$2"
local sizes=(28 36 52 68)
for size in "${sizes[@]}"; do
convert "$source_png" -resize ${size}x${size} "$TEMP_DIR/${output_prefix}_${size}.png" 2>/dev/null
if [ $? -ne 0 ]; then
echo " ⚠️ Warning: Failed to scale $(basename "$source_png") to ${size}x${size}"
fi
done
}
for theme_name in "${!themes[@]}"; do
default_png="$CURSOR_SOURCE/${theme_name}-default.png"
hand_png="$CURSOR_SOURCE/${theme_name}-hand.png"
echo "Processing: $theme_name"
if [ ! -f "$default_png" ]; then
echo " ⚠️ Missing: ${theme_name}-default.png (skipping)"
continue
fi
if [ ! -f "$hand_png" ]; then
echo " ⚠️ Missing: ${theme_name}-hand.png (skipping)"
continue
fi
default_size=$(identify -format "%wx%h" "$default_png" 2>/dev/null)
hand_size=$(identify -format "%wx%h" "$hand_png" 2>/dev/null)
echo " Original sizes: default=$default_size, hand=$hand_size"
echo " Scaling to slightly larger cursor sizes (28, 36, 52, 68)..."
create_scaled_cursors "$default_png" "${theme_name}_default"
create_scaled_cursors "$hand_png" "${theme_name}_hand"
theme_dir="$OUTPUT_DIR/$theme_name"
mkdir -p "$theme_dir/cursors"
cat > "$theme_dir/index.theme" << EOF
[Icon Theme]
Name=$theme_name
Comment=Custom cursor theme with proper hotspot positioning
EOF
default_config="$TEMP_DIR/${theme_name}_default.cfg"
cat > "$default_config" << EOF
28 5 5 $TEMP_DIR/${theme_name}_default_28.png
36 6 6 $TEMP_DIR/${theme_name}_default_36.png
52 9 9 $TEMP_DIR/${theme_name}_default_52.png
68 12 12 $TEMP_DIR/${theme_name}_default_68.png
EOF
hand_config="$TEMP_DIR/${theme_name}_hand.cfg"
cat > "$hand_config" << EOF
28 9 5 $TEMP_DIR/${theme_name}_hand_28.png
36 12 6 $TEMP_DIR/${theme_name}_hand_36.png
52 18 9 $TEMP_DIR/${theme_name}_hand_52.png
68 24 12 $TEMP_DIR/${theme_name}_hand_68.png
EOF
default_names=(
"default" "left_ptr" "arrow" "top_left_arrow"
"wait" "watch" "progress"
"help" "question_arrow"
"cross" "crosshair" "tcross"
"move" "fleur" "size_all"
"n-resize" "s-resize" "e-resize" "w-resize"
"ne-resize" "nw-resize" "se-resize" "sw-resize"
"ns-resize" "ew-resize" "nesw-resize" "nwse-resize"
"col-resize" "row-resize"
"not-allowed" "forbidden" "no-drop"
"text" "xterm" "ibeam"
"zoom-in" "zoom-out"
"alias" "copy" "context-menu"
"cell" "vertical-text" "all-scroll"
)
hand_names=(
"pointer" "hand" "hand2" "pointing_hand" "hand1"
"grab" "openhand" "grabbing" "closedhand"
)
echo " Generating cursor files with proper hotspots..."
for cursor_name in "${default_names[@]}"; do
xcursorgen "$default_config" "$theme_dir/cursors/$cursor_name" 2>/dev/null
done
for cursor_name in "${hand_names[@]}"; do
xcursorgen "$hand_config" "$theme_dir/cursors/$cursor_name" 2>/dev/null
done
echo " ✓ Created: $theme_dir"
echo " - Default cursor: hotspot at tip (top-left)"
echo " - Hand cursor: hotspot at fingertip"
echo ""
done
echo "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
echo ""
echo "========================================="
echo "SUCCESS! Created ${#themes[@]} cursor themes"
echo "========================================="
for theme_name in "${!themes[@]}"; do
echo " ✓ $theme_name"
done
echo ""
echo "Your cursor themes are in: $OUTPUT_DIR"
echo ""
echo "Cursor sizes: 28px, 36px, 52px, 68px (slightly bigger than standard)"
# /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\
# ( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )
# > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ <