Skip to content

Feature/listen wallpaper changes #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions share/dotfiles/.config/hypr/conf/autostart.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ exec-once = ~/.config/hypr/scripts/xdg.sh
# Load Wallpaper
exec-once = ~/.config/hypr/scripts/wallpaper-restore.sh

# Listen wallpaper changes
exec=once = nohup sh ~/.config/hypr/conf/autostart.conf &

# Start Polkit
exec-once=/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

Expand Down
6 changes: 6 additions & 0 deletions share/dotfiles/.config/hypr/conf/monitors/1600x900.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -----------------------------------------------------
# Monitor Setup
# name: "1600x900"
# -----------------------------------------------------

monitor=,1600x900,auto,1
15 changes: 8 additions & 7 deletions share/dotfiles/.config/hypr/scripts/wallpaper-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ cachefile="$HOME/.config/ml4w/cache/current_wallpaper"
# Get current wallpaper
# -----------------------------------------------------

if [ -f $cachefile ] ;then
if [ -f $(cat $cachefile) ]; then
echo ":: Wallpaper $(cat $cachefile) exists"
wallpaper=$(cat $cachefile)
if [ -f "$cachefile" ]; then
sed -i "s|~|$HOME|g" "$cachefile"
wallpaper=$(cat $cachefile)
if [ -f $wallpaper ]; then
echo ":: Wallpaper $wallpaper exists"
else
echo ":: Wallpaper $(cat $cachefile) not exists."
echo ":: Wallpaper $wallpaper does not exist. Using default."
wallpaper=$defaultwallpaper
fi
else
echo ":: $cachefile not exists."
echo ":: $cachefile does not exist. Using default wallpaper."
wallpaper=$defaultwallpaper
fi

Expand All @@ -39,4 +40,4 @@ fi
# -----------------------------------------------------

echo ":: Setting wallpaper with source image $wallpaper"
waypaper --wallpaper $wallpaper
waypaper --wallpaper "$wallpaper"
25 changes: 25 additions & 0 deletions share/dotfiles/.config/ml4w/scripts/listen_wallpaper_change.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

CURRENT_WALLPAPER_PATH=$HOME/hyprland-setup/dotfiles/dot_config/ml4w/cache/current_wallpaper
CONFIG_FILE=$HOME/hyprland-setup/dotfiles/dot_config/waypaper/config.ini
LAST_WALLPAPER=""

get_current_wallpaper() {
grep -oP '^wallpaper\s*=\s*\K.*' "$CONFIG_FILE"
}

LAST_WALLPAPER=$(get_current_wallpaper)

inotifywait -m -e modify "$CONFIG_FILE" | while read -r path event file; do
CURRENT_WALLPAPER=$(get_current_wallpaper)

if [[ "$CURRENT_WALLPAPER" != "$LAST_WALLPAPER" ]]; then
LAST_WALLPAPER=$CURRENT_WALLPAPER
echo "El wallpaper ha cambiado: $CURRENT_WALLPAPER"
rm $CURRENT_WALLPAPER_PATH || true
touch $CURRENT_WALLPAPER_PATH || true
echo "$LAST_WALLPAPER" >> $CURRENT_WALLPAPER_PATH
sed -i "s|~|$HOME|g" "$CURRENT_WALLPAPER_PATH"
fi
sleep 0.01
done