Browse Source

Feat: Add ability to switch cursors

pull/151/head
KKV9 2 years ago
parent
commit
dead8aaab6
  1. 112
      config/hypr/scripts/Cursors.sh

112
config/hypr/scripts/Cursors.sh

@ -0,0 +1,112 @@
#!/bin/bash
# This script will change the cursor theme
# Directory for user configurations
cDIR="$HOME/.config/hypr/UserConfigs"
# Directory for icons
iDIR="$HOME/.config/swaync/images"
# Create symlinks for all cursor themes
for CURSORS in $(find /usr/share/icons -type d -name "cursors" | awk -F/ '{print $(NF-1)}'); do
DIRECTORY=$HOME/.icons/$CURSORS
if [ ! -d "$DIRECTORY" ]; then
ln -s "/usr/share/icons/$CURSORS" "$HOME/.icons/$CURSORS"
fi
done
# Get list of cursor themes. Select one from the list
cursor=$(find /usr/share/icons $HOME/.icons -type d -name "cursors" | awk -F/ '{print $(NF-1)}' | rofi -dmenu -config ~/.config/rofi/config-long.rasi)
# Exit if a cursor theme was not selected
if [ -z "$cursor" ]; then
exit 0
fi
# Notify instructions
notify-send -u low "Default cursor size is 24"
notify-send -u low "Select cursor size"
# 1-100. Select a size from the list
size=$(seq 100 | rofi -dmenu -config ~/.config/rofi/config-long.rasi)
# Exit if a size was not selected
if [ -z "$size" ]; then
exit 0
fi
# Set the cursor theme with hyprctl
hyprctl setcursor $cursor $size
# Set the cursor theme with gsettings
gsettings set org.gnome.desktop.interface cursor-theme $cursor >/dev/null 2>&1 &
gsettings set org.gnome.desktop.interface cursor-size $size >/dev/null 2>&1 &
# Set the cursor size environment variable
if ! grep -q "env = XCURSOR_SIZE,*" $cDIR/ENVariables.conf; then
echo "
# CURSOR_SIZE - Generated by Cursors.sh
env = XCURSOR_SIZE,$size" >>"$cDIR/ENVariables.conf"
else
sed -i "s/^env = XCURSOR_SIZE.*/env = XCURSOR_SIZE,$size/" $cDIR/ENVariables.conf
fi
# Create config directories if they don't exist
mkdir -p $HOME/.config/gtk-3.0 $HOME/.config/xsettingsd $HOME/.config/gtk-4.0 $HOME/.icons/default
# Set the gtk config files
config1="$HOME/.config/gtk-3.0/settings.ini"
config2="$HOME/.config/gtk-4.0/settings.ini"
if grep -q ".gtkrc-2.0.mine" $HOME/.gtkrc-2.0; then
config3="$HOME/.gtkrc-2.0.mine"
else
config3="$HOME/.gtkrc-2.0"
fi
configs=($config1 $config2 $config3)
# Set the cursor theme in the gtk config files
for config in "${configs[@]}"; do
if $config != $config3; then
if ! grep -q "\[Settings\]" $config; then
echo "[Settings]" >>$config
fi
fi
if grep -q "gtk-cursor-theme-name" $config; then
sed -i "s/^gtk-cursor-theme-name=.*/gtk-cursor-theme-name=$cursor/" $config
else
echo "gtk-cursor-theme-name=$cursor" >>$config
fi
if grep -q "gtk-cursor-theme-size" $config; then
sed -i "s/^gtk-cursor-theme-size=.*/gtk-cursor-theme-size=$size/" $dir
else
echo "gtk-cursor-theme-size=$size" >>$config
fi
done
# This file requires double quotes around the cursor theme
if grep -q "gtk-cursor-theme-name" $config3; then
sed -i "s/^gtk-cursor-theme-name=.*/gtk-cursor-theme-name=\"$cursor\"/" $config3
fi
# Set the cursor theme in xsettingsd
if grep -q "Gtk/CursorThemeName" $HOME/.config/xsettingsd/xsettingsd.conf; then
sed -i "s/^Gtk\/CursorThemeName.*/Gtk\/CursorThemeName \"$cursor\"/" $HOME/.config/xsettingsd/xsettingsd.conf
else
echo "Gtk/CursorThemeName \"$cursor\"" >>$HOME/.config/xsettingsd/xsettingsd.conf
fi
# Generate the default cursor config file
echo "#Generated by Cursors.sh
[Icon Theme]
Name=Default
Comment=Default Cursor Theme
Inherits=$cursor" >$HOME/.icons/default/index.theme
# Notify
rofi -e "Cursor theme changed to:
Theme: $cursor
Size: $size
Close this window then try move your cursor over waybar
You may need to reload some applications to see the changes"
notify-send -u low -i "$iDIR/bell.png" "Cursor theme changed"
Loading…
Cancel
Save