5.10 Querying the Graphics Context
When you call a number of the GC convenience routines, such as
XSetForeground()
and
XSetLineAttributes()
, you might expect each to
generate a separate protocol request to change the GC. But this is not
what happens. Xlib saves up the changes in an internal structure and
makes a single request to the server just before the GC is actually used
by a drawing request.
The type GC
is a pointer to this internal
structure. All Xlib routines use a pointer to this internal structure,
not a integer ID, as we have previously implied. However, this fact does
not impact how you write Xlib code at all. In practice, a pointer to an
opaque structure and an integer ID such as a window ID are treated
exactly the same.
In R4, the XGetGCValues()
function has been
added to allow clients to read Xlib’s cache of the fields in each GC.
This can save an application from having to maintain its own cache of GC
values, when it needs to change the GC in several different places in
ways that depend on the current contents.
Note that XGetGCValues()
is not a true
round-trip query to the server—there is no protocol request that
actually asks the server for these values. This has good and bad
consequences. The good part is that XGetGCValues()
is
fast because it is not subject to network delays. The bad side is that
the values in Xlib’s cache do not include the default values for certain
of the GC members. The tile
,
stipple
, and font
fields contain
invalid IDs when XGetGCValues()
is ...
Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.