Reputation: 21
I try to learn xcb and since the documentation is quite sparse, I would like to study the implementation of the methods itself. For instance, the definition of the method xcb_poly_line is not given in the source code https://github.com/stapelberg/libxcb/tree/master/src. However, when I include it just works.
Upvotes: 2
Views: 1594
Reputation: 9867
Most of the protocol bindings in XCB are automatically generated from an XML description of the protocol at build time. Thus, to get the "real source code", you have to build XCB yourself (but you do not have to install it, since for building, first the C source code is generated).
However, I would claim that the generated source code is not very useful. You ask for xcb_poly_line
. The XCB description for this request looks like this (taken from https://gitlab.freedesktop.org/xorg/proto/xcbproto/blob/master/src/xproto.xml):
<request name="PolyLine" opcode="65" combine-adjacent="true">
<field type="BYTE" name="coordinate_mode" enum="CoordMode" />
<field type="DRAWABLE" name="drawable" />
<field type="GCONTEXT" name="gc" />
<list type="POINT" name="points" />
<doc>
[snip]
</doc>
</request>
During build time, a file called xproto.c
is generated. In it, xcb_poly_line
is defined like this:
xcb_void_cookie_t
xcb_poly_line (xcb_connection_t *c,
uint8_t coordinate_mode,
xcb_drawable_t drawable,
xcb_gcontext_t gc,
uint32_t points_len,
const xcb_point_t *points)
{
static const xcb_protocol_request_t xcb_req = {
.count = 4,
.ext = 0,
.opcode = XCB_POLY_LINE,
.isvoid = 1
};
struct iovec xcb_parts[6];
xcb_void_cookie_t xcb_ret;
xcb_poly_line_request_t xcb_out;
xcb_out.coordinate_mode = coordinate_mode;
xcb_out.drawable = drawable;
xcb_out.gc = gc;
xcb_parts[2].iov_base = (char *) &xcb_out;
xcb_parts[2].iov_len = sizeof(xcb_out);
xcb_parts[3].iov_base = 0;
xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;
/* xcb_point_t points */
xcb_parts[4].iov_base = (char *) points;
xcb_parts[4].iov_len = points_len * sizeof(xcb_point_t);
xcb_parts[5].iov_base = 0;
xcb_parts[5].iov_len = -xcb_parts[4].iov_len & 3;
xcb_ret.sequence = xcb_send_request(c, 0, xcb_parts + 2, &xcb_req);
return xcb_ret;
}
This function just takes the given arguments and sends them to the X11 server. No magic is applied.
In the X.org X11 server, the PolyLine request is handled by the function ProcPolyLine
. Its implementation will most likely not enlighten you much either: https://cgit.freedesktop.org/xorg/xserver/tree/dix/dispatch.c#n1802
Upvotes: 2