Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Xlib programming: a short tutorial

Name: Anonymous 2007-12-28 14:14

"Ok, I've to open a connection to the X server (whatever this means), with XOpenDisplay, then create a window with XCreateWindow, then draw a line with XDrawLine. Then, the program sleeps for ten seconds so I can see the result. Sounds easy."

The poor newbie writes the program. And nothing happens. He then calls his wizard friend.

-"Did you perform an XFlush after you've done everything ?
- No, why ?
- The requests stay in the client," wizard doubletalk, thinks the poor newbie, " if you don't."

The poor newbie changes the program. And nothing happens. He then calls his wizard friend.

-"Did you map your window ?
- Did I do what ???
- Creating a window doesn't make it appear on the screen. You've to map it with XMapWindow first.

The poor newbie changes the program. The window appears with nothing in it. The poor newbie then calls his wizard friend.

-"Did you wait for a MapNotify before drawing your line ?" (more wizard doubletalk)
- "No, why ?
- X has a stateless drawing model, the content of the window may be lost when the window isn't on the screen." (overflow, why can't these wizard guys speak just like you and me ?) "You've to wait for a MapNotify before drawing."

The poor newbie changes the program. Things are getting more and more complex. Not as easy as it first seemed. A loop gets the events until a MapNotify. The window appears with nothing in it. The poor newbie then calls his wizard friend.

-"I got it, did you select the StructureNotifyMask on your window ?
- ???
- Just do it, and everything'll be fine.

The poor newbie fixes the program. And the miracle happens ! A line in the window.

Name: Anonymous 2007-12-28 14:15

It's hard to unvex
when you're programming X

Name: Anonymous 2007-12-28 14:17

Too bad this doesn't work on Windows, jerk.

Name: Anonymous 2007-12-28 14:36

Programming pure Xlib is the shits,
Next time use GUI toolkits*.
'Cause when all that concerns you are widgets,
It's a lot less strain on the digits.


*So long as it's not Tk.

Name: Anonymous 2009-03-06 10:33


The number keys where   my fingers have.

Name: Anonymous 2011-02-03 7:09

Name: Anonymous 2011-02-17 20:08

that's cool and all, but check my doubles over there
Don't change these.
Name: Email:
Entire Thread Thread List