<s>
Xlib	B-Language
(	O
also	O
known	O
as	O
libX11	O
)	O
is	O
an	O
X	B-Operating_System
Window	I-Operating_System
System	I-Operating_System
protocol	O
client	O
library	B-Library
written	O
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
It	O
contains	O
functions	O
for	O
interacting	O
with	O
an	O
X	B-Operating_System
server	B-Application
.	O
</s>
<s>
These	O
functions	O
allow	O
programmers	B-Application
to	O
write	O
programs	O
without	O
knowing	O
the	O
details	O
of	O
the	B-Protocol
X	I-Protocol
protocol	I-Protocol
.	O
</s>
<s>
Few	O
applications	O
use	O
Xlib	B-Language
directly	O
;	O
rather	O
,	O
they	O
employ	O
other	O
libraries	O
that	O
use	O
Xlib	B-Language
functions	O
to	O
provide	O
widget	B-Library
toolkits	I-Library
:	O
</s>
<s>
Xlib	B-Language
appeared	O
around	O
1985	O
,	O
and	O
is	O
used	O
in	O
GUIs	B-Application
for	O
many	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
A	O
re-implementation	O
of	O
Xlib	B-Language
was	O
introduced	O
in	O
2007	O
using	O
XCB	B-Language
.	O
</s>
<s>
The	O
main	O
types	O
of	O
data	O
in	O
Xlib	B-Language
are	O
the	O
Display	O
structure	O
and	O
the	O
types	O
of	O
the	O
identifiers	O
.	O
</s>
<s>
The	O
Display	O
structure	O
of	O
the	O
Xlib	B-Language
library	B-Library
contains	O
information	O
about	O
the	O
display	O
,	O
but	O
more	O
importantly	O
it	O
contains	O
information	O
relative	O
to	O
the	O
channel	O
between	O
the	O
client	O
and	O
the	O
server	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
in	O
a	O
Unix-like	B-Operating_System
operating	I-Operating_System
system	I-Operating_System
,	O
the	O
Display	O
structure	O
contains	O
the	O
file	O
handle	O
of	O
the	O
socket	B-Protocol
of	O
this	O
channel	O
(	O
this	O
can	O
be	O
retrieved	O
using	O
the	O
ConnectionNumber	O
macro	O
.	O
)	O
</s>
<s>
Most	O
Xlib	B-Language
functions	O
have	O
a	O
Display	O
structure	O
as	O
an	O
argument	O
because	O
they	O
either	O
operate	O
on	O
the	O
channel	O
or	O
are	O
relative	O
to	O
a	O
specific	O
channel	O
.	O
</s>
<s>
In	O
particular	O
,	O
all	O
Xlib	B-Language
functions	O
that	O
interact	O
with	O
the	O
server	B-Application
need	O
this	O
structure	O
for	O
accessing	O
the	O
channel	O
.	O
</s>
<s>
are	O
managed	O
by	O
the	O
server	B-Application
,	O
which	O
means	O
that	O
the	O
data	O
about	O
their	O
actual	O
implementation	O
is	O
all	O
stored	O
in	O
the	O
server	B-Application
.	O
</s>
<s>
The	O
client	O
cannot	O
directly	O
operate	O
on	O
an	O
object	O
,	O
but	O
can	O
only	O
request	O
the	O
server	B-Application
to	O
perform	O
the	O
operation	O
specifying	O
the	O
identifier	O
of	O
the	O
object	O
.	O
</s>
<s>
are	O
all	O
identifiers	O
,	O
which	O
are	O
32-bit	O
integers	O
(	O
just	O
as	O
in	O
the	O
X11	B-Operating_System
protocol	O
itself	O
)	O
.	O
</s>
<s>
A	O
client	O
'	O
creates	O
 '	O
a	O
window	O
by	O
requesting	O
that	O
the	O
server	B-Application
create	O
a	O
window	O
.	O
</s>
<s>
This	O
is	O
done	O
via	O
a	O
call	O
to	O
an	O
Xlib	B-Language
function	O
that	O
returns	O
an	O
identifier	O
for	O
the	O
window	O
,	O
that	O
is	O
,	O
a	O
number	O
.	O
</s>
<s>
This	O
identifier	O
can	O
then	O
be	O
used	O
by	O
the	O
client	O
for	O
requesting	O
other	O
operations	O
on	O
the	O
same	O
window	O
to	O
the	O
server	B-Application
.	O
</s>
<s>
The	O
identifiers	O
are	O
unique	O
to	O
the	O
server	B-Application
.	O
</s>
<s>
For	O
example	O
,	O
two	O
applications	O
connecting	O
with	O
the	O
same	O
server	B-Application
use	O
the	O
same	O
identifier	O
to	O
refer	O
to	O
the	O
same	O
window	O
.	O
</s>
<s>
The	O
Xlib	B-Language
functions	O
that	O
send	O
requests	O
to	O
the	O
server	B-Application
usually	O
do	O
not	O
send	O
these	O
requests	O
immediately	O
but	O
store	O
them	O
in	O
a	O
buffer	O
,	O
called	O
the	O
request	O
buffer	O
.	O
</s>
<s>
The	O
term	O
request	O
in	O
this	O
case	O
refers	O
to	O
the	O
request	O
from	O
the	O
client	O
that	O
is	O
directed	O
to	O
the	O
server	B-Application
:	O
the	O
request	O
buffer	O
can	O
contain	O
all	O
kinds	O
of	O
requests	O
to	O
the	O
server	B-Application
,	O
not	O
only	O
those	O
having	O
a	O
visible	O
effect	O
on	O
the	O
screen	O
.	O
</s>
<s>
The	O
request	O
buffer	O
is	O
guaranteed	O
to	O
be	O
flushed	O
(	O
i.e.	O
,	O
all	O
requests	O
done	O
so	O
far	O
are	O
sent	O
to	O
the	O
server	B-Application
)	O
after	O
a	O
call	O
to	O
the	O
functions	O
XSync	O
or	O
XFlush	O
,	O
after	O
a	O
call	O
to	O
a	O
function	O
that	O
returns	O
a	O
value	O
from	O
the	O
server	B-Application
(	O
these	O
functions	O
block	O
until	O
the	O
answer	O
is	O
received	O
)	O
,	O
and	O
in	O
some	O
other	O
conditions	O
.	O
</s>
<s>
Xlib	B-Language
stores	O
the	O
received	O
events	O
in	O
a	O
queue	O
.	O
</s>
<s>
While	O
the	O
X	B-Operating_System
server	B-Application
sends	O
events	O
asynchronously	O
,	O
applications	O
using	O
the	O
Xlib	B-Language
library	B-Library
are	O
required	O
to	O
explicitly	O
call	O
Xlib	B-Language
functions	O
for	O
accessing	O
the	O
events	O
in	O
the	O
queue	O
.	O
</s>
<s>
Errors	O
are	O
instead	O
received	O
and	O
treated	O
asynchronously	O
:	O
the	O
application	O
can	O
provide	O
an	O
error	O
handler	O
that	O
will	O
be	O
called	O
whenever	O
an	O
error	O
message	O
from	O
the	O
server	B-Application
is	O
received	O
.	O
</s>
<s>
The	O
functions	O
in	O
the	O
Xlib	B-Language
library	B-Library
can	O
be	O
grouped	O
in	O
:	O
</s>
<s>
The	O
client	O
creates	O
a	O
connection	O
with	O
the	O
server	B-Application
by	O
calling	O
XOpenDisplay	O
.	O
</s>
<s>
The	O
drawing	O
of	O
the	O
window	O
content	O
is	O
therefore	O
made	O
inside	O
the	O
loop	B-General_Concept
handling	I-General_Concept
the	I-General_Concept
events	I-General_Concept
.	O
</s>
<s>
The	O
event	B-General_Concept
loop	I-General_Concept
waits	O
for	O
an	O
incoming	O
event	O
:	O
if	O
this	O
event	O
is	O
a	O
key	O
press	O
,	O
the	O
application	O
exits	O
;	O
if	O
it	O
is	O
an	O
expose	O
event	O
,	O
the	O
window	O
content	O
is	O
drawn	O
.	O
</s>
<s>
Xlib	B-Language
does	O
not	O
provide	O
support	O
for	O
buttons	O
,	O
menus	O
,	O
scrollbars	O
,	O
etc	O
.	O
</s>
<s>
Such	O
widgets	O
are	O
provided	O
by	O
other	O
libraries	O
,	O
which	O
in	O
turn	O
use	O
Xlib	B-Language
.	O
</s>
<s>
libraries	O
built	O
atop	O
of	O
the	O
X	B-Language
Toolkit	I-Language
Intrinsics	I-Language
library	B-Library
(	O
Xt	O
)	O
,	O
which	O
provides	O
support	O
for	O
widgets	O
but	O
does	O
not	O
provide	O
any	O
particular	O
widget	O
;	O
specific	O
widgets	O
are	O
provided	O
by	O
widget	B-Library
set	I-Library
libraries	O
that	O
use	O
Xt	O
,	O
such	O
as	O
Xaw	B-Library
and	O
Motif	B-Application
;	O
</s>
<s>
libraries	O
that	O
provide	O
widget	B-Library
sets	I-Library
using	O
Xlib	B-Language
directly	O
,	O
without	O
the	O
Xt	O
library	B-Library
,	O
such	O
as	O
the	O
X	B-Operating_System
versions	O
of	O
GTK	B-Application
,	O
Qt	B-Language
,	O
FLTK	B-Language
and	O
fpGUI	B-Language
.	O
</s>
<s>
Applications	O
using	O
any	O
of	O
these	O
widget	B-Library
libraries	I-Library
typically	O
specify	O
the	O
content	O
of	O
the	O
window	O
before	O
entering	O
the	O
main	B-General_Concept
loop	I-General_Concept
and	O
do	O
not	O
need	O
to	O
explicitly	O
handle	O
Expose	O
events	O
and	O
redraw	O
the	O
window	O
content	O
.	O
</s>
<s>
The	O
XCB	B-Language
library	B-Library
is	O
an	O
alternative	O
to	O
Xlib	B-Language
.	O
</s>
<s>
Its	O
two	O
main	O
aims	O
are	O
:	O
reduction	O
in	O
library	B-Library
size	O
and	O
direct	O
access	O
to	O
the	O
X11	B-Operating_System
protocol	O
.	O
</s>
<s>
A	O
modification	O
of	O
Xlib	B-Language
has	O
been	O
produced	O
to	O
use	O
XCB	B-Language
as	O
a	O
low-level	O
layer	O
.	O
</s>
