spmenu-wiki/Pywal integration with wallpaper-spmenu.md

94 lines
3.2 KiB
Markdown

# Pywal integration with wallpaper-spmenu
This wiki article goes through Pywal integration with
[wallpaper-spmenu](https://git.speedie.site/speedie/wallpaper-spmenu),
a tool used to set wallpapers on X or Wayland using spmenu (hence why
it's on this wiki). It also assumes that all your software
is set up to use Pywal. It will not be covered here.
Before you can do this, you must run `wallpaper-spmenu` once, to create
the wallpaperrc configuration file. This file is located in
`~/.config/wallpaper-spmenu/wallpaperrc` by default. If the file exists
you can continue.
What we want to do is append some extra lines to the `set_wallpaper.sh`
script. This script is the script that sets the wallpaper, and is usually
autostarted by your window manager, if you've set it up to be autostarted.
## Creating a post_write_script() hook function
Open the config file up in your favorite text editor. You need to add a
`post_write_script()` function to this file. This function as the name
implies executes whenever the `set_wallpaper.sh` has been changed. A
simple example function might look like this:
```Shell
post_write_script() {
cat << EOF >> "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
wal -nqi "$1"
}
```
This function simply adds `wal -nqi "$1"` to it. `$1` refers to the first
argument, which is going to be the path to the wallpaper that was set. I
would probably add some other things to this script, such as deleting the
Pywal cache before `wal -nqi "$1"`.
If you want to replicate the behaviour of the old `speedwm-swal` script,
you might want your function to look like this:
```Shell
post_write_script() {
cat << EOF >> "$WALLPAPER_CONFIG_DIR/set_wallpaper.sh"
rm -rf "$HOME/.cache/wal"
xrdb -remove
wal -nqi "$1"
xrdb ~/.cache/wal/colors.Xresources
command -v libspeedwm > /dev/null && \
pidof speedwm > /dev/null && \
libspeedwm --perform core_wm_reload
$WALLPAPER_CONFIG_DIR/postrun.sh
EOF
command -v speedwm > /dev/null && \
pidof speedwm > /dev/null && \
speedwm -s "Loading"
}
```
It should be noted that some of this is speedwm specific, and as such
should be deleted if you're using a different window manager/compositor.
## startpage integration
If you're using [startpage](https://git.speedie.site/speedie/startpage),
and wish to copy the wallpaper, you'll need to copy the script for your
chosen web browser to `~/.config/wallpaper-spmenu` and rename it to
`postrun.sh`.
Then add `$WALLPAPER_CONFIG_DIR/postrun.sh` to your `post_write_script()`
function before the `EOF`.
**NOTE: The script assumes that the startpage index is located at
~/.config/startpage/index.html. If it isn't, you MUST change the
PREFIX variable in the script.**
Do note that older versions of the startpage may set CWAL to
`$HOME/.config/speedwm/swal/CurrentWallpaper`.
If this is the case then you'll want to change it to
`$HOME/.config/wallpaper-spmenu/currentwallpaper`.
## speedwm dynamic reloading integration
To reload colors automatically, you should add
`xrdb ~/.cache/wal/colors.Xresources` and
`libspeedwm libspeedwm --perform core_wm_reload` to
the file. The libspeedwm line simply signals to speedwm that
it should attempt to reload .Xresources. The xrdb line loads
the Pywal colors, and must therefore be added before the
libspeedwm line.