Hacker News new | ask | show | jobs
by Aransentin 807 days ago
It should be noted that Xlib has been a compatibility wrapper around XCB – the "modern" X11 client library replacement – for about 15 years now, so it might make more sense to just target that.

(The only thing on the top of my head that absolutely requires Xlib is some niche Vulkan stuff; e.g. VK_EXT_acquire_xlib_display unfortunately has no XCB analogue.)

4 comments

It should also be noted that in general, Xlib can do a lot more than XCB with a /lot/ less effort and bugs, and has an actual documentation, tutorials, books.

Xlib certainly is quirky, in particular around error handling, though.

It's been a very long while since I played with any of this, and I don't want to rely too much on the widely understood to be lacking documentation, but are Xlib and XCB still not in a very weird situation in which one depends on another for different reasons? In this specific case, at least multiple years ago, glx wouldn't play nice without Xlib, if it would be possible at all without a lot of pain. I don't expect it to have changed for obvious reasons, XCB never being complete and X interest slowly waning.

https://xcb.freedesktop.org/opengl/#index3h1

These days you can use EGL to get an OpenGL context in a pure XCB application without needing to use Xlib.
Last I checked (which was years ago, admittedly) the GLX libraries still required Xlib. There were XCB functions for GLX, but they didn't work with the client-side libraries, so you had to use Xlib.

Of course, you should just skip GLX nowadays and use EGL instead, which I'm pretty sure does work with XCB.

I haven't done anything with X11 in a few years, but last I looked made no sense to do anything with XCB because the documentation is half complete, whereas Xlib has everything you might need documented.
Otoh, Xlib's approach to networking is kind of wrong on so many levels.

> Calls that don't require a response from the X server are queued in a buffer to be sent as a batch of requests to the server. Those that require a response flush all the buffered requests and then block until the response is received. [1]

X11, the protocol is a distributed systems protocol, built on asynchronous message passing, that outputs to the screen as a side effect. Xlib hides the nature of the underlying protocol, and makes it very hard to pipeline things that should be pipelined for maximum performance. Xcb separates out sending a request and waiting for a response, so if you absolutely need the response before you continue, you can do that, but you can also request many things and then wait when you need them.

[1] https://www.x.org/wiki/guide/xlib-and-xcb/