Skip to content

Design Choices

Tobias Stoeckmann edited this page Apr 24, 2021 · 3 revisions

Introduction

The xwallpaper development started in 2017; a long time after many other wallpaper utilities for X have been already created. On this page I want to highlight reasons for its creation and how it fits into specific environments.

Existing Solutions

Creating and releasing a new program should not happen for the sake of writing just another program. I prefer to improve existing code bases. It takes off the burden of maintenance and already existing user base benefits from improvements as well.

I was aware of these software projects (technical details added for further discussion):

Project Image Loading X11 Connection Pseudo Transparency Multi Monitor
Esetroot imlib2 Xlib yes -
feh imlib2 Xlib yes Xinerama
hsetroot imlib2 Xlib yes Xinerama
nitrogen gdk-pixbuf Xlib yes Xinerama
xloadimage custom Xlib - -
xsetroot Xlib Xlib - -
xsetwallpaper stbi Xlib - -

Technical Details

Let's analyse their technical foundations in this chapter.

imlib2

The imlib2 library can load many file formats and allows image processing. It either depends on other image libraries like libpng or uses own parser code. The imlib2 library is described in detail here.

It is the successor of imlib and has been succeeded by Evas (overview of EFL can be found on Wikipedia)). This means that imlib2 is a legacy project. The parsers are of mixed quality. The project itself performs no fuzzing. It is still maintained though and submitted patches are applied.

gdk-pixbuf

A summy can be found on its project website. It is the image loading and processing library used by GTK+ and is under active development. It has been integrated in Google's oss-fuzz for fuzzing as can be seen here. Manual code review revealed a general high quality of these parsers.

Xinerama

Xinerama is a multi-monitor extension for X. See Wikipedia's article for an overview. Its feature set has been fully integrated and superseded by RandR. Xinerama extension is still available in X but its library used in conjunction with Xlib is considered unmaintained (see libXinerama in MAINTAINERS. The Qt toolkit drops support for Xinerama in version 6, further indicating the decline of its importance.

Xlib

Xlib summarizes various X client libraries like libX11, libXinerama, etc. These libraries cover communication between X client and server. They include utility code on top of simple protocol handling for easier integration into programs.

With the advent of XCB (see Wikipedia's article for a summary) the protocol communication can be performed by toolkits or directly by programs with enhanced possibilities for asynchronous communication.

Unfortunately this led to a split among X client programs. GTK+ for example stays with Xlib whereas Qt switched to XCB.

STBI

A public domain image parser available in NetBSD. It does not depend on any further libraries like libjpeg or libpng.

Environment

The xwallpaper utility is supposed to be used with window managers which do not manage "their backgrounds". It sets the X root window and is not aware of desktop environments. Since Gnome, KDE, and other desktop environments handle the background of a desktop independently of the X root window, it is accepted and known that xwallpaper "does not work" in these situations.

Window Managers

Let's inspect some available window managers. Keep in mind that this list is not supposed to be complete:

Project X11 Connection Multi Monitor
bspwm XCB RandR and Xinerama
cwm XCB RandR
dwm Xlib Xinerama
i3 XCB RandR and Xinerama

These window managers use RandR if available and fall back to Xinerama only if RandR support is missing.

Final Design Choices

The existing solutions depend on one or multiple legacy libraries which either lack functionality or contain parsers which lack regular code review. Even though I have submitted patches in the past which have been integrated, I considered it to be a futile attempt considering that better code bases already exist. Therefore I prefer gdk-pixbuf over imlib2, XCB over Xlib and RandR over Xinerama.

Some modern and actively developed window managers use XCB and RandR. For these scenarios xwallpaper is a perfect match. It avoids issues because no RandR and Xinerama identifier translation has to be performed for multi monitor setups.

For best integration into Xorg environment, xwallpaper's command line interface is based on xrandr's command line interface. Although I would like to depend on gdk-pixbuf as image loading for more file format support, it would drag in GTK dependencies which are not always available.

Extras

To protect xwallpaper against programming errors within its C code base or its dependencies, sandboxing is directly integrated. Some existing solutions have the ability to write into files, access the network through curl or execute programs on their own. All these attack surfaces are eleminated by avoiding write accesses and shutting down further system calls when they are not needed anymore.

Conclusion

So, do I think that xwallpaper is the universally best utility out there? No. But it perfectly fits into an XCB/RandR niche which was not covered in 2017 -- or I was simply not aware of it.

To complete the table of existing solutions, xwallpaper can be added like this:

Project Image Loading X11 Connection Pseudo Transparency Multi Monitor
xwallpaper custom XCB yes RandR
Clone this wiki locally