Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dotfiles/.config/ml4w/scripts/ml4w-autostart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CACHE_FOLDER="$HOME/.cache/ml4w/hyprland-dotfiles"
CACHE_FILE="$CACHE_FOLDER/current_wallpaper"
DEFAULT_WALLPAPER="$HOME/.config/ml4w/wallpapers/default.jpg"
AWWW_CACHE_FOLDER="$HOME/.cache/awww"

# Colors for UI
RED='\033[0;31m'
Expand All @@ -19,15 +20,24 @@ error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
# Ensure that cache folder exists
mkdir -p $HOME/.cache

# Set Wallpaper
# Set ML4W Wallpaper Cache
mkdir -p $CACHE_FOLDER
if [ ! -f $CACHE_FILE ]; then
touch $CACHE_FILE
echo "$DEFAULT_WALLPAPER" > "$CACHE_FILE"
info "Cache file created"
fi

~/.config/ml4w/scripts/ml4w-wallpaper "$(cat $CACHE_FILE)" &
# Start awww-daemon
if command -v awww-daemon &> /dev/null; then
pgrep -x "awww-daemon" || awww-daemon & sleep 0.5
fi

# Check to see if awww cache exists; if not, call wallpaper script explicitly
[ -d "$AWWW_CACHE_FOLDER" ] && [ "$(ls -A "$AWWW_CACHE_FOLDER")" ] && HAS_AWWW_CACHE=true || HAS_AWWW_CACHE=false
if ! $HAS_AWWW_CACHE; then
~/.config/ml4w/scripts/ml4w-wallpaper "$(cat $CACHE_FILE)" &
fi

# Start Quickshell
killall qs
Expand Down
100 changes: 70 additions & 30 deletions dotfiles/.config/ml4w/scripts/ml4w-wallpaper
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
IMAGE_PATH=""
EFFECT=""
NOTIFICATIONS=false
SKIP=false
SKIP_WALLPAPER=false
SKIP_THEMING=false
MONITOR_OUTPUT=""
AWWW_CROP_GRAVITY="center"
CACHE_FOLDER="$HOME/.cache/ml4w/hyprland-dotfiles"
CACHE_FILE="$CACHE_FOLDER/current_wallpaper"
DEFAULT_WALLPAPER="$HOME/.config/ml4w/wallpapers/default.jpg"
Expand Down Expand Up @@ -46,9 +49,13 @@ show_help() {
echo "Optional Parameters:"
echo " --effect NAME Apply a specific wallpaper effect."
echo " --random FOLDER Select a random image from FOLDER."
echo " --notifications false Disable desktop notifications."
echo " --notifications BOOL Show or suppress desktop notifications (default false)."
echo " --help Show this help message and exit."
echo " --skip Will skip setting the wallpaper with awww."
echo " --skip-wallpaper Will skip setting the wallpaper with awww."
echo " --skip-theming Will skip updating OS themes based on new wallpaper."
echo " --skip Alias for \"--skip-wallpaper\"."
echo " --monitor Specify which input to apply wallpaper change (default applies to all outputs)"
echo " --crop-gravity Specify where to anchor wallpaper image in case cropping is needed (values from 'awww img --crop-gravity; default is center)"
echo ""
}

Expand All @@ -73,8 +80,12 @@ fi

while [[ $# -gt 0 ]]; do
case "$1" in
--skip)
SKIP=true
--skip|--skip-wallpaper)
SKIP_WALLPAPER=true
shift 1
;;
--skip-theming)
SKIP_THEMING=true
shift 1
;;
--effect)
Expand Down Expand Up @@ -111,9 +122,22 @@ while [[ $# -gt 0 ]]; do
--notifications)
if [[ "$2" == "false" ]]; then
NOTIFICATIONS=false
elif [[ "$2" == "true" ]]; then
NOTIFICATIONS=true
else
echo "Error: --notification accpeted values are true or false"
exit 1
fi
shift 2
;;
--monitor)
MONITOR_OUTPUT="$2"
shift 2
;;
--crop-gravity)
AWWW_CROP_GRAVITY="$2"
shift 2
;;
--help)
show_help
exit 0
Expand Down Expand Up @@ -159,16 +183,6 @@ if [ ! -d $CACHE_FOLDER ]; then
mkdir -p $CACHE_FOLDER
fi

# Ensure awww-daemon is running
if ! pgrep -x "awww-daemon" > /dev/null; then
mkdir -p "$HOME/.cache/awww"
info "Starting awww-daemon..."
awww-daemon &

# Give the daemon a brief moment to initialize before sending commands
sleep 1
fi

# Write image path to cache file
if [ ! -f "$CACHE_FILE" ]; then
touch "$CACHE_FILE"
Expand All @@ -193,17 +207,49 @@ if [ -f "$SETTINGS_WALLPAPER_EFFECT" ]; then
fi

# Set the Wallpaper
if [ "$SKIP" = true ]; then
if [ "$SKIP_WALLPAPER" = true ]; then
info "Setting wallpaper skipped"
else
info "Setting wallpaper: $IMAGE_PATH"
# Ensure awww-daemon is running
if ! pgrep -x "awww-daemon" > /dev/null; then
mkdir -p "$HOME/.cache/awww"
info "Starting awww-daemon..."
awww-daemon &

# Give the daemon a brief moment to initialize before sending commands
sleep 1
fi

# Crop gravity with awww is only supported on 0.12.1 and newer versions
read AWWW_MINOR AWWW_PATCH <<< $(awww --version | awk -F. '{print $2 " " $3}')
(( $AWWW_MINOR > 12 || $AWWW_MINOR == 12 && $AWWW_PATCH > 0 )) \
&& AWWW_CROP_GRAVITY_ARGS="--resize crop --crop-gravity $AWWW_CROP_GRAVITY" \
|| AWWW_CROP_GRAVITY_ARGS=""

# Update wallpaper
info "Setting wallpaper: $IMAGE_PATH${MONITOR_OUTPUT:+ on monitor $MONITOR_OUTPUT}"
info "Using wallpaper effect $SETTINGS_TRANSITION_EFFECT"
awww img "$IMAGE_PATH" --transition-type $SETTINGS_TRANSITION_EFFECT
awww img "$IMAGE_PATH" \
${MONITOR_OUTPUT:+-o $MONITOR_OUTPUT} \
$AWWW_CROP_GRAVITY_ARGS \
--transition-type $SETTINGS_TRANSITION_EFFECT
info "Wallpaper Updated: Successfully set $(basename "$IMAGE_PATH")${MONITOR_OUTPUT:+ on monitor $MONITOR_OUTPUT}"
fi

# If skipping theming, notify then exit
if "$SKIP_THEMING"; then
info "Updating theming skipped"
if [ "$SKIP_WALLPAPER" = false ]; then
send_notification \
"Wallpaper Update Completed" \
"Successfully updated wallpaper $(basename "$IMAGE_PATH")${MONITOR_OUTPUT:+ on output $MONITOR_OUTPUT}"
fi
exit 0
fi

# Detect Theme
SETTINGS_FILE="$HOME/.config/gtk-3.0/settings.ini"
THEME_PREF=$(grep -E '^gtk-application-prefer-dark-theme=' "$SETTINGS_FILE" | awk -F'=' '{print $2}')
THEME_PREF=$(grep -E '^gtk-application-prefer-dark-theme=' "$SETTINGS_FILE" | awk -F'=' '{print ($2 == 1 ? "dark" : "light")}')

# Determine matugen binary path
if [ -f $HOME/.cargo/bin/matugen ]; then
Expand All @@ -215,11 +261,7 @@ else
fi

# Execute matugen
if [ "$THEME_PREF" -eq 1 ]; then
$MATUGEN_BIN image "$IMAGE_PATH" --source-color-index 0 -m "dark"
else
$MATUGEN_BIN image "$IMAGE_PATH" --source-color-index 0 -m "light"
fi
$MATUGEN_BIN image "$IMAGE_PATH" --source-color-index 0 -m "$THEME_PREF"
info "Matugen updated"

# Update Quickshell theme
Expand Down Expand Up @@ -271,9 +313,6 @@ magick "$IMAGE_PATH" -gravity Center -extent 1:1 "$SQUARE_WALLPAPER"
info "$(basename "$SQUARE_WALLPAPER") created"

# Create rasi file
if [ ! -f $RASI_FILE ]; then
touch $RASI_FILE
fi
echo "* { current-image: url(\"$BLURRED_WALLPAPER\", height); }" > "$RASI_FILE"
info "$(basename "$RASI_FILE") written with $(basename "$BLURRED_WALLPAPER")"

Expand All @@ -284,6 +323,7 @@ info "$(basename "$RASI_FILE") written with $(basename "$BLURRED_WALLPAPER")"
# fi

# Notification
send_notification "Wallpaper Update Completed" "Successfully set and processed $(basename "$IMAGE_PATH")"
info "Wallpaper Updated: Successfully set $(basename "$IMAGE_PATH")"
exit 0
send_notification \
"Wallpaper Update Completed" \
"Successfully set and processed $(basename "$IMAGE_PATH")${MONITOR_OUTPUT:+ on monitor $MONITOR_OUTPUT}"
exit 0
Loading