xbgdump

Crates.ioxbgdump
lib.rsxbgdump
version0.1.7
sourcesrc
created_at2021-05-31 22:26:02.532069
updated_at2022-06-06 19:09:46.212163
descriptionCLI tool to dump the X11 background to a file
homepagehttps://github.com/FallenWarrior2k/xbgdump
repositoryhttps://github.com/FallenWarrior2k/xbgdump
max_upload_size
id404501
size19,777
(FallenWarrior2k)

documentation

README

xbgdump

CI Crates.io

xbgdump is a simple tool to dump the current X11 background to an image file.

You can use it like xbgdump file.png or xbgdump - to send data to stdout. By default, it writes to the file bg.png in the current directory. For efficiency reasons, data sent to stdout is encoded as PAM instead of PNG. Beside a noticeable speedup, this should not make any difference when piping into ImageMagick or similar.

When given the -m (or --mask) flag, xbgdump will query the current screen layout with RandR and mask off-screen areas with transparency. For more details, consult the help with xbgdump -h.

For now, only PNG and PAM are supported, but in theory, it should be easy to expand support to all formats supported by image-rs.

Motivation

I made this because I use nitrogen and i3lock as my screen locker. I wanted a blurred version of my background for my lock screen, but i3lock only takes a single image, which I didn't have, as nitrogen generates it on the fly.

I knew polybar inspects the background to implement pseudo-transparency, which is where I took the initial idea from. I then tried using xprop, but to the best of my knowledge, it appears to only let me retrieve the ID of the pixmap used, not its contents. Which then led to me making this.

Internals

xbgdump works by retrieving the pixmap attached to the X root window under the property _XROOTPMAP_ID. This property is set by feh and nitrogen; I have not tested this with other wallpaper-setting tools or desktop environments yet.

For 8-bit RGB, the contents of this pixmap are returned by X11 as BGR0—I don't know if this is actually documented somewhere; I found out through trial and error—which is then converted to RGB before being encoded as PNG and output to the given file or stdout.

Commit count: 56

cargo fmt