So, Wayland is finally a major thing in the Linux Desktop world. And whether you like it or not, X11 is going to be phased out from all major distros sooner or later. (It will probably never die though.)
(Here comes some nostalgic bla bla, if you just want to know how to get screensavers from Xscreensaver in wayland, scroll down.)
I moved from xmonad to hyprland a few months back and after fiddling around a bit I felt right at home. (It is also nice to configure your window manager / wayland compositor in a language that can be understood without having a master in math)
But there is one thing bothering me: Screensavers. Or rather the lack of them.
I know, screensavers are a relic of the past, something from the 90s. Although there still are certain screens that can suffer from burn-in, we can just switch them off today. There is seldom a good technical reason to have them. But then again, even back in the day there always was just something artistic about them. Back when I was using X11 I used electric sheep, which I highly recommend. This is in fact art using tech, and there is no technical reason needed to have such a thing. Remember the pipes in windows? Everyone remembers that. Or the ant in the dark with the flash light? Or the flying toasters? I remember sitting in front of my parents Win 98 box just watching those mesmerizing pipes tangle.
Besides, the author of Xscreensaver, Jamie Zawinski, caused some really hilarious bug reports in the linux world. Mostly this one when he placed a warning inside Xscreensaver that it is outdated and that goes off only after some years to make Debian devs aware of how outdated the software of their stable branch is. Or this thread in the Gentoo Forums where Xscreensaver caused some poor guy trouble with his boss, when it showed some inappropriate things to the boss‘ niece and nephew. This ultimately led to the „offensive“ use flag of the Gentoo Xscreensaver package. That I am the proxy maintainer of, by the way. I also had my share of patching out offensive things from Xscreensaver. The source code is also full of weird and offensive comments. I love it.
But it seems there is only a few people thinking that screensavers have a right to exist in the modern world of lockscreens. Because on wayland there seems to be no such thing. And if you search online for it, you can only find a few questions on reddit asking for it.
Time to change that.
So a first I was thinking that can’t be that hard. We have swaylock on Wayland to lock the screen and does all the fancy things like blur. There is also gtklock, which also has plugin support and the dev from it has already written some for music player control and whatnot. Just play an animation in the background and you should be fine.
So I tried writing a plugin for gtklock, and halfway through understanding how this is done, it dawned on me that this is not what I am looking for. Screensavers are not just videos or gifs played in a loop. They are rendered animations. (I wonder why the 90s people decided to do that this way. Maybe rendered stuff was just cool and new back then. There was also a massive hype around the first Toy Story because of that.)
Also, it would be a shame to waste all the existing screensavers from Xscreensaver and not make them usable on Wayland.
So let’s see… maybe I could try using Xscreensavers existing screensavers and make them work on wayland somehow? Now, you can (sort of) run them on Wayland (they are compiled binaries in Xscreensavers /hacks folder) but they run through XWayland, the X-Server interfacing with Wayland to have support for legacy programs.
I have given that some thought, and I was looking into getting a Xscreensaver screensaver to run via XWayland in a GTK-Widget of Gtklock, which is a Wayland window. Or maybe try to build the screensavers for wayland using EGLX? This is though stuff.
But it turns out someone else is into screensavers as well: Wscreensaver by Manuel Stoeckl. So it turns out this guy has already (partly) done it and ported Xscreensaver screensavers to wayland.
And the best thing is, he already wrote a fork of swaylock to display those as screensavers!
Now let’s get this running.
I think it goes without saying that this is highly experimental software which should not be in a mission critical environment.
Wscreensaver
https://git.sr.ht/~mstoeckl/wscreensaver
Note: I wrote a package for wscreensaver and pushed it the Gentoos GURU. So if you have the GURU activated in your Gentoo system, just emerge gui-apps/wscreensaver from there. When using the package, the compiled screensavers will end up in the directory /usr/lib64/misc/wscreensaver/xscreensaver-antspotlight. You can then lock the screen using a screensaver and swaylock-plugin (see below) with a command like this for example:
swaylock-plugin --command /usr/lib64/misc/wscreensaver/xscreensaver-antspotlight
—-
We first need to install the dependencies (on gentoo you will have those anyway) and clone the wscreensaver repo. Also it helps to install Xscreensaver using emerge, so we already have all it’s build dependencies. Otherwise the ebuild file for Xscreensaver (or the ebuild from wscreensaver) can help figuring out he dependencies. (Look at COMMON_DEPEND and BDEPEND mostly)
sudo emerge dev-util/meson dev-util/ninja x11-misc/xscreensaver
git clone https://git.sr.ht/\~mstoeckl/wscreensaver
Then first build xscreensaver to generate some files we later need to compile the wayland screensavers:
cd wscreensaver
./configure
make
and cd into the wayland directory inside the source
cd wayland
Then compile the screensavers for Wayland
meson build
ninja -C build
That should result in some generated screensaver animations in the build directory. Many of those are not working (they will tell what is missing when they are run, though.) but the first one, xscreensaver-abstractile should work as an animated background in a wayland compositor. Awesome.
Random screensavers from a folder
A slight variation of the script provided by Manuel is the Readme of swaylock-plugin can get us random screensavers.
Save this script somewhere. For example as rotate_xscreensavers.sh
#!/usr/bin/env bash
folder=$1
file=`ls "${folder}" | shuf -n 1`
delay=60.
timeout $delay "${folder}/${file}"
And make it executeable
chmod +x rotate_xscreensavers.sh
Then run swaylock plugin with the script as the command:
swaylock-plugin --command '/home/pascal/.config/swaylock/rotate_xscreensavers.sh /usr/lib64/misc/wscreensaver'
Where you have to alter the path to the script and to the folders of screensavers from wscreensaver of course.
Swaylock-plugin
https://github.com/mstoeckl/swaylock-plugin
Note: I wrote a package for swaylock-plugin and pushed it the Gentoos GURU. So if you have the GURU activated in your Gentoo system, just emerge swaylock-plugin from there. You can then link /usr/bin/swaylock to /usr/bin/swaylock-plugin, to use swaylock-plugin like normal swaylock in other applications. !!! Also do symlink /etc/pam.d/swaylock to /etc/pam.d/swaylock-plugin like so, because otherwise swaylock-plugin starts but can not be unlocked anymore. (see also: https://github.com/mstoeckl/swaylock-plugin/issues/8)
sudo ln -s /etc/pam.d/swaylock-plugin /etc/pam.d/swaylock
(In this case gui-apps/swaylock and gui-apps/swaylock-effects can not be installed obviously)
—-
Even though this is called swalock-plugin, this is a full fork of swaylock. So don’t confuse it with the swaylock inside the system repos.
Clone the repo again first and go into the directory. Again, emerge the package or install the dependencies manually with help of the ebuild.
sudo emerge gui-apps/swaylock
git clone https://github.com/mstoeckl/swaylock-plugin
cd swaylock-plugin
And compile the code:
meson build
ninca -C build
The compiled binary should now be in the build directory.
Using that binary I can have a lock screen with a screensaver background:
./build/swaylock-plugin --command /home/pascal/dev/wscreensaver/wayland/build/xscreensaver-abstractile
(Note that swaylock-plugin seems to have some trouble relative paths for the command)
Random screensavers from a folder
A slight variation of the script provided by Manuel is the Readme of swaylock-plugin can get us random screensavers.
Save this script somewhere. For example as rotate_xscreensavers.sh
#!/usr/bin/env bash
folder=$1
file=`ls "${folder}" | shuf -n 1`
delay=60.
timeout $delay "${folder}/${file}"
And make it executeable
chmod +x rotate_xscreensavers.sh
Then run swaylock plugin with the script as the command:
swaylock-plugin --command '/home/pascal/.config/swaylock/rotate_xscreensavers.sh /usr/lib64/misc/wscreensaver'
Where you have to alter the path to the script and to the folders of screensavers from wscreensaver of course.
Conclusion
It can be done and I finally have screensavers back in wayland!
This is still somewhat rough around the edges. I think I am going to try to get some more screensavers from xscreensaver to work with wayland and contribute to Manuel Stoeckls repo if im successful. It would be great to have a version of Electric Sheep as well. But lets see what can be done.
Also a package in the guru for swaylock-plugin should be done.
Let’s see.