Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xorg loading an image

I'm starting to code up my own window manager, and was wondering how to use the xorg api to get from raw image data ( such as the data given by libpng ), into an Xorg Pixmap or something drawable by Xorg?

like image 516
DavidG Avatar asked Mar 27 '26 01:03

DavidG


2 Answers

You probably discovered this at some point since 2008, but for the benefit of future readers...

XCreatePixmapFromBitmapData() will load literal bitmap (i.e. 1-bit, black&white) data into a pixmap. This is most likely not what you want, if the goal is to load from a PNG.

A newer way to do this is to use Cairo or GdkPixbuf. The old-school Xlib APIs such as XCreatePixmapFromBitmapData() and XDrawWhatever() are all pretty much deprecated (not that they will actually be removed ever, but they are outdated and out of sync with how modern apps work).

The way people would generally recommend doing things these days is:

  • prefer libxcb to libX11, libxcb is just a very thin wrapper around the X protocol and lacks calls that do multiple X protocol requests (for example CreatePixmapFromBitmapData does CreatePixmap, CreateGC, PutImage, FreeGC)
  • prefer cairo (or comparable library, Skia is one) to the server-side drawing APIs

You could use cairo_image_surface_create_from_png() for simple purposes or GdkPixbuf if you need to support more formats, etc.

like image 118
Havoc P Avatar answered Mar 30 '26 08:03

Havoc P


XCreatePixmapFromBitmapData should do just that. Remember that you need to feed in data of the same bit depth as your xserver is using.

like image 30
Johan Dahlin Avatar answered Mar 30 '26 08:03

Johan Dahlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!