[Nottingham] beginners guide to how X works

Cam camilo at mesias.co.uk
Sat May 5 01:42:50 BST 2007


> What I DO want to get my little head round is the way in which mouse and
> keyboard input is passed to the correct program, how 'mouse over' events
> know when the mouse is over the object and whether there is any way in
> which a program can find out what windows exist on a display.

You didn't mention what sort of level you wanted to approach this from.

If you are a curious C programmer you could search for 'xlib reference' 
or similar (it takes me back a bit!). Basically you make a call to 
'open' the display which returns a handle, then you can create windows 
and perform operations on them. You then read events in a loop. The 
events can be key presses, mouse actions, window crossing events and so on.

Hardly anyone programs at that level though, it's much more productive 
to use a widget toolkit which adds buttons, text fields and so on. You 
can use the popular widget libraries from C, C++ or even interpreted 
languages like Perl and Ruby. Even at a high level you still get to open 
the display, create widgets then go into an event loop.

As well as windows there are lots of behind the scenes structures like 
atoms (a bit like environment variables), keymaps, colourmaps and stuff 
about fonts. There are library functions to get at these and that is how 
you would find the root window or navigate the tree of other windows.


camilo at mesias.co.uk

More information about the Nottingham mailing list