Wayland environment automatically switches wallpaper

Since switching to the window manager labwc, the desktop components have been customized by myself, and the more I use it, the more I like it.

But there are two things I am not very satisfied with:

    1. alt-tab switches the active window without thumbnails, making it inconvenient to quickly select after judgment;
    1. The wallpaper software cannot automatically switch (strictly speaking, this has nothing to do with labwc, the wallpaper software is chosen by you, swaybg).

The first problem is that I usually click the mouse on the status bar to select. The disadvantage is that my hands are away from the keyboard, which affects efficiency, which is barely acceptable.

This article solves the second problem. There are actually many wallpaper programs under wayland, each of which has a different focus and the original design intention of the author.

Listed below:

  • swaybg Choose a picture as a static wallpaper

  • swww has many stars and slightly powerful functions. It can use colors as wallpapers, perform various operations on a single picture, and control the effects during the switching process. But if you want to automatically switch, you need to write a separate script.

     1➜ ~ swww --help
     2A Solution to your Wayland Wallpaper Woes
     4Change what your monitors display as a background by controlling the swww daemon at runtime. Supports animated gifs and putting different stuff in different monitors. I also did my best to make it as resource
     5efficient as possible.
     7Note `swww` will only work in a compositor that implements the layer-shell protocol. Typically, wlr-roots based compositors.
     9Usage: swww <COMMAND>
    12clear Fills the specified outputs with the given color
    13img Sends an image (or animated gif) for the daemon to display
    14init Initializes the daemon
    15kill Kills the daemon
    16query Asks the daemon to print output information (names and dimensions)
    17help Print this message or the help of the given subcommand(s)
    20-h, --help
    21Print help (see a summary with '-h')
    23-V, --version
    24Print version
  • mpvpaper This is a bit outrageous. It uses mpv video playback as wallpaper. It may be suitable for corporate promotion and special groups.

  • wpaperd It is still under development. I personally choose this one because the logic is simple and clear. The key is to be able to set up a wallpaper directory (with wallpaper pictures in it) and randomly change wallpapers every once in a while. This is exactly the function I need, so I recommend this 👍.

1. Installation

  • Download and compile
1$ git clone https://github.com/danyspin97/wpaperd
2$ cd wpaperd
3$ cargo build --release
  • Put the program into the target PATH directory

After compilation, there will be two binary programs wpaperctl and wpaperd, which will be placed in /usr/local/bin for easy calling and execution.

The former is a control program and the latter is a daemon process, which conforms to the routine and everything feels familiar.

1cp target/release/wpaperctl target/release/wpaperd /usr/local/bin

2. Configuration file

After creating the configuration file directory, adjust the configuration. My example is as follows:

 1mkdir /home/mephisto/.config/wpaperd/
 2➜ ~ cd .config/wpaperd
 3➜ wpaperd pwd
 5➜ wpaperd cat wallpaper.toml
 7path = "/home/mephisto/Pictures/Wallpapers/"
 8duration = "30m"
 9sorting = "random"
12path = "/home/mephisto/Pictures/Wallpapers/"
13duration = "30m"
14sorting = "random"
17path = "/home/mephisto/Pictures/Wallpapers/"
18duration = "30m"
19sorting = "random"

The meaning of the above configuration is to randomly switch wallpapers every 30 minutes. The wallpaper source is the directory configured in path. Sorting also has non-random ascending and descending. I like randomness and gambling in life.

3. Set startup

In the labwc environment, it is very simple. Comment out swaybg and switch to the wpaperd daemon.

1➜ ~ head -n 5 ~/.config/labwc/autostart
2#Example autostart file
4# Set background color.
5# swaybg -i ~/Pictures/land.jpg >/dev/null 2>&1 &
6wpaperd >/dev/null 2>&1 &

Finally, just go to the Internet to find some good-looking wallpapers and put them into the wallpaper directory in path. The image formats support jpeg, png, webp, etc.

The final effect is that each screen randomly displays different wallpapers. Of course, you can also set it to have the same wallpaper on both screens.

In addition, you can view the currently displayed picture

1➜ ~ wpaperctl all-wallpapers
2eDP-1: "/home/mephisto/Pictures/Wallpapers/road.jpeg"
3DP-1: "/home/mephisto/Pictures/Wallpapers/th.jpeg"

For more ways to play, please check the documentation. Readers can try it themselves. I personally feel that the author understands users and has everything they need. The whole design is very simple and convenient.

4. Other knowledge

Curious babies may ask, how do you know the connection name of the monitor?

  • X11 environment, run xrandr

  • Wayland environment, run wlr-randr

If you are prompted that this command does not exist, you may need to install related software packages.

For example, in the wayland environment shown below, there are two screens eDP-1 and DP-1.

1sudo apt install wlr-randr
3~ wlr-randr | grep -i dp
4DP-1 "Dell Inc. DELL P2417H C9G5D83N67HI (DP-1)"
5eDP-1 "Chimei Innolux Corporation 0x14C0 (eDP-1)"

eDP means embedded display, the computer comes with a screen. DP means display, external display.

Programs such as the waybar status bar and dunst desktop notifications all have configuration items that allow you to select a screen. Once you know the name, you can configure which screen to display the target information on.

Lastmod: Friday, December 1, 2023

See Also: