Skip to content
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

shuffle random wallpaper #194

Open
aloispichler opened this issue Aug 24, 2024 · 11 comments
Open

shuffle random wallpaper #194

aloispichler opened this issue Aug 24, 2024 · 11 comments

Comments

@aloispichler
Copy link

aloispichler commented Aug 24, 2024

To randomly pick (shuffle) a wallpaper out of a set of wallpapers, I had

exec-once=swaybg -i $(shuf -n1 -e /usr/share/backgrounds/xfce/ArchSimple.png /usr/share/backgrounds/xfce/arch2024.jpg /usr/share/backgrounds/xfce/arch2023.jpg /usr/share/backgrounds/xfce/arch10.jpg)

How can this be accomplished with hyprpaper?
I want to avoid preloading all.

@vaxerski
Copy link
Member

edit the config with something like sed and then launch?

@jerilMJ
Copy link

jerilMJ commented Sep 2, 2024

Just adding a working example snippet from my config.

$SCRIPTS_DIR/pick_wallpaper.sh:

# Pick random wallpaper
random_pick=$(find "$wp_dir" -type f -name "*.png" -o -name "*.jpg" | shuf -n1)
# Replace the placeholder in template and save to .conf file
sed -e "s~<wp>~${random_pick}~g" $conf_dir/templates/hyprpaper.template > $conf_dir/hyprpaper.conf

$conf_dir/templates/hyprpaper.template:

$wp = <wp>
preload = $wp
wallpaper = , $wp

then just exec-once it

exec-once = $SCRIPTS_DIR/pick_wallpaper.sh && hyprpaper

@KobKobson
Copy link

@jerilMJ thanks for that simple but effective solution.

Simple keybinding to load random wallpaper in hyprland.conf:

bind = $mainMod, W, exec, pkill hyprpaper && $pickWallpaper && hyprpaper

@fxzzi
Copy link

fxzzi commented Feb 3, 2025

An extremely simple script could do this for you:

#!/usr/bin/env bash

WALLPAPER_DIR="$HOME/walls/images/"
CURRENT_WALL=$(hyprctl hyprpaper listloaded)

# Get a random wallpaper that is not the current one
WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$(basename "$CURRENT_WALL")" | shuf -n 1)

# Apply the selected wallpaper
hyprctl hyprpaper reload ,"$WALLPAPER"

no need to modify the config or preload anything or restart hyprpaper.

@KobKobson
Copy link

KobKobson commented Feb 8, 2025

That's a good solution, if you don't want the change to be persistent.

jerilMJ's solution is on point for changing the default wallpaper as the change is persistent after restart.

@fxzzi
Copy link

fxzzi commented Feb 8, 2025

does that not defeat the purpose of it being randomised? If you were to save the wallpaper isn't that just a less convenient wallpaper picker?

@KobKobson
Copy link

No, since I like to pick a random wallpaper from time to time, but not after every reboot.
That way I can choose the time when I want to change things up a bit, not the next update requiring a reboot.

@fxzzi
Copy link

fxzzi commented Feb 8, 2025

ok, then you can pick a wallpaper, symlink it somewhere like ~/.local/state/wallpaper and have hyprpaper load from that path instead. then it will save across reboots and until you manually randomize the wallpaper again. a script like this should work (untested):

#!/usr/bin/env bash

WALLPAPER_DIR="$HOME/walls/images/"
WALL_LOC="$XDG_STATE_HOME/wallpaper"

# Get a random wallpaper that is not the current one
WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$(basename "$(readlink -e $WALL_LOC)")" | shuf -n 1)

# symlink somewhere
ln -sf $WALLPAPER $WALL_LOC

# Apply the selected wallpaper
hyprctl hyprpaper reload ,"$WALLPAPER"

@KobKobson
Copy link

You really don't like the idea of modifying the config and restarting hyprpaper hahaha
Thanks for the tip, looks promising.

@fxzzi
Copy link

fxzzi commented Feb 8, 2025

you're right xd

sed'ing the config file and then restarting hyprpaper is just really hacky tbh. I assume you lose the nice animation when switching wallpapers if you did it like that. I mean if it works for you then sure, go for it, but imo there are better methods than sed'ing and restarting

@KobKobson
Copy link

Yeah, you're right, reloading looks like the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants