Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is learning XCB with C is better than using Gtk?

580 views
Skip to first unread message

onlooker

unread,
May 24, 2017, 8:01:14 AM5/24/17
to
Being a self-learner, I would like to try gui programming with C on X11.
First I thought I would use gtk but later thought to use XCB because gtk
and other like others sit on top of xlib so why not using libxcb but,
after reading many blog posts, it seems that using libxcb is not a
wise decision as it is difficult and learning curve is very steep.
Any hint and advice?
Thank you.
P.S My goal is to learn gui. I'm not planning to write any desktop etc.

sp...@potato.field

unread,
May 24, 2017, 9:38:47 AM5/24/17
to
On Wed, 24 May 2017 17:31:08 +0530
onlooker <vec...@m-net.arbornet.org> wrote:
>Being a self-learner, I would like to try gui programming with C on X11.
>First I thought I would use gtk but later thought to use XCB because gtk
>and other like others sit on top of xlib so why not using libxcb but,
>after reading many blog posts, it seems that using libxcb is not a
>wise decision as it is difficult and learning curve is very steep.
>Any hint and advice?

I don't see the point of XCB. The Xlib API isn't particularly hard to use
though finding good documentation for it these days might be difficult as
the O'Reilly Xlib programming books are AFAIK out of print. They might be
available as pdfs online however.

If you want to do just GUI programming in C then gtk is probably your only
sensible option as Qt is C++. If you just want to dabble in some simple
graphics then learn Xlib along with the Xdbe double buffer and XRender
extensions. Both APIs poorly documented as is typical for X extensions.
If want to do 3D graphics then OpenGL is your first port of call.

--
Spud

Jens Thoms Toerring

unread,
May 25, 2017, 4:09:42 AM5/25/17
to
sp...@potato.field wrote:
> On Wed, 24 May 2017 17:31:08 +0530
> onlooker <vec...@m-net.arbornet.org> wrote:
> >Being a self-learner, I would like to try gui programming with C on X11.
> >First I thought I would use gtk but later thought to use XCB because gtk
> >and other like others sit on top of xlib so why not using libxcb but,
> >after reading many blog posts, it seems that using libxcb is not a
> >wise decision as it is difficult and learning curve is very steep.
> >Any hint and advice?

> I don't see the point of XCB. The Xlib API isn't particularly hard to use
> though finding good documentation for it these days might be difficult as
> the O'Reilly Xlib programming books are AFAIK out of print. They might be
> available as pdfs online however.

> If you want to do just GUI programming in C then gtk is probably your only
> sensible option as Qt is C++.

Depends on what you consider to be sensible, but there's also
XForms (http://xforms-toolkit.org/). Admittedly, it's not as
sleek as newer toolkits, but perhaps easier to get started
with. And, as the current (but not very active at the moment)
maintainer, I might be biased;-)

Best regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de

James K. Lowden

unread,
May 25, 2017, 6:10:03 PM5/25/17
to
On Wed, 24 May 2017 13:38:43 +0000 (UTC)
sp...@potato.field wrote:

> On Wed, 24 May 2017 17:31:08 +0530
> onlooker <vec...@m-net.arbornet.org> wrote:
> >First I thought I would use gtk but later thought to use XCB
> >because gtk and other like others sit on top of xlib so why not
> >using libxcb but, after reading many blog posts, it seems that using
> >libxcb is not a wise decision as it is difficult and learning curve
> >is very steep. Any hint and advice?
>
> I don't see the point of XCB. The Xlib API isn't particularly hard to
> use though finding good documentation for it these days might be
> difficult as the O'Reilly Xlib programming books are AFAIK out of
> print.

I had the same question as the OP six months ago, and came to the same
conclusion.

Being skeptical of frameworks generally and having dabbled in GTK 10
years ago, I looked at the low-level options. They seemed to be:

xlib
xcb
Xt

The cool kids like xcb and claim xlib is obsolete, but I immediately
found holes in the documentation. Xt makes too many decisions for me,
although I admire its handling of user-configurable settings. For my
money xlib is just as relevant and useful today as it was in 1985.

Jim Gettys's original documentation, "Xlib ? C Language X Interface" is
a masterpiece. It's careful and precise. Every term is defined before
use, and used consistently. I won't say I was never confused, but I
will say I could never blame my confusion on the text.

Gettys was writing in the days before documentation style was
geek-casual. (Yo, bro, it's not like that.) The language is dense and
matter-of-fact, the jokes few. It can be a little intimidating if
you're not used to it, but it won't waste your time.

onlooker, if you go that route, don't forget the xlib functions are
documented with man pages. Once you understand roughly how, say,
XCreateGC works, the manual will get you the details quickly.

Working with xlib helped me distinguish between the various objects
maintained by the server, and learn what's a property of what. X being
a complex beast, the functions frequently have 5+ parameters and some
of the structures are leviathans. But it's all tractable and fairly
consistent, and yields to practice.

--jkl

Kaz Kylheku

unread,
May 25, 2017, 6:51:13 PM5/25/17
to
On 2017-05-24, sp...@potato.field <sp...@potato.field> wrote:
> On Wed, 24 May 2017 17:31:08 +0530
> onlooker <vec...@m-net.arbornet.org> wrote:
>>Being a self-learner, I would like to try gui programming with C on X11.
>>First I thought I would use gtk but later thought to use XCB because gtk
>>and other like others sit on top of xlib so why not using libxcb but,
>>after reading many blog posts, it seems that using libxcb is not a
>>wise decision as it is difficult and learning curve is very steep.
>>Any hint and advice?
>
> I don't see the point of XCB. The Xlib API isn't particularly hard to use
> though finding good documentation for it these days might be difficult as
> the O'Reilly Xlib programming books are AFAIK out of print. They might be
> available as pdfs online however.

Somewhere, I have set of O'Reilly X11 books, from a quarter century ago,
still *in shrink wrap*. Boo yeah!

Kaz Kylheku

unread,
May 25, 2017, 6:52:56 PM5/25/17
to
On 2017-05-25, Jens Thoms Toerring <j...@toerring.de> wrote:
> sp...@potato.field wrote:
>> If you want to do just GUI programming in C then gtk is probably your only
>> sensible option as Qt is C++.
>
> Depends on what you consider to be sensible, but there's also
> XForms (http://xforms-toolkit.org/). Admittedly, it's not as
> sleek as newer toolkits, but perhaps easier to get started
> with. And, as the current (but not very active at the moment)
> maintainer, I might be biased;-)

I used that nearly 25 years ago, and remember being quoted in the FAQ
list at some point.

Melzzzzz

unread,
May 25, 2017, 8:23:18 PM5/25/17
to
With XLib you have to draw widgets yourself. It's not complicated it
just needs more work. With Gtk and such you have premade Widgets.

--
press any key to continue or any other to quit...

Kaz Kylheku

unread,
May 25, 2017, 10:15:58 PM5/25/17
to
Xaw & Xaw3d 4vr.

sp...@potato.field

unread,
May 26, 2017, 4:26:01 AM5/26/17
to
On Thu, 25 May 2017 18:09:59 -0400
"James K. Lowden" <jklo...@speakeasy.net> wrote:
>although I admire its handling of user-configurable settings. For my
>money xlib is just as relevant and useful today as it was in 1985. =20

Yes, I agree. The only thing its missing for 2D graphics is alpha blending
and the one thing I've never understood is why didn't they just add that
to the XColor structure instead of coming up with a whole new (and ugly)
XRender API and extension to support it which uses completely different
graphics objects to Xlib. A masterclass in poor design IMO.

--
Spud

Nicolas George

unread,
May 26, 2017, 4:57:10 AM5/26/17
to
"James K. Lowden" , dans le message
<20170525180959.db4d...@speakeasy.net>, a écrit :
> Being skeptical of frameworks generally and having dabbled in GTK 10
> years ago, I looked at the low-level options. They seemed to be:
>
> xlib
> xcb
> Xt

You are mistaken, Xt is not low-level, it is already the basis for
toolkits.

> The cool kids like xcb and claim xlib is obsolete, but I immediately
> found holes in the documentation.

There are many holes in the Xlib documentation.

> Xt makes too many decisions for me,
> although I admire its handling of user-configurable settings. For my
> money xlib is just as relevant and useful today as it was in 1985.

It is not a matter of being obsolete or anything like that, it is a
matter of design decision.

X11 is an asynchronous network protocol. Xlib and XCB are libraries to
disguise it into an API.

Xlib made the design decision to make that API synchronous, as much as
possible. It is of course not possible for events, but all operations
that elicit an immediate response from the server, like creating a
window or interning an atom, are implemented as synchronous functions,
waiting for the reply.

XCB made the opposite decision: the operations are split in two
functions, one for starting the request to the server and one for
getting its result. There are of course patterns to combine both when
the response is necessary immediately.

The net result is that XCB is somewhat more verbose than Xlib, but more
efficient. The efficiency is not visible on normal setups where the
server and the clients run on the same hardware, but it can be very
noticeable when the network between the clients and the server is fast
but with some latency: with XCB, interning several atoms or creating
several independent windows can be started all at once, waiting for the
round-trip only once.

Scott Lurndal

unread,
May 26, 2017, 8:49:04 AM5/26/17
to
The MIT documents for all the X11R* releases are still available on-line.

The O'Reilly X11 books are available free, here:

https://www.x.org/wiki/UserDocumentation/

Scott Lurndal

unread,
May 26, 2017, 8:49:52 AM5/26/17
to
Or one can use the Athena Widgets distributed with all X11 installations.
(libXaw.so).

Nicolas George

unread,
May 26, 2017, 9:47:37 AM5/26/17
to
Scott Lurndal, dans le message <OvVVA.31697$Us3....@fx01.iad>, a
écrit :
> Or one can use the Athena Widgets distributed with all X11 installations.
> (libXaw.so).

Unless one wants an ergonomic UI.

Scott Lurndal

unread,
May 26, 2017, 10:19:39 AM5/26/17
to
I'm posting this using an Xaw program, and it's far more ergonomic
than anything that's been created subsequently, IMO. And it works
great tunnelling X11 over DSL, which no modern toolkit (e.g. GTK+) does.

Nicolas George

unread,
May 26, 2017, 11:51:13 AM5/26/17
to
Scott Lurndal, dans le message <ZPWVA.131773$jo6....@fx33.iad>, a
écrit :
> I'm posting this using an Xaw program, and it's far more ergonomic
> than anything that's been created subsequently, IMO.

Well, let's compare ergonomic advice. Can you point some typical Xaw
programs that you consider having an ergonomic UI?

Scott Lurndal

unread,
May 26, 2017, 12:17:56 PM5/26/17
to
Take a look at the headers, above.

Kaz Kylheku

unread,
May 26, 2017, 10:23:35 PM5/26/17
to
Wait, did you just say ergo-NOMIC?

I totally fucking thought you said ergo-GENIC five weeks ago, so I wrote
the whole app using SUIT: The Simple User Interface Toolkit

Aw man ...

onlooker

unread,
May 27, 2017, 3:44:21 AM5/27/17
to
Thank you all very much for your valuable help and advice.
I'm using usenet as a free-package subscriber so I'm forbidden to
send reply and followups.

Nicolas George

unread,
May 27, 2017, 8:03:42 AM5/27/17
to
Scott Lurndal, dans le message <SyYVA.136005$rl4.1...@fx35.iad>, a
écrit :
> Take a look at the headers, above.

xrn? Surely you are joking? Are you really pretending that xrn is an
example of an ergonomic UI as can be built with Xaw?

Let us see.

I start it, I get immediately a frozen window and a second one telling
me that I should configure $NNTPSERVER, and two buttons to close it.
Judging by the bolder of one of the buttons, it should be the default.
But hitting the return key does nothing; neither does escape; using the
arrows does not move the bolder border either. And the window does not
even react to the delete protocol.

I could have stopped right there, because it confirms exactly what I
know of the terrible UI of the Xaw-based programs. But maybe there is
something there, still. Maybe Xaw gives by default a terrible UI like
that but can be tweaked to give a good UI, and maybe xrn did it for the
normal use of the program. So I carried on.

So I wait for the frozen window telling me "getting list of newsgroups",
and I try to enter this very newsgroup. I get a huge list of all
newsgroups, I try to navigate in it. I can navigate with the mouse.
First bad surprise, the mouse wheel has no effect. I can also navigate
with the arrows and page-up, page-down, good. But still, the list is
huge. I type the first letter of the newsgroup, it should bring me at a
better place; except no, it only beeps.

Well, I can stop here. Unconfigured startup could be argued a corner
case not worth polishing, but navigating the newgroups list is a common
case, and the UI for it is typical of the UI of the application:
terrible, especially when it comes to keyboard navigation of the
interface. I have seen games with custom quick-and-dirty toolkit have a
more ergonomic UI.

Thank you for making my point for me: Xaw is awful.

James K. Lowden

unread,
May 30, 2017, 7:01:02 PM5/30/17
to
On Sat, 27 May 2017 13:14:15 +0530
onlooker <vec...@m-net.arbornet.org> wrote:

> I'm using usenet as a free-package subscriber so I'm forbidden to
> send reply and followups.

When my so-called ISP dropped usenet support, I subscribed to NewsDemon:

https://www.newsdemon.com/?ref=10292760

At $2/yr I'd call it cheap.

--jkl

0 new messages