[Xcb] Best way to load a png/jpeg file when using XCB?

Josh Triplett josh at joshtriplett.org
Sun Jul 4 12:25:48 PDT 2010

On Sun, Jul 04, 2010 at 06:13:56PM +0200, Michael Stapelberg wrote:
> Hi,
> I recently wanted to convert i3lock (a simple screen locker forked from slock)
> to use XCB. One of the features of i3lock is to display an image instead of
> only a black screen (like slock). At the moment, we do this using libXpm for
> simplicity.
> Because libxpm requires xlib, I can’t use it with xcb. So I looked into
> directly using libjpeg and/or libpng, but it seems very complicated (multiple
> pages of code to load an image while i3lock has only ~ 250 SLOC). Also, I
> looked into imlib2, but it also does not work with xcb (because you need the
> xlib Display and Visual data structure for imlib_context_set_visual()).
> My question is: What is the best way (not much code, no strange dependencies)
> to load an image in a relatively convenient format (jpeg/png) when using XCB?

You might consider it overkill, but Cairo will do exactly what you want.
You can create a Cairo XCB surface, and render a PNG to it.

- Josh Triplett

More information about the Xcb mailing list