2

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.

JanuschP
  • 21
  • 1
  • 3
  • The repository you linked is outdated (2012). The function xcb_poly_line seems to be added to version 1.13. You should browse [upstream](https://gitlab.freedesktop.org/xorg/lib/libxcb/tree/master). That said, I am not able to find `xcb_poly_line` anyway, but i guess it has to be somewhere in libxcb-* projects. – KamilCuk Mar 10 '19 at 14:36
  • I think `xcb_poly_line` is defined in `xbc/proto.h`(according to [x.org](ftp://www.x.org/pub/X11R7.7/doc/man/man3/xcb_poly_line.3.xhtml)) as prototype to something else, try opening the `xbc/proto.h` and search for it, it could be in `/include` `/usr/include`(you better use `gcc -xc -E -v -` to figure out, as in [this answer](https://stackoverflow.com/a/6666338/5420570)), also [searched](https://gitlab.freedesktop.org/search?utf8=%E2%9C%93&search=xcb_poly_line&group_id=&project_id=2429&search_code=true&repository_ref=master) for it, and found nothing but documentation on how to use it. – BladeMight Mar 10 '19 at 16:20

1 Answers1

1

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

Uli Schlachter
  • 9,337
  • 1
  • 23
  • 39