redraw, who (xlib/cairo), when...
glynn at gclements.plus.com
Sun May 26 13:03:32 PDT 2013
First Last wrote:
> So now my problem, I need to redraw the clock, that actualy doesn't
> working yet, since I 'm bit lost with "when" and "how" to redraw, if
> it's cairoor xlibwho has (or both) to redraw etc.
You should redraw the window (or at least the rectangle specified in
the XExposeEvent structure) in response to an Expose event. Ideally,
you should collect any pending Expose events and perform the minimum
amount of work necessary to redraw the specified rectangles (i.e. if
there are multiple pending Expose events covering the entire window,
you should only redraw it once, not once per event).
> Moreover, there is something I don't understand more, when I hit
> "space", then the window moves and there is a redraw (you can see it
> when the minutes change).
Your main loop calls XNextEvent(), which will block until an event is
available. If there are no events to report, it will block
If you want the application to perform a task (e.g. update the
display) at regular intervals, you need to use e.g. XEventsQueued() or
XCheckMaskEvent() to query for events without blocking.
If no events are available, use XInternalConnectionNumbers() to get a
list of the relevant descriptors (those for the connection to the X
server plus associated processes such as input method servers) then
use select() or poll() with a timeout to wait until input is available
or the timeout expires.
Beyond that, I suggest looking at the source code for the main loop of
an existing GUI toolkit for clues as to how to implement input, timer
and/or idle events.
Glynn Clements <glynn at gclements.plus.com>
More information about the xorg