From 408e74538676230e289d79c6b0195b464bfc6606 Mon Sep 17 00:00:00 2001 From: TORRI Vincent Date: Sat, 30 Sep 2006 12:45:12 +0200 Subject: [PATCH] update tutorial to the new api. Add some doc about cursors. Add some colors to section 6 (Opening and closing the connection to an X server). Tell me if you want to keep colors or not (colors can be modified in xcb.css) --- doc/tutorial/index.html | 2442 ++++++++++++++++++++++++----------------------- doc/tutorial/xcb.css | 20 + 2 files changed, 1266 insertions(+), 1196 deletions(-) diff --git a/doc/tutorial/index.html b/doc/tutorial/index.html index b24c4ba..64f36a4 100644 --- a/doc/tutorial/index.html +++ b/doc/tutorial/index.html @@ -103,10 +103,11 @@
  • Drawing a pixmap in a window
  • Freeing a pixmap -
  • Messing with the mouse cursor +
  • Messing with the mouse cursor
      -
    1. Creating and destroying a mouse cursor -
    2. Setting a window's mouse cursor +
    3. Creating and destroying a mouse cursor +
    4. Setting a window's mouse cursor +
    5. Complete example
  • Translation of basic Xlib functions and macros
      @@ -162,7 +163,7 @@

      This tutorial is based on the Xlib Tutorial - written by Guy Keren. The + written by Guy Keren. The author allowed me to take some parts of his text, mainly the text which deals with the X Windows generality.

      @@ -300,7 +301,7 @@ requests to the X server.
    1. If the event was a quit message, exit the loop.
    -
  • Close down the connection to the X server. +
  • Close down the connection to the X server.
  • Perform cleanup operations.
    @@ -322,7 +323,7 @@ given X server. It hides a queue of messages coming from the server, and a queue of pending requests that our client intends to send to the server. In XCB, this structure is named - 'XCBConnection'. It is analogous to the Xlib Display. + 'xcb_connection_t'. It is analogous to the Xlib Display. When we open a connection to an X server, the library returns a pointer to such a structure. Later, we supply this pointer to any XCB function that should send @@ -393,7 +394,7 @@ double get_time(void) { struct timeval timev; - + gettimeofday(&timev, NULL); return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000); @@ -402,46 +403,45 @@ get_time(void) int main () { - XCBConnection *c; - XCBATOM *atoms; - XCBInternAtomCookie *cs; - char **names; - int count; - int i; - double start; - double end; - double diff; + xcb_connection_t *c; + xcb_atom_t *atoms; + xcb_intern_atom_cookie_t *cs; + char **names; + int count; + int i; + double start; + double end; + double diff; /* Xlib */ Display *disp; Atom *atoms_x; double diff_x; - c = XCBConnect (NULL, NULL); + c = xcb_connect (NULL, NULL); count = 500; - atoms = (XCBATOM *)malloc (count * sizeof (atoms)); + atoms = (xcb_atom_t *)malloc (count * sizeof (atoms)); names = (char **)malloc (count * sizeof (char *)); /* init names */ - for (i = 0; i < count; ++i) - { - char buf[100]; + for (i = 0; i < count; ++i) { + char buf[100]; - sprintf (buf, "NAME%d", i); - names[i] = strdup (buf); - } + sprintf (buf, "NAME%d", i); + names[i] = strdup (buf); + } /* bad use */ start = get_time (); for (i = 0; i < count; ++i) - atoms[i] = XCBInternAtomReply (c, - XCBInternAtom (c, - 0, - strlen(names[i]), - names[i]), - NULL)->atom; + atoms[i] = xcb_intern_atom_reply (c, + xcb_intern_atom (c, + 0, + strlen(names[i]), + names[i]), + NULL)->atom; end = get_time (); diff = end - start; @@ -450,19 +450,18 @@ main () /* good use */ start = get_time (); - cs = (XCBInternAtomCookie *) malloc (count * sizeof(XCBInternAtomCookie)); + cs = (xcb_intern_atom_cookie_t *) malloc (count * sizeof(xcb_intern_atom_cookie_t)); for(i = 0; i < count; ++i) - cs[i] = XCBInternAtom (c, 0, strlen(names[i]), names[i]); + cs[i] = xcb_intern_atom (c, 0, strlen(names[i]), names[i]); - for(i = 0; i < count; ++i) - { - XCBInternAtomRep *r; + for(i = 0; i < count; ++i) { + xcb_intern_atom_reply_t *r; - r = XCBInternAtomReply(c, cs[i], 0); - if(r) - atoms[i] = r->atom; - free(r); - } + r = xcb_intern_atom_reply(c, cs[i], 0); + if(r) + atoms[i] = r->atom; + free(r); + } end = get_time (); printf ("good use time : %f\n", end - start); @@ -471,13 +470,11 @@ main () /* free var */ for (i = 0; i < count; ++i) - { - free (names[i]); - } + free (names[i]); free (atoms); free (cs); - XCBDisconnect (c); + xcb_disconnect (c); /* Xlib */ disp = XOpenDisplay (getenv("DISPLAY")); @@ -498,8 +495,8 @@ main () free (names); XCloseDisplay (disp); - - return 1; + + return 0; }
  • The Graphic Context @@ -554,22 +551,22 @@ main ()

    - You have to checkout in CVS the following modules: + You have to checkout in the git repository the following modules:

    - Note that Xproto and xcb-proto exist only to install header + Note that xcb-proto exists only to install header files, so typing 'make' or 'make all' will produce the message "Nothing to be done for 'all'". That's normal.

    @@ -590,8 +587,8 @@ gcc -Wall prog.c -o prog `pkg-config --cflags --libs xcb` will be the one in the environment variable DISPLAY.

    -XCBConnection *XCBConnect (const char *displayname,
    -                           int        *screenp);
    +xcb_connection_t *xcb_connect (const char *displayname,
    +                               int        *screenp);
     

    The second parameter returns the screen number used for the @@ -599,24 +596,24 @@ XCBConnection *XCBConnect (const char *displayname, and is opaque. Here is how the connection can be opened:

    -#include <X11/XCB/xcb.h>
    +#include <X11/XCB/xcb.h>
     
    -int
    -main (int argc, char *argv[])
    +int
    +main ()
     {
    -  XCBConnection *c;
    -  
    +  xcb_connection_t *c;
    +
       /* Open the connection to the X server. Use the DISPLAY environment variable as the default display name */
    -  c = XCBConnect (NULL, NULL);
    +  c = xcb_connect (NULL, NULL);
     
    -  return 1;
    +  return 0;
     }
     

    To close a connection, it suffices to use:

    -void XCBDisconnect (XCBConnection *c);
    +void xcb_disconnect (xcb_connection_t *c);
     
    @@ -629,7 +626,7 @@ void XCBDisconnect (XCBConnection *c);
      -
    • XCBConnect () +
    • xcb_connect ()
    @@ -639,7 +636,7 @@ void XCBDisconnect (XCBConnection *c);
      -
    • XCBDisconnect () +
    • xcb_disconnect ()
    @@ -651,35 +648,35 @@ void XCBDisconnect (XCBConnection *c); basic information about it: what screens it has, what is the size (width and height) of the screen, how many colors it supports (black and white ? grey scale ?, 256 colors ? more ?), - and so on. We get such information from the XCBSCREEN + and so on. We get such information from the xcb_screen_t structure:

     typedef struct {
    -    XCBWINDOW root;
    -    XCBCOLORMAP default_colormap;
    -    CARD32 white_pixel;
    -    CARD32 black_pixel;
    -    CARD32 current_input_masks;
    -    CARD16 width_in_pixels;
    -    CARD16 height_in_pixels;
    -    CARD16 width_in_millimeters;
    -    CARD16 height_in_millimeters;
    -    CARD16 min_installed_maps;
    -    CARD16 max_installed_maps;
    -    XCBVISUALID root_visual;
    -    BYTE backing_stores;
    -    BOOL save_unders;
    -    CARD8 root_depth;
    -    CARD8 allowed_depths_len;
    -} XCBSCREEN;
    +    xcb_window_t   root;
    +    xcb_colormap_t default_colormap;
    +    uint32_t       white_pixel;
    +    uint32_t       black_pixel;
    +    uint32_t       current_input_masks;
    +    uint16_t       width_in_pixels;
    +    uint16_t       height_in_pixels;
    +    uint16_t       width_in_millimeters;
    +    uint16_t       height_in_millimeters;
    +    uint16_t       min_installed_maps;
    +    uint16_t       max_installed_maps;
    +    xcb_visualid_t root_visual;
    +    uint8_t        backing_stores;
    +    uint8_t        save_unders;
    +    uint8_t        root_depth;
    +    uint8_t        allowed_depths_len;
    +} xcb_screen_t;
     

    We could retrieve the first screen of the connection by using the following function:

    -XCBSCREENIter XCBSetupRootsIter (XCBSetup *R);
    +xcb_screen_iterator_t xcb_setup_roots_iterator (xcb_setup_t *R);
     

    Here is a small program that shows how to use this function: @@ -692,22 +689,21 @@ XCBSCREENIter XCBSetupRootsIter (XCBSetup *R); int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - int screen_nbr; - XCBSCREENIter iter; - + xcb_connection_t *c; + xcb_screen_t *screen; + int screen_nbr; + xcb_screen_iterator_t iter; + /* Open the connection to the X server. Use the DISPLAY environment variable */ - c = XCBConnect (NULL, &screen_nbr); - + c = xcb_connect (NULL, &screen_nbr); + /* Get the screen #screen_nbr */ - iter = XCBSetupRootsIter (XCBGetSetup (c)); - for (; iter.rem; --screen_nbr, XCBSCREENNext (&iter)) - if (screen_nbr == 0) - { - screen = iter.data; - break; - } + iter = xcb_setup_roots_iterator (xcb_get_setup (c)); + for (; iter.rem; --screen_nbr, xcb_screen_next (&iter)) + if (screen_nbr == 0) { + screen = iter.data; + break; + } printf ("\n"); printf ("Informations of screen %ld:\n", screen->root.xid); @@ -717,7 +713,7 @@ main (int argc, char *argv[]) printf (" black pixel...: %ld\n", screen->black_pixel); printf ("\n"); - return 1; + return 0; }

  • Creating a basic window - the "hello world" program @@ -728,42 +724,43 @@ main (int argc, char *argv[])

     typedef struct {
    -    CARD32 xid;
    -} XCBWINDOW;
    +    uint32_t xid;
    +} xcb_window_t;
     

    We first ask for a new Id for our window, with this function:

    -XCBWINDOW XCBWINDOWNew(XCBConnection *c);
    +xcb_window_t xcb_window_new(xcb_connection_t *c);
     

    Then, XCB supplies the following function to create new windows:

    -XCBVoidCookie XCBCreateWindow (XCBConnection *c,             /* Pointer to the XCBConnection structure */
    -                               CARD8          depth,         /* Depth of the screen */
    -                               XCBWINDOW      wid,           /* Id of the window */
    -                               XCBWINDOW      parent,        /* Id of an existing window that should be the parent of the new window */
    -                               INT16          x,             /* X position of the top-left corner of the window (in pixels) */
    -                               INT16          y,             /* Y position of the top-left corner of the window (in pixels) */
    -                               CARD16         width,         /* Width of the window (in pixels) */
    -                               CARD16         height,        /* Height of the window (in pixels) */
    -                               CARD16         border_width,  /* Width of the window's border (in pixels) */
    -                               CARD16         _class,
    -                               XCBVISUALID    visual,
    -                               CARD32         value_mask,
    -                               const CARD32  *value_list);
    +xcb_void_cookie_t xcb_create_window (xcb_connection_t *c,             /* Pointer to the xcb_connection_t structure */
    +                                     uint8_t           depth,         /* Depth of the screen */
    +                                     xcb_window_t      wid,           /* Id of the window */
    +                                     xcb_window_t      parent,        /* Id of an existing window that should be the parent of the new window */
    +                                     int16_t           x,             /* X position of the top-left corner of the window (in pixels) */
    +                                     int16_t           y,             /* Y position of the top-left corner of the window (in pixels) */
    +                                     uint16_t          width,         /* Width of the window (in pixels) */
    +                                     uint16_t          height,        /* Height of the window (in pixels) */
    +                                     uint16_t          border_width,  /* Width of the window's border (in pixels) */
    +                                     uint16_t          _class,
    +                                     xcb_visualid_t     visual,
    +                                     uint32_t          value_mask,
    +                                     const uint32_t   *value_list);
     

    The fact that we created the window does not mean that it will be drawn on screen. By default, newly created windows are not mapped on the screen (they are invisible). In order to make our - window visible, we use the function XCBMapWindow(), whose + window visible, we use the function xcb_map_window(), whose prototype is

    -XCBVoidCookie XCBMapWindow (XCBConnection *c, XCBWINDOW window);
    +xcb_void_cookie_t xcb_map_window (xcb_connection_t *c,
    +                                  xcb_window_t      window);
     

    Finally, here is a small program to create a window of size @@ -777,72 +774,72 @@ XCBVoidCookie XCBMapWindow (XCBConnection *c, XCBWINDOW window); int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBDRAWABLE win; - + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_drawable_t win; + /* Open the connection to the X server */ - c = XCBConnect (NULL, NULL); - + c = xcb_connect (NULL, NULL); + /* Get the first screen */ - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; /* Ask for our window's Id */ - win.window = XCBWINDOWNew(c); + win.window = xcb_window_new(c); /* Create the window */ - XCBCreateWindow (c, /* Connection */ - XCBCopyFromParent, /* depth (same as root)*/ - win.window, /* window Id */ - screen->root, /* parent window */ - 0, 0, /* x, y */ - 150, 150, /* width, height */ - 10, /* border_width */ - XCBWindowClassInputOutput,/* class */ - screen->root_visual, /* visual */ - 0, NULL); /* masks, not used yet */ + xcb_create_window (c, /* Connection */ + XCB_COPY_FROM_PARENT, /* depth (same as root)*/ + win.window, /* window Id */ + screen->root, /* parent window */ + 0, 0, /* x, y */ + 150, 150, /* width, height */ + 10, /* border_width */ + XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ + screen->root_visual, /* visual */ + 0, NULL); /* masks, not used yet */ /* Map the window on the screen */ - XCBMapWindow (c, win.window); + xcb_map_window (c, win.window); /* Make sure commands are sent before we pause, so window is shown */ - XCBFlush (c); - + xcb_flush (c); + pause (); /* hold client until Ctrl-C */ - return 1; + return 0; }

    - In this code, you see one more function - XCBFlush(), not explained + In this code, you see one more function - xcb_flush(), not explained yet. It is used to flush all the pending requests. More precisely, there are 2 functions that do such things. The first - one is XCBFlush(): + one is xcb_flush():

    -int XCBFlush (XCBConnection *c);
    +int xcb_flush (xcb_connection_t *c);
     

    This function flushes all pending requests to the X server (much like the fflush() function is used to - flush standard output). The second function is - XCBSync(): + flush standard output). The second function is + xcb_sync():

    -int XCBSync(XCBConnection *c, XCBGenericError **e);
    +int xcb_aux_sync (xcb_connection_t *c);
     

    This functions also flushes all pending requests to the X server, and then waits until the X server finishing processing these requests. In a normal program, this will not be necessary (we'll see why when we get to write a normal X program), but for - now, we put it there. + now, we put it there.

    The window that is created by the above code has a default background (gray). This one can be set to a specific color, thanks to the two last parameters of - XCBCreateWindow(), which are not + xcb_create_window(), which are not described yet. See the subsections Configuring a window or Registering for event types using event masks @@ -865,8 +862,8 @@ int XCBSync(XCBConnection *c, XCBGenericError **e);

      -
    • XCBWINDOWNew () -
    • XCBCreateWindow () +
    • xcb_window_new () +
    • xcb_create_window ()
    @@ -891,64 +888,64 @@ int XCBSync(XCBConnection *c, XCBGenericError **e);

     typedef struct {
    -    CARD32 xid;
    -} XCBGCONTEXT;
    +    uint32_t xid;
    +} xcb_gcontext_t;
     

    We first ask the X server to attribute an Id to our graphic context with this function:

    -XCBGCONTEXT XCBGCONTEXTNew (XCBConnection *c);
    +xcb_gcontext_t xcb_gcontext_new (xcb_connection_t *c);
     

    Then, we set the attributes of the graphic context with this function:

    -XCBVoidCookie XCBCreateGC (XCBConnection *c,
    -                           XCBGCONTEXT    cid,
    -                           XCBDRAWABLE    drawable,
    -                           CARD32         value_mask,
    -                           const CARD32  *value_list);
    +xcb_void_cookie_t xcb_create_gc (xcb_connection_t *c,
    +                                 xcb_gcontext_t    cid,
    +                                 xcb_drawable_t    drawable,
    +                                 uint32_t          value_mask,
    +                                 const uint32_t   *value_list);
     

    We give now an example on how to allocate a graphic context that specifies that each drawing function that uses it will draw in foreground with a black color. -

    +

     #include <X11/XCB/xcb.h>
     
     int
     main (int argc, char *argv[])
     {
    -  XCBConnection *c;
    -  XCBSCREEN     *screen;
    -  XCBDRAWABLE    win;
    -  XCBGCONTEXT    black;
    -  CARD32         mask;
    -  CARD32         value[1];
    -  
    +  xcb_connection_t *c;
    +  xcb_screen_t     *screen;
    +  xcb_drawable_t    win;
    +  xcb_gcontext_t    black;
    +  uint32_t          mask;
    +  uint32_t          value[1];
    +
       /* Open the connection to the X server and get the first screen */
    -  c = XCBConnect (NULL, NULL);
    -  screen = XCBSetupRootsIter (XCBGetSetup (c)).data;
    +  c = xcb_connect (NULL, NULL);
    +  screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
     
       /* Create a black graphic context for drawing in the foreground */
       win.window = screen->root;
    -  black = XCBGCONTEXTNew (c);
    -  mask = XCBGCForeground;
    +  black = xcb_gcontext_new (c);
    +  mask = XCB_GC_FOREGROUND;
       value[0] = screen->black_pixel;
    -  XCBCreateGC (c, black, win, mask, value);
    +  xcb_create_gc (c, black, win, mask, value);
     
    -  return 1;
    +  return 0;
     }
     

    Note should be taken regarding the role of "value_mask" and - "value_list" in the prototype of XCBCreateGC(). Since a + "value_list" in the prototype of xcb_create_gc(). Since a graphic context has many attributes, and since we often just want to define a few of them, we need to be able to tell the - XCBCreateGC() which attributes we + xcb_create_gc() which attributes we want to set. This is what the "value_mask" parameter is for. We then use the "value_list" parameter to specify actual values for the attribute we defined in "value_mask". Thus, for @@ -973,8 +970,8 @@ main (int argc, char *argv[])

      -
    • XCBGCONTEXTNew () -
    • XCBCreateGC () +
    • xcb_gcontext_new () +
    • xcb_create_gc ()
    @@ -989,39 +986,39 @@ main (int argc, char *argv[]) by using this function:

    -XCBVoidCookie XCBChangeGC (XCBConnection *c,           /* The XCB Connection */
    -                           XCBGCONTEXT    gc,          /* The Graphic Context */
    -                           CARD32         value_mask,  /* Components of the Graphic Context that have to be set */
    -                           const CARD32  *value_list); /* Value as specified by value_mask */
    +xcb_void_cookie_t xcb_change_gc (xcb_connection_t *c,           /* The XCB Connection */
    +                                 xcb_gcontext_t    gc,          /* The Graphic Context */
    +                                 uint32_t          value_mask,  /* Components of the Graphic Context that have to be set */
    +                                 const uint32_t   *value_list); /* Value as specified by value_mask */
     

    The value_mask parameter could take - any combination of these masks from the XCBGC enumeration: + any combination of these masks from the xcb_gc_t enumeration:

    It is possible to set several attributes at the same @@ -1051,34 +1048,34 @@ XCBVoidCookie XCBChangeGC (XCBConnection *c, /* The XCB Connection */ To draw a point, or several points, we use

    -XCBVoidCookie XCBPolyPoint (XCBConnection  *c,               /* The connection to the X server */
    -                            BYTE            coordinate_mode, /* Coordinate mode, usually set to XCBCoordModeOrigin */
    -                            XCBDRAWABLE     drawable,        /* The drawable on which we want to draw the point(s) */
    -                            XCBGCONTEXT     gc,              /* The Graphic Context we use to draw the point(s) */
    -                            CARD32          points_len,      /* The number of points */
    -                            const XCBPOINT *points);         /* An array of points */
    +xcb_void_cookie_t xcb_poly_point (xcb_connection_t  *c,               /* The connection to the X server */
    +                                  uint8_t            coordinate_mode, /* Coordinate mode, usually set to XCB_COORD_MODE_ORIGIN */
    +                                  xcb_drawable_t     drawable,        /* The drawable on which we want to draw the point(s) */
    +                                  xcb_gcontext_t     gc,              /* The Graphic Context we use to draw the point(s) */
    +                                  uint32_t           points_len,      /* The number of points */
    +                                  const xcb_point_t *points);         /* An array of points */
     

    The coordinate_mode parameter specifies the coordinate mode. Available values are

    - If XCBCoordModePrevious is used, then all points but the first one + If XCB_COORD_MODE_PREVIOUS is used, then all points but the first one are relative to the immediately previous point.

    - The XCBPOINT type is just a + The xcb_point_t type is just a structure with two fields (the coordinates of the point):

     typedef struct {
    -    INT16 x;
    -    INT16 y;
    -} XCBPOINT;
    +    int16_t x;
    +    int16_t y;
    +} xcb_point_t;
     

    You could see an example in xpoints.c. TODO Set the link. @@ -1087,12 +1084,12 @@ typedef struct { To draw a line, or a polygonal line, we use

    -XCBVoidCookie XCBPolyLine (XCBConnection  *c,               /* The connection to the X server */
    -                           BYTE            coordinate_mode, /* Coordinate mode, usually set to XCBCoordModeOrigin */
    -                           XCBDRAWABLE     drawable,        /* The drawable on which we want to draw the line(s) */
    -                           XCBGCONTEXT     gc,              /* The Graphic Context we use to draw the line(s) */
    -                           CARD32          points_len,      /* The number of points in the polygonal line */
    -                           const XCBPOINT *points);         /* An array of points */
    +xcb_void_cookie_t xcb_poly_line (xcb_connection_t  *c,               /* The connection to the X server */
    +                                 uint8_t            coordinate_mode, /* Coordinate mode, usually set to XCB_COORD_MODE_ORIGIN */
    +                                 xcb_drawable_t     drawable,        /* The drawable on which we want to draw the line(s) */
    +                                 xcb_gcontext_t     gc,              /* The Graphic Context we use to draw the line(s) */
    +                                 uint32_t           points_len,      /* The number of points in the polygonal line */
    +                                 const xcb_point_t *points);         /* An array of points */
     

    This function will draw the line between the first and the @@ -1103,47 +1100,47 @@ XCBVoidCookie XCBPolyLine (XCBConnection *c, /* The connection to To draw a segment, or several segments, we use

    -XCBVoidCookie XCBPolySegment (XCBConnection    *c,              /* The connection to the X server */
    -                              XCBDRAWABLE       drawable,       /* The drawable on which we want to draw the segment(s) */
    -                              XCBGCONTEXT       gc,             /* The Graphic Context we use to draw the segment(s) */
    -                              CARD32            segments_len,   /* The number of segments */
    -                              const XCBSEGMENT *segments);      /* An array of segments */
    +xcb_void_cookie_t xcb_poly_segment (xcb_connection_t    *c,              /* The connection to the X server */
    +                                    xcb_drawable_t       drawable,       /* The drawable on which we want to draw the segment(s) */
    +                                    xcb_gcontext_t       gc,             /* The Graphic Context we use to draw the segment(s) */
    +                                    uint32_t             segments_len,   /* The number of segments */
    +                                    const xcb_segment_t *segments);      /* An array of segments */
     

    - The XCBSEGMENT type is just a + The xcb_segment_t type is just a structure with four fields (the coordinates of the two points that define the segment):

     typedef struct {
    -    INT16 x1;
    -    INT16 y1;
    -    INT16 x2;
    -    INT16 y2;
    -} XCBSEGMENT;
    +    int16_t x1;
    +    int16_t y1;
    +    int16_t x2;
    +    int16_t y2;
    +} xcb_segment_t;
     

    To draw a rectangle, or several rectangles, we use

    -XCBVoidCookie XCBPolyRectangle (XCBConnection      *c,              /* The connection to the X server */
    -                                XCBDRAWABLE         drawable,       /* The drawable on which we want to draw the rectangle(s) */
    -                                XCBGCONTEXT         gc,             /* The Graphic Context we use to draw the rectangle(s) */
    -                                CARD32              rectangles_len, /* The number of rectangles */
    -                                const XCBRECTANGLE *rectangles);    /* An array of rectangles */
    +xcb_void_cookie_t xcb_poly_rectangle (xcb_connection_t      *c,              /* The connection to the X server */
    +                                      xcb_drawable_t         drawable,       /* The drawable on which we want to draw the rectangle(s) */
    +                                      xcb_gcontext_t         gc,             /* The Graphic Context we use to draw the rectangle(s) */
    +                                      uint32_t               rectangles_len, /* The number of rectangles */
    +                                      const xcb_rectangle_t *rectangles);    /* An array of rectangles */
     

    - The XCBRECTANGLE type is just a + The xcb_rectangle_t type is just a structure with four fields (the coordinates of the top-left corner of the rectangle, and its width and height):

     typedef struct {
    -    INT16 x;
    -    INT16 y;
    -    CARD16 width;
    -    CARD16 height;
    -} XCBRECTANGLE;
    +    int16_t  x;
    +    int16_t  y;
    +    uint16_t width;
    +    uint16_t height;
    +} xcb_rectangle_t;
     
    @@ -1151,25 +1148,25 @@ typedef struct { To draw an elliptical arc, or several elliptical arcs, we use

    -XCBVoidCookie XCBPolyArc (XCBConnection *c,          /* The connection to the X server */
    -                          XCBDRAWABLE    drawable,   /* The drawable on which we want to draw the arc(s) */
    -                          XCBGCONTEXT    gc,         /* The Graphic Context we use to draw the arc(s) */
    -                          CARD32         arcs_len,   /* The number of arcs */
    -                          const XCBARC  *arcs);      /* An array of arcs */
    +xcb_void_cookie_t xcb_poly_arc (xcb_connection_t *c,          /* The connection to the X server */
    +                                xcb_drawable_t    drawable,   /* The drawable on which we want to draw the arc(s) */
    +                                xcb_gcontext_t    gc,         /* The Graphic Context we use to draw the arc(s) */
    +                                uint32_t          arcs_len,   /* The number of arcs */
    +                                const xcb_arc_t  *arcs);      /* An array of arcs */
     

    - The XCBARC type is a structure with + The xcb_arc_t type is a structure with six fields:

     typedef struct {
    -    INT16 x;        /* Top left x coordinate of the rectangle surrounding the ellipse */
    -    INT16 y;        /* Top left y coordinate of the rectangle surrounding the ellipse */
    -    CARD16 width;   /* Width of the rectangle surrounding the ellipse */
    -    CARD16 height;  /* Height of the rectangle surrounding the ellipse */
    -    INT16 angle1;   /* Angle at which the arc begins */
    -    INT16 angle2;   /* Angle at which the arc ends */
    -} XCBARC;
    +    int16_t  x;       /* Top left x coordinate of the rectangle surrounding the ellipse */
    +    int16_t  y;       /* Top left y coordinate of the rectangle surrounding the ellipse */
    +    uint16_t width;   /* Width of the rectangle surrounding the ellipse */
    +    uint16_t height;  /* Height of the rectangle surrounding the ellipse */
    +    int16_t  angle1;  /* Angle at which the arc begins */
    +    int16_t  angle2;  /* Angle at which the arc ends */
    +} xcb_arc_t;
     

    @@ -1196,13 +1193,13 @@ typedef struct { we use

    -XCBVoidCookie XCBFillPoly (XCBConnection  *c,
    -                           XCBDRAWABLE     drawable,
    -                           XCBGCONTEXT     gc,
    -                           CARD8           shape,
    -                           CARD8           coordinate_mode,
    -                           CARD32          points_len,
    -                           const XCBPOINT *points);
    +xcb_void_cookie_t xcb_fill_poly (xcb_connection_t  *c,
    +                                 xcb_drawable_t     drawable,
    +                                 xcb_gcontext_t     gc,
    +                                 uint8_t            shape,
    +                                 uint8_t            coordinate_mode,
    +                                 uint32_t           points_len,
    +                                 const xcb_point_t *points);
     

    The shape parameter specifies a @@ -1210,29 +1207,29 @@ XCBVoidCookie XCBFillPoly (XCBConnection *c, values are

      -
    • XCBPolyShapeComplex -
    • XCBPolyShapeNonconvex -
    • XCBPolyShapeConvex +
    • XCB_POLY_SHAPE_COMPLEX +
    • XCB_POLY_SHAPE_NONCONVEX +
    • XCB_POLY_SHAPE_CONVEX

    To fill one or several rectangles, we use

    -XCBVoidCookie XCBPolyFillRectangle (XCBConnection      *c,
    -                                    XCBDRAWABLE         drawable,
    -                                    XCBGCONTEXT         gc,
    -                                    CARD32              rectangles_len,
    -                                    const XCBRECTANGLE *rectangles);
    +xcb_void_cookie_t xcb_poly_fill_rectangle (xcb_connection_t      *c,
    +                                           xcb_drawable_t         drawable,
    +                                           xcb_gcontext_t         gc,
    +                                           uint32_t               rectangles_len,
    +                                           const xcb_rectangle_t *rectangles);
     

    To fill one or several arcs, we use

    -XCBVoidCookie XCBPolyFillArc (XCBConnection *c,
    -                              XCBDRAWABLE    drawable,
    -                              XCBGCONTEXT    gc,
    -                              CARD32         arcs_len,
    -                              const XCBARC  *arcs);
    +xcb_void_cookie_t xcb_poly_fill_arc (xcb_connection_t *c,
    +                                     xcb_drawable_t    drawable,
    +                                     xcb_gcontext_t    gc,
    +                                     uint32_t          arcs_len,
    +                                     const xcb_arc_t  *arcs);
     

    @@ -1245,152 +1242,121 @@ XCBVoidCookie XCBPolyFillArc (XCBConnection *c,

    TODO: Use screen->root_depth for depth parameter.

    -

    - TODO: Remove get_depth(). It isn't used! -

     #include <stdlib.h>
     #include <stdio.h>
     
     #include <X11/XCB/xcb.h>
     
    -/* Get the depth of the screen. Needed in order to draw something */
    -int
    -get_depth(XCBConnection *c,
    -          XCBSCREEN     *root)
    -{
    -  XCBDRAWABLE        drawable;
    -  XCBGetGeometryRep *geom;
    -  int                depth;
    -
    -  drawable.window = root->root;
    -  geom = XCBGetGeometryReply (c, XCBGetGeometry(c, drawable), 0);
    -
    -  if(!geom)
    -    {
    -      perror ("GetGeometry(root) failed");
    -      exit (0);
    -    }
    -  
    -  depth = geom->depth;
    -  free (geom);
    -
    -  return depth;
    -}
    -
     int
     main (int argc, char *argv[])
     {
    -  XCBConnection   *c;
    -  XCBSCREEN       *screen;
    -  XCBDRAWABLE      win;
    -  XCBGCONTEXT      foreground;
    -  XCBGenericEvent *e;
    -  CARD32           mask = 0;
    -  CARD32           values[2];
    +  xcb_connection_t    *c;
    +  xcb_screen_t        *screen;
    +  xcb_drawable_t       win;
    +  xcb_gcontext_t       foreground;
    +  xcb_generic_event_t *e;
    +  uint32_t             mask = 0;
    +  uint32_t             values[2];
     
       /* geometric objects */
    -  XCBPOINT         points[] = {
    +  xcb_point_t          points[] = {
         {10, 10},
         {10, 20},
         {20, 10},
         {20, 20}};
     
    -  XCBPOINT         polyline[] = {
    +  xcb_point_t          polyline[] = {
         {50, 10},
         { 5, 20},     /* rest of points are relative */
         {25,-20},
         {10, 10}};
     
    -  XCBSEGMENT       segments[] = {
    +  xcb_segment_t        segments[] = {
         {100, 10, 140, 30},
         {110, 25, 130, 60}};
     
    -  XCBRECTANGLE     rectangles[] = {
    +  xcb_rectangle_t      rectangles[] = {
         { 10, 50, 40, 20},
         { 80, 50, 10, 40}};
     
    -  XCBARC           arcs[] = {
    +  xcb_arc_t            arcs[] = {
         {10, 100, 60, 40, 0, 90 << 6},
         {90, 100, 55, 40, 0, 270 << 6}};
    -  
    +
       /* Open the connection to the X server */
    -  c = XCBConnect (NULL, NULL);
    -  
    +  c = xcb_connect (NULL, NULL);
    +
       /* Get the first screen */
    -  screen = XCBSetupRootsIter (XCBGetSetup (c)).data;
    +  screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
     
       /* Create black (foreground) graphic context */
       win.window = screen->root;
     
    -  foreground = XCBGCONTEXTNew (c);
    -  mask = XCBGCForeground | XCBGCGraphicsExposures;
    +  foreground = xcb_gcontext_new (c);
    +  mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
       values[0] = screen->black_pixel;
       values[1] = 0;
    -  XCBCreateGC (c, foreground, win, mask, values);
    +  xcb_create_gc (c, foreground, win, mask, values);
     
       /* Ask for our window's Id */
    -  win.window = XCBWINDOWNew(c);
    +  win.window = xcb_window_new(c);
     
       /* Create the window */
    -  mask = XCBCWBackPixel | XCBCWEventMask;
    +  mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
       values[0] = screen->white_pixel;
    -  values[1] = XCBEventMaskExposure;
    -  XCBCreateWindow (c,                        /* Connection          */
    -                   XCBCopyFromParent,        /* depth               */
    -                   win.window,               /* window Id           */
    -                   screen->root,             /* parent window       */
    -                   0, 0,                     /* x, y                */
    -                   150, 150,                 /* width, height       */
    -                   10,                       /* border_width        */
    -                   XCBWindowClassInputOutput,/* class               */
    -                   screen->root_visual,      /* visual              */
    -                   mask, values);            /* masks */
    +  values[1] = XCB_EVENT_MASK_EXPOSURE;
    +  xcb_create_window (c,                             /* Connection          */
    +                     XCB_COPY_FROM_PARENT,          /* depth               */
    +                     win.window,                    /* window Id           */
    +                     screen->root,                  /* parent window       */
    +                     0, 0,                          /* x, y                */
    +                     150, 150,                      /* width, height       */
    +                     10,                            /* border_width        */
    +                     XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
    +                     screen->root_visual,           /* visual              */
    +                     mask, values);                 /* masks */
     
       /* Map the window on the screen */
    -  XCBMapWindow (c, win.window);
    +  xcb_map_window (c, win.window);
     
     
       /* We flush the request */
    -  XCBFlush (c);
    -
    -  while ((e = XCBWaitForEvent (c)))
    -    {
    -      switch (e->response_type & ~0x80)
    -        {
    -        case XCBExpose:
    -          {
    -            /* We draw the points */
    -            XCBPolyPoint (c, XCBCoordModeOrigin, win, foreground, 4, points);
    -            
    -            /* We draw the polygonal line */
    -            XCBPolyLine (c, XCBCoordModePrevious, win, foreground, 4, polyline);
    -            
    -            /* We draw the segements */
    -            XCBPolySegment (c, win, foreground, 2, segments);
    -            
    -            /* We draw the rectangles */
    -            XCBPolyRectangle (c, win, foreground, 2, rectangles);
    -            
    -            /* We draw the arcs */
    -            XCBPolyArc (c, win, foreground, 2, arcs);
    -
    -            /* We flush the request */
    -            XCBFlush (c);
    -            
    -            break;
    -          }
    -        default:
    -          {
    -            /* Unknown event type, ignore it */
    -            break;
    -          }
    -        }
    -      /* Free the Generic Event */
    -      free (e);
    +  xcb_flush (c);
    +
    +  while ((e = xcb_wait_for_event (c))) {
    +    switch (e->response_type & ~0x80) {
    +    case XCB_EXPOSE: {
    +      /* We draw the points */
    +      xcb_poly_point (c, XCB_COORD_MODE_ORIGIN, win, foreground, 4, points);
    +
    +      /* We draw the polygonal line */
    +      xcb_poly_line (c, XCB_COORD_MODE_PREVIOUS, win, foreground, 4, polyline);
    +
    +      /* We draw the segements */
    +      xcb_poly_segment (c, win, foreground, 2, segments);
    +
    +      /* We draw the rectangles */
    +      xcb_poly_rectangle (c, win, foreground, 2, rectangles);
    +
    +      /* We draw the arcs */
    +      xcb_poly_arc (c, win, foreground, 2, arcs);
    +
    +      /* We flush the request */
    +      xcb_flush (c);
    +
    +      break;
    +    }
    +    default: {
    +      /* Unknown event type, ignore it */
    +      break;
    +    }
         }
    +    /* Free the Generic Event */
    +    free (e);
    +  }
     
    -  return 1;
    +  return 0;
     }
     
    @@ -1418,32 +1384,32 @@ main (int argc, char *argv[])

    In XCB, you use the "value_mask" and "value_list" data in the - XCBCreateWindow() function to + xcb_create_window() function to register for events. Here is how we register for Expose event when creating a window:

    -  mask = XCBCWEventMask;
    -  valwin[0] = XCBEventMaskExposure;
    -  win.window = XCBWINDOWNew (c);
    -  XCBCreateWindow (c, depth, win.window, root->root,
    -                   0, 0, 150, 150, 10,
    -                   XCBWindowClassInputOutput, root->root_visual,
    -                   mask, valwin);
    +  mask = XCB_CW_EVENT_MASK;
    +  valwin[0] = XCB_EVENT_MASK_EXPOSURE;
    +  win.window = xcb_window_new (c);
    +  xcb_create_window (c, depth, win.window, root->root,
    +                     0, 0, 150, 150, 10,
    +                     XCB_WINDOW_CLASS_INPUT_OUTPUT, root->root_visual,
    +                     mask, valwin);
     

    - XCBEventMaskExposure is a constant defined - in the XCBEventMask enumeration in the "xproto.h" header file. If we wanted to register for several + XCB_EVENT_MASK_EXPOSURE is a constant defined + in the xcb_event_mask_t enumeration in the "xproto.h" header file. If we wanted to register for several event types, we can logically "or" them, as follows:

    -  mask = XCBCWEventMask;
    -  valwin[0] = XCBEventMaskExposure | XCBEventMaskButtonPress;
    -  win.window = XCBWINDOWNew (c);
    -  XCBCreateWindow (c, depth, win.window, root->root,
    -                   0, 0, 150, 150, 10,
    -                   XCBWindowClassInputOutput, root->root_visual,
    -                   mask, valwin);
    +  mask = XCB_CW_EVENT_MASK;
    +  valwin[0] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS;
    +  win.window = xcb_window_new (c);
    +  xcb_create_window (c, depth, win.window, root->root,
    +                     0, 0, 150, 150, 10,
    +                     XCB_WINDOW_CLASS_INPUT_OUTPUT, root->root_visual,
    +                     mask, valwin);
     

    This registers for Expose events as @@ -1453,43 +1419,43 @@ main (int argc, char *argv[])

    The values that a mask could take are given - by the XCBCW enumeration: + by the xcb_cw_t enumeration:

     typedef enum {
    -    XCBCWBackPixmap       = 1L<<0,
    -    XCBCWBackPixel        = 1L<<1,
    -    XCBCWBorderPixmap     = 1L<<2,
    -    XCBCWBorderPixel      = 1L<<3,
    -    XCBCWBitGravity       = 1L<<4,
    -    XCBCWWinGravity       = 1L<<5,
    -    XCBCWBackingStore     = 1L<<6,
    -    XCBCWBackingPlanes    = 1L<<7,
    -    XCBCWBackingPixel     = 1L<<8,
    -    XCBCWOverrideRedirect = 1L<<9,
    -    XCBCWSaveUnder        = 1L<<10,
    -    XCBCWEventMask        = 1L<<11,
    -    XCBCWDontPropagate    = 1L<<12,
    -    XCBCWColormap         = 1L<<13,
    -    XCBCWCursor           = 1L<<14
    -} XCBCW;
    +    XCB_CW_BACK_PIXMAP       = 1L<<0,
    +    XCB_CW_BACK_PIXEL        = 1L<<1,
    +    XCB_CW_BORDER_PIXMAP     = 1L<<2,
    +    XCB_CW_BORDER_PIXEL      = 1L<<3,
    +    XCB_CW_BIT_GRAVITY       = 1L<<4,
    +    XCB_CW_WIN_GRAVITY       = 1L<<5,
    +    XCB_CW_BACKING_STORE     = 1L<<6,
    +    XCB_CW_BACKING_PLANES    = 1L<<7,
    +    XCB_CW_BACKING_PIXEL     = 1L<<8,
    +    XCB_CW_OVERRIDE_REDIRECT = 1L<<9,
    +    XCB_CW_SAVE_UNDER        = 1L<<10,
    +    XCB_CW_EVENT_MASK        = 1L<<11,
    +    XCB_CW_DONT_PROPAGATE    = 1L<<12,
    +    XCB_CW_COLORMAP          = 1L<<13,
    +    XCB_CW_CURSOR            = 1L<<14
    +} xcb_cw_t;
     

    Note: we must be careful when setting the values of the valwin parameter, as they have to follow the order the - XCBCW enumeration. Here is an + xcb_cw_t enumeration. Here is an example:

    -  mask = XCBCWEventMask | XCBCWBackPixmap;
    -  valwin[0] = XCBNone;                           /* for XCBCWBackPixmap (whose value is 1)    */
    -  valwin[1] = XCBEventMaskExposure | XCBEventMaskButtonPress; /* for XCBCWEventMask, whose value (2048)    */
    -                                              /* is greater than the one of XCBCWBackPixmap */
    +  mask = XCB_CW_EVENT_MASK | XCB_CW_BACK_PIXMAP;
    +  valwin[0] = XCB_NONE;                                              /* for XCB_CW_BACK_PIXMAP (whose value is 1)     */
    +  valwin[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS; /* for XCB_CW_EVENT_MASK, whose value (2048)     */
    +                                                                     /* is greater than the one of XCB_CW_BACK_PIXMAP */
     

    If the window has already been created, we can use the - XCBConfigureWindow() function to set + xcb_configure_window() function to set the events that the window will receive. The subsection Configuring a window shows its prototype. As an example, here is a piece of code that @@ -1498,11 +1464,11 @@ typedef enum { ButtonPress events:

    -const static CARD32 values[] = { XCBEventMaskExposure | XCBEventMaskButtonPress };
    +const static uint32_t values[] = { XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS };
     
     /* The connection c and the window win are supposed to be defined */
     
    -XCBConfigureWindow (c, win, XCBCWEventMask, values);
    +xcb_configure_window (c, win, XCB_CW_EVENT_MASK, values);
     

    @@ -1524,16 +1490,16 @@ XCBConfigureWindow (c, win, XCBCWEventMask, values);

    • - XCBWaitForEvent (XCBConnection *c) + xcb_wait_for_event (xcb_connection_t *c) is the blocking way. It waits (so blocks...) until an event is queued in the X server. Then it retrieves it into a newly allocated structure (it dequeues it from the queue) and returns it. This structure has to be freed. The function returns NULL if an error occurs. - +
    • - XCBPollForEvent (XCBConnection *c, int + xcb_poll_for_event (xcb_connection_t *c, int *error) is the non-blocking way. It looks at the event queue and returns (and dequeues too) an existing event into a newly allocated structure. This structure has to be @@ -1545,76 +1511,69 @@ XCBConfigureWindow (c, win, XCBCWEventMask, values);

      There are various ways to write such a loop. We present two ways to write such a loop, with the two functions above. The - first one uses XCBWaitForEvent, which + first one uses xcb_wait_for_event_t, which is similar to an event Xlib loop using only XNextEvent:

      -  XCBGenericEvent *e;
      -
      -  while ((e = XCBWaitForEvent (c)))
      -    {
      -      switch (e->response_type & ~0x80)
      -        {
      -        case XCBExpose:
      -          {
      -            /* Handle the Expose event type */
      -            XCBExposeEvent *ev = (XCBExposeEvent *)e;
      -
      -            /* ... */
      -
      -            break;
      -          }
      -        case XCBButtonPress: 
      -          {
      -            /* Handle the ButtonPress event type */
      -            XCBButtonPressEvent *ev = (XCBButtonPressEvent *)e;
      -
      -            /* ... */
      -
      -            break;
      -          }
      -        default:
      -          {
      -            /* Unknown event type, ignore it */
      -            break;
      -          }
      -        }
      -      /* Free the Generic Event */
      -      free (e);
      +  xcb_generic_event_t *e;
      +
      +  while ((e = xcb_wait_for_event (c))) {
      +    switch (e->response_type & ~0x80) {
      +    case XCB_EXPOSE: {
      +      /* Handle the Expose event type */
      +      xcb_expose_event_t *ev = (xcb_expose_event_t *)e;
      +
      +      /* ... */
      +
      +      break;
           }
      +    case XCB_BUTTON_PRESS: {
      +      /* Handle the ButtonPress event type */
      +      xcb_button_press_event_t *ev = (xcb_button_press_event_t *)e;
      +
      +      /* ... */
      +
      +      break;
      +    }
      +    default: {
      +      /* Unknown event type, ignore it */
      +      break;
      +    }
      +    }
      +    /* Free the Generic Event */
      +    free (e);
      +  }
       

      You will certainly want to use XCBPollForEvent(XCBConnection *c, int + class="code">xcb_poll_for_event(xcb_connection_t *c, int *error) if, in Xlib, you use XPending or XCheckMaskEvent:

      -  while (XPending (display))
      -    {
      -      XEvent ev;
      +  while (XPending (display)) {
      +    XEvent ev;
       
      -      XNextEvent(d, &ev);
      -      
      -      /* Manage your event */
      -    }
      +    XNextEvent(d, &ev);
      +
      +    /* Manage your event */
      +  }
       

      Such a loop in XCB looks like:

      -  XCBGenericEvent *ev;
      +  xcb_generic_event_t *ev;
       
      -  while ((ev = XCBPollForEvent (conn, 0)))
      -    {
      -      /* Manage your event */
      -    }
      +  while ((ev = xcb_poll_for_event (conn, 0))) {
      +    /* Manage your event */
      +  }
       

      The events are managed in the same way as with XCBWaitForEvent. + class="code">xcb_wait_for_event_t. Obviously, we will need to give the user some way of terminating the program. This is usually done by handling a special "quit" event, as we will soon see. @@ -1630,18 +1589,18 @@ XCBConfigureWindow (c, win, XCBCWEventMask, values);

      -
    • XCBWaitForEvent () +
    • xcb_wait_for_event ()
      -
    • XPending ()
    • -
    • XCheckMaskEvent ()
    • +
    • XPending () +
    • XCheckMaskEvent ()
      -
    • XCBPollForEvent () +
    • xcb_poll_for_event ()
    @@ -1677,17 +1636,17 @@ XCBConfigureWindow (c, win, XCBCWEventMask, values);

     typedef struct {
    -    BYTE response_type;  /* The type of the event, here it is XCBExpose */
    -    CARD8 pad0;
    -    CARD16 sequence;
    -    XCBWINDOW window;    /* The Id of the window that receives the event (in case */
    -                         /* our application registered for events on several windows */
    -    CARD16 x;            /* The x coordinate of the top-left part of the window that needs to be redrawn */
    -    CARD16 y;            /* The y coordinate of the top-left part of the window that needs to be redrawn */
    -    CARD16 width;        /* The width of the part of the window that needs to be redrawn */
    -    CARD16 height;       /* The height of the part of the window that needs to be redrawn */
    -    CARD16 count;
    -} XCBExposeEvent;
    +    uint8_t      response_type; /* The type of the event, here it is XCB_EXPOSE */
    +    uint8_t      pad0;
    +    uint16_t     sequence;
    +    xcb_window_t window;        /* The Id of the window that receives the event (in case */
    +                                /* our application registered for events on several windows */
    +    uint16_t     x;             /* The x coordinate of the top-left part of the window that needs to be redrawn */
    +    uint16_t     y;             /* The y coordinate of the top-left part of the window that needs to be redrawn */
    +    uint16_t     width;         /* The width of the part of the window that needs to be redrawn */
    +    uint16_t     height;        /* The height of the part of the window that needs to be redrawn */
    +    uint16_t     count;
    +} xcb_expose_event_t;
     
  • Getting user input

    @@ -1706,9 +1665,9 @@ typedef struct { (or more) of the following masks when we create our window:

    @@ -1717,22 +1676,22 @@ typedef struct {

     typedef struct {
    -    BYTE response_type;  /* The type of the event, here it is XCBButtonPressEvent or XCBButtonReleaseEvent */
    -    XCBBUTTON detail;
    -    CARD16 sequence;
    -    XCBTIMESTAMP time;   /* Time, in milliseconds the event took place in */
    -    XCBWINDOW root;
    -    XCBWINDOW event;
    -    XCBWINDOW child;
    -    INT16 root_x;
    -    INT16 root_y;
    -    INT16 event_x;       /* The x coordinate where the mouse has been pressed in the window */
    -    INT16 event_y;       /* The y coordinate where the mouse has been pressed in the window */
    -    CARD16 state;        /* A mask of the buttons (or keys) during the event */
    -    BOOL same_screen;
    -} XCBButtonPressEvent;
    -
    -typedef XCBButtonPressEvent XCBButtonReleaseEvent;
    +    uint8_t         response_type; /* The type of the event, here it is xcb_button_press_event_t or xcb_button_release_event_t */
    +    xcb_button_t    detail;
    +    uint16_t        sequence;
    +    xcb_timestamp_t time;          /* Time, in milliseconds the event took place in */
    +    xcb_window_t    root;
    +    xcb_window_t    event;
    +    xcb_window_t    child;
    +    int16_t         root_x;
    +    int16_t         root_y;
    +    int16_t         event_x;       /* The x coordinate where the mouse has been pressed in the window */
    +    int16_t         event_y;       /* The y coordinate where the mouse has been pressed in the window */
    +    uint16_t        state;         /* A mask of the buttons (or keys) during the event */
    +    uint8_t         same_screen;
    +} xcb_button_press_event_t;
    +
    +typedef xcb_button_press_event_t xcb_button_release_event_t;
     

    The time field may be used to calculate "double-click" @@ -1742,23 +1701,23 @@ typedef XCBButtonPressEvent XCBButtonReleaseEvent;

    The state field is a mask of the buttons held down during - the event. It is a bitwise OR of any of the following (from the XCBButtonMask and - XCBModMask enumerations): + the event. It is a bitwise OR of any of the following (from the xcb_button_mask_t and + xcb_mod_mask_t enumerations):

    Their names are self explanatory, where the first 5 refer to @@ -1771,7 +1730,7 @@ typedef XCBButtonPressEvent XCBButtonReleaseEvent; change when clicking with various buttons.

  • Mouse movement events -

    +

    Similar to mouse button press and release events, we also can be notified of various mouse movement events. These can be split into two families. One is of mouse pointer @@ -1782,20 +1741,20 @@ typedef XCBButtonPressEvent XCBButtonReleaseEvent; during the creation of our window:

    @@ -1804,20 +1763,20 @@ typedef XCBButtonPressEvent XCBButtonReleaseEvent;

     typedef struct {
    -    BYTE response_type;  /* The type of the event */
    -    BYTE detail;
    -    CARD16 sequence;
    -    XCBTIMESTAMP time;   /* Time, in milliseconds the event took place in */
    -    XCBWINDOW root;
    -    XCBWINDOW event;
    -    XCBWINDOW child;
    -    INT16 root_x;
    -    INT16 root_y;
    -    INT16 event_x;       /* The x coordinate of the mouse when the  event was generated */
    -    INT16 event_y;       /* The y coordinate of the mouse when the  event was generated */
    -    CARD16 state;        /* A mask of the buttons (or keys) during the event */
    -    BOOL same_screen;
    -} XCBMotionNotifyEvent;
    +    uint8_t         response_type; /* The type of the event */
    +    uint8_t         detail;
    +    uint16_t        sequence;
    +    xcb_timestamp_t time;          /* Time, in milliseconds the event took place in */
    +    xcb_window_t    root;
    +    xcb_window_t    event;
    +    xcb_window_t    child;
    +    int16_t         root_x;
    +    int16_t         root_y;
    +    int16_t         event_x;       /* The x coordinate of the mouse when the  event was generated */
    +    int16_t         event_y;       /* The y coordinate of the mouse when the  event was generated */
    +    uint16_t        state;         /* A mask of the buttons (or keys) during the event */
    +    uint8_t         same_screen;
    +} xcb_motion_notify_event_t;
     
  • Mouse pointer enter and leave events

    @@ -1830,10 +1789,10 @@ typedef struct { create our window:

    @@ -1843,23 +1802,23 @@ typedef struct {

     typedef struct {
    -    BYTE response_type;  /* The type of the event */
    -    BYTE detail;
    -    CARD16 sequence;
    -    XCBTIMESTAMP time;   /* Time, in milliseconds the event took place in */
    -    XCBWINDOW root;
    -    XCBWINDOW event;
    -    XCBWINDOW child;
    -    INT16 root_x;
    -    INT16 root_y;
    -    INT16 event_x;       /* The x coordinate of the mouse when the  event was generated */
    -    INT16 event_y;       /* The y coordinate of the mouse when the  event was generated */
    -    CARD16 state;        /* A mask of the buttons (or keys) during the event */
    -    BYTE mode;           /* The number of mouse button that was clicked */
    -    BYTE same_screen_focus;
    -} XCBEnterNotifyEvent;
    -
    -typedef XCBEnterNotifyEvent XCBLeaveNotifyEvent;
    +    uint8_t         response_type; /* The type of the event */
    +    uint8_t         detail;
    +    uint16_t        sequence;
    +    xcb_timestamp_t time;          /* Time, in milliseconds the event took place in */
    +    xcb_window_t    root;
    +    xcb_window_t    event;
    +    xcb_window_t    child;
    +    int16_t         root_x;
    +    int16_t         root_y;
    +    int16_t         event_x;       /* The x coordinate of the mouse when the  event was generated */
    +    int16_t         event_y;       /* The y coordinate of the mouse when the  event was generated */
    +    uint16_t        state;         /* A mask of the buttons (or keys) during the event */
    +    uint8_t         mode;          /* The number of mouse button that was clicked */
    +    uint8_t         same_screen_focus;
    +} xcb_enter_notify_event_t;
    +
    +typedef xcb_enter_notify_event_t xcb_leave_notify_event_t;
     
  • The keyboard focus

    @@ -1884,10 +1843,10 @@ typedef XCBEnterNotifyEvent XCBLeaveNotifyEvent; masks when we create our window:

    @@ -1897,22 +1856,22 @@ typedef XCBEnterNotifyEvent XCBLeaveNotifyEvent;

     typedef struct {
    -    BYTE response_type;  /* The type of the event */
    -    XCBKEYCODE detail;
    -    CARD16 sequence;
    -    XCBTIMESTAMP time;   /* Time, in milliseconds the event took place in */
    -    XCBWINDOW root;
    -    XCBWINDOW event;
    -    XCBWINDOW child;
    -    INT16 root_x;
    -    INT16 root_y;
    -    INT16 event_x;
    -    INT16 event_y;
    -    CARD16 state;
    -    BOOL same_screen;
    -} XCBKeyPressEvent;
    -
    -typedef XCBKeyPressEvent XCBKeyReleaseEvent;
    +    uint8_t         response_type; /* The type of the event */
    +    xcb_keycode_t   detail;
    +    uint16_t        sequence;
    +    xcb_timestamp_t time;          /* Time, in milliseconds the event took place in */
    +    xcb_window_t    root;
    +    xcb_window_t    event;
    +    xcb_window_t    child;
    +    int16_t         root_x;
    +    int16_t         root_y;
    +    int16_t         event_x;
    +    int16_t         event_y;
    +    uint16_t        state;
    +    uint8_t         same_screen;
    +} xcb_key_press_event_t;
    +
    +typedef xcb_key_press_event_t xcb_key_release_event_t;
     

    The detail field refers to the @@ -1938,162 +1897,145 @@ typedef XCBKeyPressEvent XCBKeyReleaseEvent; #include <X11/XCB/xcb.h> void -print_modifiers(CARD32 mask) +print_modifiers (uint32_t mask) { const char **mod, *mods[] = { "Shift", "Lock", "Ctrl", "Alt", "Mod2", "Mod3", "Mod4", "Mod5", "Button1", "Button2", "Button3", "Button4", "Button5" }; - printf("Modifier mask: "); + printf ("Modifier mask: "); for (mod = mods ; mask; mask >>= 1, mod++) if (mask & 1) printf(*mod); - putchar('\n'); + putchar ('\n'); } int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBDRAWABLE win; - XCBGenericEvent *e; - CARD32 mask = 0; - CARD32 values[2]; - + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_drawable_t win; + xcb_generic_event_t *e; + uint32_t mask = 0; + uint32_t values[2]; + /* Open the connection to the X server */ - c = XCBConnect (NULL, NULL); - + c = xcb_connect (NULL, NULL); + /* Get the first screen */ - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; /* Ask for our window's Id */ - win.window = XCBWINDOWNew(c); + win.window = xcb_window_new (c); /* Create the window */ - mask = XCBCWBackPixel | XCBCWEventMask; + mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; - values[1] = XCBEventMaskExposure | XCBEventMaskButtonPress - | XCBEventMaskButtonRelease | XCBEventMaskPointerMotion - | XCBEventMaskEnterWindow | XCBEventMaskLeaveWindow - | XCBEventMaskKeyPress | XCBEventMaskKeyRelease; - XCBCreateWindow (c, /* Connection */ - 0, /* depth */ - win.window, /* window Id */ - screen->root, /* parent window */ - 0, 0, /* x, y */ - 150, 150, /* width, height */ - 10, /* border_width */ - XCBWindowClassInputOutput,/* class */ - screen->root_visual, /* visual */ - mask, values); /* masks */ + values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | + XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | + XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | + XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE; + xcb_create_window (c, /* Connection */ + 0, /* depth */ + win.window, /* window Id */ + screen->root, /* parent window */ + 0, 0, /* x, y */ + 150, 150, /* width, height */ + 10, /* border_width */ + XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ + screen->root_visual, /* visual */ + mask, values); /* masks */ /* Map the window on the screen */ - XCBMapWindow (c, win.window); - - XCBFlush (c); - - while ((e = XCBWaitForEvent (c))) - { - switch (e->response_type & ~0x80) - { - case XCBExpose: - { - XCBExposeEvent *ev = (XCBExposeEvent *)e; - - printf ("Window %ld exposed. Region to be redrawn at location (%d,%d), with dimension (%d,%d)\n", - ev->window.xid, ev->x, ev->y, ev->width, ev->height); - break; - } - case XCBButtonPress: - { - XCBButtonPressEvent *ev = (XCBButtonPressEvent *)e; - print_modifiers(ev->state); - - switch (ev->detail.id) - { - case 4: - { - printf ("Wheel Button up in window %ld, at coordinates (%d,%d)\n", - ev->event.xid, ev->event_x, ev->event_y); - break; - } - case 5: - { - printf ("Wheel Button down in window %ld, at coordinates (%d,%d)\n", - ev->event.xid, ev->event_x, ev->event_y); - break; - } - default: - printf ("Button %d pressed in window %ld, at coordinates (%d,%d)\n", - ev->detail.id, ev->event.xid, ev->event_x, ev->event_y); - } - break; - } - case XCBButtonRelease: - { - XCBButtonReleaseEvent *ev = (XCBButtonReleaseEvent *)e; - print_modifiers(ev->state); - - printf ("Button %d released in window %ld, at coordinates (%d,%d)\n", - ev->detail.id, ev->event.xid, ev->event_x, ev->event_y); - break; - } - case XCBMotionNotify: - { - XCBMotionNotifyEvent *ev = (XCBMotionNotifyEvent *)e; - - printf ("Mouse moved in window %ld, at coordinates (%d,%d)\n", - ev->event.xid, ev->event_x, ev->event_y); - break; - } - case XCBEnterNotify: - { - XCBEnterNotifyEvent *ev = (XCBEnterNotifyEvent *)e; - - printf ("Mouse entered window %ld, at coordinates (%d,%d)\n", - ev->event.xid, ev->event_x, ev->event_y); - break; - } - case XCBLeaveNotify: - { - XCBLeaveNotifyEvent *ev = (XCBLeaveNotifyEvent *)e; - - printf ("Mouse left window %ld, at coordinates (%d,%d)\n", - ev->event.xid, ev->event_x, ev->event_y); - break; - } - case XCBKeyPress: - { - XCBKeyPressEvent *ev = (XCBKeyPressEvent *)e; - print_modifiers(ev->state); - - printf ("Key pressed in window %ld\n", - ev->event.xid); - break; - } - case XCBKeyRelease: - { - XCBKeyReleaseEvent *ev = (XCBKeyReleaseEvent *)e; - print_modifiers(ev->state); - - printf ("Key released in window %ld\n", - ev->event.xid); - break; - } - default: - { - /* Unknown event type, ignore it */ - printf("Unknown event: %d\n", e->response_type); - break; - } - } - /* Free the Generic Event */ - free (e); + xcb_map_window (c, win.window); + + xcb_flush (c); + + while ((e = xcb_wait_for_event (c))) { + switch (e->response_type & ~0x80) { + case XCB_EXPOSE: { + xcb_expose_event_t *ev = (xcb_expose_event_t *)e; + + printf ("Window %ld exposed. Region to be redrawn at location (%d,%d), with dimension (%d,%d)\n", + ev->window.xid, ev->x, ev->y, ev->width, ev->height); + break; + } + case XCB_BUTTON_PRESS: { + xcb_button_press_event_t *ev = (xcb_button_press_event_t *)e; + print_modifiers(ev->state); + + switch (ev->detail.id) { + case 4: + printf ("Wheel Button up in window %ld, at coordinates (%d,%d)\n", + ev->event.xid, ev->event_x, ev->event_y); + break; + case 5: + printf ("Wheel Button down in window %ld, at coordinates (%d,%d)\n", + ev->event.xid, ev->event_x, ev->event_y); + break; + default: + printf ("Button %d pressed in window %ld, at coordinates (%d,%d)\n", + ev->detail.id, ev->event.xid, ev->event_x, ev->event_y); + } + break; + } + case XCB_BUTTON_RELEASE: { + xcb_button_release_event_t *ev = (xcb_button_release_event_t *)e; + print_modifiers(ev->state); + + printf ("Button %d released in window %ld, at coordinates (%d,%d)\n", + ev->detail.id, ev->event.xid, ev->event_x, ev->event_y); + break; + } + case XCB_MOTION_NOTIFY: { + xcb_motion_notify_event_t *ev = (xcb_motion_notify_event_t *)e; + + printf ("Mouse moved in window %ld, at coordinates (%d,%d)\n", + ev->event.xid, ev->event_x, ev->event_y); + break; + } + case XCB_ENTER_NOTIFY: { + xcb_enter_notify_event_t *ev = (xcb_enter_notify_event_t *)e; + + printf ("Mouse entered window %ld, at coordinates (%d,%d)\n", + ev->event.xid, ev->event_x, ev->event_y); + break; + } + case XCB_LEAVE_NOTIFY: { + xcb_leave_notify_event_t *ev = (xcb_leave_notify_event_t *)e; + + printf ("Mouse left window %ld, at coordinates (%d,%d)\n", + ev->event.xid, ev->event_x, ev->event_y); + break; } + case XCB_KEY_PRESS: { + xcb_key_press_event_t *ev = (xcb_key_press_event_t *)e; + print_modifiers(ev->state); - return 1; + printf ("Key pressed in window %ld\n", + ev->event.xid); + break; + } + case XCB_KEY_RELEASE: { + xcb_key_release_event_t *ev = (xcb_key_release_event_t *)e; + print_modifiers(ev->state); + + printf ("Key released in window %ld\n", + ev->event.xid); + break; + } + default: + /* Unknown event type, ignore it */ + printf("Unknown event: %d\n", e->response_type); + break; + } + /* Free the Generic Event */ + free (e); + } + + return 0; } @@ -2114,8 +2056,8 @@ main (int argc, char *argv[])

     typedef struct {
    -    CARD32 xid;
    -} XCBFONT;
    +    uint32_t xid;
    +} xcb_font_t;
     

    It is used to contain information about a font, and is passed @@ -2152,43 +2094,43 @@ typedef struct {

    The property and its type (a string, an integer, etc) are - Id. Their type are XCBATOM: + Id. Their type are xcb_atom_t:

     typedef struct {
    -    CARD32 xid;
    -} XCBATOM;
    +    uint32_t xid;
    +} xcb_atom_t;
     

    To change the property of a window, we use the following function:

    -XCBVoidCookie XCBChangeProperty (XCBConnection *c,  /* Connection to the X server */
    -                                 CARD8 mode,        /* Property mode */
    -                                 XCBWINDOW window,  /* Window */
    -                                 XCBATOM property,  /* Property to change */
    -                                 XCBATOM type,      /* Type of the property */
    -                                 CARD8 format,      /* Format of the property (8, 16, 32) */
    -                                 CARD32 data_len,   /* Length of the data parameter */
    -                                 const void *data); /* Data */
    +xcb_void_cookie_t xcb_change_property (xcb_connection_t *c,       /* Connection to the X server */
    +                                       uint8_t          mode,     /* Property mode */
    +                                       xcb_window_t     window,   /* Window */
    +                                       xcb_atom_t       property, /* Property to change */
    +                                       xcb_atom_t       type,     /* Type of the property */
    +                                       uint8_t          format,   /* Format of the property (8, 16, 32) */
    +                                       uint32_t         data_len, /* Length of the data parameter */
    +                                       const void      *data);    /* Data */
     

    The mode parameter coud be one of - the following values (defined in enumeration XCBPropMode in + the following values (defined in enumeration xcb_prop_mode_t in the xproto.h header file):


  • Setting the window name and icon name

    The first thing we want to do would be to set the name for our window. This is done using the - XCBChangeProperty() function. This + xcb_change_property() function. This name may be used by the window manager as the title of the window (in the title bar), in a task list, etc. The property atom to use to set the name of a window is @@ -2206,53 +2148,53 @@ XCBVoidCookie XCBChangeProperty (XCBConnection *c, /* Connection to the X serve int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBDRAWABLE win; - char *title = "Hello World !"; - char *title_icon = "Hello World ! (iconified)"; + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_window_t win; + char *title = "Hello World !"; + char *title_icon = "Hello World ! (iconified)"; + - /* Open the connection to the X server */ - c = XCBConnect (NULL, NULL); - + c = xcb_connect (NULL, NULL); + /* Get the first screen */ - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; /* Ask for our window's Id */ - win.window = XCBWINDOWNew(c); + win = xcb_window_new (c); /* Create the window */ - XCBCreateWindow (c, /* Connection */ - 0, /* depth */ - win.window, /* window Id */ - screen->root, /* parent window */ - 0, 0, /* x, y */ - 250, 150, /* width, height */ - 10, /* border_width */ - XCBWindowClassInputOutput,/* class */ - screen->root_visual, /* visual */ - 0, NULL); /* masks, not used */ + xcb_create_window (c, /* Connection */ + 0, /* depth */ + win, /* window Id */ + screen->root, /* parent window */ + 0, 0, /* x, y */ + 250, 150, /* width, height */ + 10, /* border_width */ + XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ + screen->root_visual, /* visual */ + 0, NULL); /* masks, not used */ /* Set the title of the window */ - XCBChangeProperty(c, XCBPropModeReplace, win.window, - WM_NAME, STRING, 8, - strlen(title), title); + xcb_change_property (c, XCB_PROP_MODE_REPLACE, win, + WM_NAME, STRING, 8, + strlen (title), title); /* Set the title of the window icon */ - XCBChangeProperty(c, XCBPropModeReplace, win.window, - WM_ICON_NAME, STRING, 8, - strlen(title_icon), title_icon); + xcb_change_property (c, XCB_PROP_MODE_REPLACE, win, + WM_ICON_NAME, STRING, 8, + strlen(title_icon), title_icon); /* Map the window on the screen */ - XCBMapWindow (c, win.window); + xcb_map_window (c, win); + + xcb_flush (c); - XCBFlush (c); - while (1) {} - return 1; + return 0; }

    @@ -2299,7 +2241,8 @@ gcc prog.c -o prog `pkg-config --cflags --libs xcb_atom` To map a window, you use the following function:

    -XCBVoidCookie XCBMapWindow(XCBConnection *c, XCBWINDOW window);
    +xcb_void_cookie_t xcb_map_window (xcb_connection_t *c,
    +                                  xcb_window_t      window);
     

    To have a simple example, see the example @@ -2312,11 +2255,12 @@ XCBVoidCookie XCBMapWindow(XCBConnection *c, XCBWINDOW window); Un-mapping a window is also simple. You use the function

    -XCBVoidCookie XCBUnmapWindow(XCBConnection *c, XCBWINDOW window);
    +xcb_void_cookie_t xcb_unmap_window (xcb_connection_t *c,
    +                                    xcb_window_t      window);
     

    The utilization of this function is the same as - XCBMapWindow(). + xcb_map_window().

  • Configuring a window

    @@ -2328,28 +2272,28 @@ XCBVoidCookie XCBUnmapWindow(XCBConnection *c, XCBWINDOW window); function:

    -XCBVoidCookie XCBConfigureWindow (XCBConnection *c,            /* The connection to the X server*/
    -                                  XCBWINDOW      window,       /* The window to configure */
    -                                  CARD16         value_mask,   /* The mask */
    -                                  const CARD32  *value_list);  /* The values to set */
    +xcb_void_cookie_t xcb_configure_window (xcb_connection_t *c,            /* The connection to the X server*/
    +                                        xcb_window_t      window,       /* The window to configure */
    +                                        uint16_t          value_mask,   /* The mask */
    +                                        const uint32_t   *value_list);  /* The values to set */
     

    We set the value_mask to one or - several mask values that are in the XCBConfigWindow enumeration in the xproto.h header: + several mask values that are in the xcb_config_window_t enumeration in the xproto.h header:

    We then give to value_mask the new value. We now describe how to use - XCBConfigureWindow in some useful + xcb_configure_window_t in some useful situations.

  • Moving a window around the screen @@ -2358,12 +2302,12 @@ XCBVoidCookie XCBConfigureWindow (XCBConnection *c, /* The connection to a different location. This can be done like this:

    -const static CARD32 values[] = { 10, 20 };
    +const static uint32_t values[] = { 10, 20 };
     
     /* The connection c and the window win are supposed to be defined */
     
     /* Move the window to coordinates x = 10 and y = 20 */
    -XCBConfigureWindow (c, win, XCBConfigWindowX | XCBConfigWindowY, values);
    +xcb_configure_window (c, win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
     

    Note that when the window is moved, it might get partially @@ -2377,25 +2321,25 @@ XCBConfigureWindow (c, win, XCBConfigWindowX | XCBConfigWindowY, values); window. This is done using the following code:

    -const static CARD32 values[] = { 200, 300 };
    +const static uint32_t values[] = { 200, 300 };
     
     /* The connection c and the window win are supposed to be defined */
     
     /* Resize the window to width = 10 and height = 20 */
    -XCBConfigureWindow (c, win, XCBConfigWindowWidth | XCBConfigWindowHeight, values);
    +xcb_configure_window (c, win, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
     

    We can also combine the move and resize operations using one - single call to XCBConfigureWindow: + single call to xcb_configure_window_t:

    -const static CARD32 values[] = { 10, 20, 200, 300 };
    +const static uint32_t values[] = { 10, 20, 200, 300 };
     
     /* The connection c and the window win are supposed to be defined */
     
     /* Move the window to coordinates x = 10 and y = 20 */
     /* and resize the window to width = 10 and height = 20 */
    -XCBConfigureWindow (c, win, XCBConfigWindowX | XCBConfigWindowY | XCBConfigWindowWidth | XCBConfigWindowHeight, values);
    +xcb_configure_window (c, win, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
     
  • Changing windows stacking order: raise and lower

    @@ -2408,20 +2352,20 @@ XCBConfigureWindow (c, win, XCBConfigWindowX | XCBConfigWindowY | XCBConfigWindo how to manipulate our windows stack order:

    -const static CARD32 values[] = { XCBStackModeAbove };
    +const static uint32_t values[] = { XCB_STACK_MODE_ABOVE };
     
     /* The connection c and the window win are supposed to be defined */
     
     /* Move the window on the top of the stack */
    -XCBConfigureWindow (c, win, XCBConfigWindowStackMode, values);
    +xcb_configure_window (c, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
     
    -const static CARD32 values[] = { XCBStackModeBelow };
    +const static uint32_t values[] = { XCB_STACK_MODE_BELOW };
     
     /* The connection c and the window win are supposed to be defined */
     
     /* Move the window on the bottom of the stack */
    -XCBConfigureWindow (c, win, XCBConfigWindowStackMode, values);
    +xcb_configure_window (c, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
     
  • Getting information about a window

    @@ -2434,47 +2378,47 @@ XCBConfigureWindow (c, win, XCBConfigWindowStackMode, values);

     typedef struct {
    -    BYTE response_type;
    -    CARD8 depth;            /* depth of the window */
    -    CARD16 sequence;
    -    CARD32 length;
    -    XCBWINDOW root;         /* Id of the root window *>
    -    INT16 x;                /* X coordinate of the window's location */
    -    INT16 y;                /* Y coordinate of the window's location */
    -    CARD16 width;           /* Width of the window */
    -    CARD16 height;          /* Height of the window */
    -    CARD16 border_width;    /* Width of the window's border */
    -} XCBGetGeometryRep;
    +    uint8_t      response_type;
    +    uint8_t      depth;         /* depth of the window */
    +    uint16_t     sequence;
    +    uint32_t     length;
    +    xcb_window_t root;          /* Id of the root window *>
    +    int16_t      x;             /* X coordinate of the window's location */
    +    int16_t      y;             /* Y coordinate of the window's location */
    +    uint16_t     width;         /* Width of the window */
    +    uint16_t     height;        /* Height of the window */
    +    uint16_t     border_width;  /* Width of the window's border */
    +} xcb_get_geometry_reply_t;
     

    XCB fill this structure with two functions:

    -XCBGetGeometryCookie  XCBGetGeometry      (XCBConnection         *c,
    -                                           XCBDRAWABLE            drawable);
    -XCBGetGeometryRep    *XCBGetGeometryReply (XCBConnection         *c,
    -                                           XCBGetGeometryCookie   cookie,
    -                                           XCBGenericError      **e);
    +xcb_get_geometry_cookie_t  xcb_get_geometry       (xcb_connection_t         *c,
    +                                                   xcb_drawable_t            drawable);
    +xcb_get_geometry_reply_t  *xcb_get_geometry_reply (xcb_connection_t         *c,
    +                                                   xcb_get_geometry_cookie_t cookie,
    +                                                   xcb_generic_error_t     **e);
     

    You use them as follows:

    -  XCBConnection     *c;
    -  XCBDRAWABLE        win;
    -  XCBGetGeometryRep *geom;
    +  xcb_connection_t         *c;
    +  xcb_drawable_t            win;
    +  xcb_get_geometry_reply_t *geom;
     
       /* You initialize c and win */
     
    -  geom = XCBGetGeometryReply (c, XCBGetGeometry (c, win), 0);
    +  geom = xcb_get_geometry_reply (c, xcb_get_geometry (c, win), NULL);
     
       /* Do something with the fields of geom */
    -  
    +
       free (geom);
     

    Remark that you have to free the structure, as - XCBGetGeometryReply allocates a + xcb_get_geometry_reply_t allocates a newly one.

    @@ -2491,79 +2435,79 @@ XCBGetGeometryRep *XCBGetGeometryReply (XCBConnection *c,

     typedef struct {
    -    BYTE response_type;
    -    CARD8 pad0;
    -    CARD16 sequence;
    -    CARD32 length;
    -    XCBWINDOW root;
    -    XCBWINDOW parent;    /* Id of the parent window */
    -    CARD16 children_len;
    -    CARD8 pad1[14];
    -} XCBQueryTreeRep;
    +    uint8_t      response_type;
    +    uint8_t      pad0;
    +    uint16_t     sequence;
    +    uint32_t     length;
    +    xcb_window_t root;
    +    xcb_window_t parent;       /* Id of the parent window */
    +    uint16_t     children_len;
    +    uint8_t      pad1[14];
    +} xcb_query_tree_reply_t;
     

    To fill this structure, we use these two functions:

    -XCBQueryTreeCookie XCBQueryTree      (XCBConnection       *c,
    -                                      XCBWINDOW            window);
    -XCBQueryTreeRep   *XCBQueryTreeReply (XCBConnection       *c,
    -                                      XCBQueryTreeCookie   cookie,
    -                                      XCBGenericError    **e);
    +xcb_query_tree_cookie_t xcb_query_tree       (xcb_connection_t        *c,
    +                                              xcb_window_t             window);
    +xcb_query_tree_reply_t *xcb_query_tree_reply (xcb_connection_t        *c,
    +                                              xcb_query_tree_cookie_t  cookie,
    +                                              xcb_generic_error_t    **e);
     

    The translated coordinates will be found in this structure:

     typedef struct {
    -    BYTE response_type;
    -    BOOL same_screen;
    -    CARD16 sequence;
    -    CARD32 length;
    -    XCBWINDOW child;
    -    CARD16 dst_x;        /* Translated x coordinate */
    -    CARD16 dst_y;        /* Translated y coordinate */
    -} XCBTranslateCoordinatesRep;
    +    uint8_t      response_type;
    +    uint8_t      same_screen;
    +    uint16_t     sequence;
    +    uint32_t     length;
    +    xcb_window_t child;
    +    uint16_t     dst_x;        /* Translated x coordinate */
    +    uint16_t     dst_y;        /* Translated y coordinate */
    +} xcb_translate_coordinates_reply_t;
     

    As usual, we need two functions to fill this structure:

    -XCBTranslateCoordinatesCookie XCBTranslateCoordinates      (XCBConnection                  *c,
    -                                                            XCBWINDOW                       src_window,
    -                                                            XCBWINDOW                       dst_window,
    -                                                            INT16                           src_x,
    -                                                            INT16                           src_y);
    -XCBTranslateCoordinatesRep   *XCBTranslateCoordinatesReply (XCBConnection                 *c,
    -                                                            XCBTranslateCoordinatesCookie   cookie,
    -                                                            XCBGenericError               **e);
    +xcb_translate_coordinates_cookie_t xcb_translate_coordinates       (xcb_connection_t                  *c,
    +                                                                    xcb_window_t                       src_window,
    +                                                                    xcb_window_t                       dst_window,
    +                                                                    int16_t                            src_x,
    +                                                                    int16_t                            src_y);
    +xcb_translate_coordinates_reply_t *xcb_translate_coordinates_reply (xcb_connection_t                  *c,
    +                                                                    xcb_translate_coordinates_cookie_t cookie,
    +                                                                    xcb_generic_error_t              **e);
     

    We use them as follows:

    -  XCBConnection              *c;
    -  XCBDRAWABLE                 win;
    -  XCBGetGeometryRep          *geom;
    -  XCBQueryTreeRep            *tree;
    -  XCBTranslateCoordinatesRep *trans;
    +  xcb_connection_t                  *c;
    +  xcb_drawable_t                     win;
    +  xcb_get_geometry_reply_t          *geom;
    +  xcb_query_tree_reply_t            *tree;
    +  xcb_translate_coordinates_reply_t *trans;
     
       /* You initialize c and win */
     
    -  geom  = XCBGetGeometryReply (c, XCBGetGeometry (c, win), 0);
    +  geom  = xcb_get_geometry_reply (c, xcb_get_geometry (c, win), NULL);
       if (!geom)
         return 0;
     
    -  tree  = XCBQueryTreeReply (c, XCBQueryTree (c, win), 0);
    +  tree  = xcb_query_tree_reply (c, xcb_query_tree (c, win), NULL);
       if (!tree)
         return 0;
     
    -  trans = XCBTranslateCoordinatesReply (c,
    -                                        XCBTranslateCoordinates (c,
    -                                                                 win,
    -                                                                 tree->parent,
    -                                                                 geom->x, geom->y),
    -                                        0);
    +  trans = xcb_translate_coordinates_reply (c,
    +                                           xcb_translate_coordinates (c,
    +                                                                      win,
    +                                                                      tree->parent,
    +                                                                      geom->x, geom->y),
    +                                           NULL);
       if (!trans)
         return 0;
     
    @@ -2590,53 +2534,53 @@ XCBTranslateCoordinatesRep   *XCBTranslateCoordinatesReply (XCBConnection
             

     typedef struct {
    -    BYTE response_type;
    -    CARD8 backing_store;
    -    CARD16 sequence;
    -    CARD32 length;
    -    XCBVISUALID visual;            /* Visual of the window */
    -    CARD16 _class;
    -    CARD8 bit_gravity;
    -    CARD8 win_gravity;
    -    CARD32 backing_planes;
    -    CARD32 backing_pixel;
    -    BOOL save_under;
    -    BOOL map_is_installed;
    -    CARD8 map_state;               /* Map state of the window */
    -    BOOL override_redirect;
    -    XCBCOLORMAP colormap;          /* Colormap of the window */
    -    CARD32 all_event_masks;
    -    CARD32 your_event_mask;
    -    CARD16 do_not_propagate_mask;
    -} XCBGetWindowAttributesRep;
    +    uint8_t        response_type;
    +    uint8_t        backing_store;
    +    uint16_t       sequence;
    +    uint32_t       length;
    +    xcb_visualid_t visual;                /* Visual of the window */
    +    uint16_t       _class;
    +    uint8_t        bit_gravity;
    +    uint8_t        win_gravity;
    +    uint32_t       backing_planes;
    +    uint32_t       backing_pixel;
    +    uint8_t        save_under;
    +    uint8_t        map_is_installed;
    +    uint8_t        map_state;             /* Map state of the window */
    +    uint8_t        override_redirect;
    +    xcb_colormap_t colormap;              /* Colormap of the window */
    +    uint32_t       all_event_masks;
    +    uint32_t       your_event_mask;
    +    uint16_t       do_not_propagate_mask;
    +} xcb_get_window_attributes_reply_t;
     

    XCB supplies these two functions to fill it:

    -XCBGetWindowAttributesCookie XCBGetWindowAttributes      (XCBConnection                 *c, 
    -                                                          XCBWINDOW                      window);
    -XCBGetWindowAttributesRep   *XCBGetWindowAttributesReply (XCBConnection                 *c, 
    -                                                          XCBGetWindowAttributesCookie   cookie,
    -                                                          XCBGenericError              **e);
    +xcb_get_window_attributes_cookie_t xcb_get_window_attributes       (xcb_connection_t                  *c,
    +                                                                    xcb_window_t                       window);
    +xcb_get_window_attributes_reply_t *xcb_get_window_attributes_reply (xcb_connection_t                  *c,
    +                                                                    xcb_get_window_attributes_cookie_t cookie,
    +                                                                    xcb_generic_error_t              **e);
     

    You use them as follows:

    -  XCBConnection             *c;
    -  XCBDRAWABLE                win;
    -  XCBGetWindowAttributesRep *attr;
    +  xcb_connection_t                  *c;
    +  xcb_drawable_t                     win;
    +  xcb_get_window_attributes_reply_t *attr;
     
       /* You initialize c and win */
     
    -  attr = XCBGetWindowAttributesReply (c, XCBGetWindowAttributes (c, win), 0);
    +  attr = xcb_get_window_attributes_reply (c, xcb_get_window_attributes (c, win), NULL);
     
       if (!attr)
         return 0;
     
       /* Do something with the fields of attr */
    -  
    +
       free (attr);
     

    @@ -2660,7 +2604,7 @@ XCBGetWindowAttributesRep *XCBGetWindowAttributesReply (XCBConnection application allocated the colors it needed, and when all the color entries (4, 16, 256 colors) were in use, the next color allocation would fail. -

    +

    Thus, the notion of "a color map" was introduced. A color map is a table whose size is the same as the number of @@ -2716,13 +2660,13 @@ XCBGetWindowAttributesRep *XCBGetWindowAttributesReply (XCBConnection

     typedef struct {
    -    CARD32 xid;
    -} XCBCOLORMAP;
    +    uint32_t xid;
    +} xcb_colormap_t;
     

    In order to access the screen's default color map, you just - have to retrieve the default_colormap - field of the XCBSCREEN structure + have to retrieve the default_colormap + field of the xcb_screen_t structure (see Section Checking basic information about a connection):

    @@ -2734,17 +2678,17 @@ typedef struct { int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBCOLORMAP colormap; - + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_colormap_t colormap; + /* Open the connection to the X server and get the first screen */ - c = XCBConnect (NULL, NULL); - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + c = xcb_connect (NULL, NULL); + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; colormap = screen->default_colormap; - return 1; + return 0; }

    @@ -2758,17 +2702,17 @@ main (int argc, char *argv[]) map, with this function:

    -XCBCOLORMAP XCBCOLORMAPNew (XCBConnection *c);
    +xcb_colormap_t xcb_colormap_new (xcb_connection_t *c);
     

    Then, we create the color map with

    -XCBVoidCookie XCBCreateColormap (XCBConnection *c,       /* Pointer to the XCBConnection structure */
    -                                 BYTE           alloc,   /* Colormap entries to be allocated (AllocNone or AllocAll) */
    -                                 XCBCOLORMAP    mid,     /* Id of the color map */
    -                                 XCBWINDOW      window,  /* Window on whose screen the colormap will be created */
    -                                 XCBVISUALID    visual); /* Id of the visual supported by the screen */
    +xcb_void_cookie_t xcb_create_colormap (xcb_connection_t *c,       /* Pointer to the xcb_connection_t structure */
    +                                       uint8_t           alloc,   /* Colormap entries to be allocated (AllocNone or AllocAll) */
    +                                       xcb_colormap_t    mid,     /* Id of the color map */
    +                                       xcb_window_t      window,  /* Window on whose screen the colormap will be created */
    +                                       xcb_visualid_t    visual); /* Id of the visual supported by the screen */
     

    Here is an example of creation of a new color map: @@ -2779,21 +2723,21 @@ XCBVoidCookie XCBCreateColormap (XCBConnection *c, /* Pointer to the XCBCo int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBWINDOW win; - XCBCOLORMAP cmap - + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_window_t win; + xcb_colormap_t cmap + /* Open the connection to the X server and get the first screen */ - c = XCBConnect (NULL, NULL); - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + c = xcb_connect (NULL, NULL); + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; /* We create the window win here*/ - cmap = XCBCOLORMAPNew (c); - XCBCreateColormap (c, XCBColormapAllocNone, cmap, win, screen->root_visual); + cmap = xcb_colormap_new (c); + xcb_create_colormap (c, XCB_COLORMAP_ALLOC_NONE, cmap, win, screen->root_visual); - return 1; + return 0; }

    @@ -2805,8 +2749,8 @@ main (int argc, char *argv[]) To free a color map, it suffices to use this function:

    -XCBVoidCookie XCBFreeColormap (XCBConnection *c,   /* The connection */
    -                               XCBCOLORMAP cmap);  /* The color map */
    +xcb_void_cookie_t xcb_free_colormap (xcb_connection_t *c,   /* The connection */
    +                                     xcb_colormap_t cmap);  /* The color map */
     
    @@ -2819,8 +2763,8 @@ XCBVoidCookie XCBFreeColormap (XCBConnection *c, /* The connection */
      -
    • XCBCOLORMAPNew () -
    • XCBCreateColormap () +
    • xcb_colormap_new () +
    • xcb_create_colormap ()
    @@ -2830,7 +2774,7 @@ XCBVoidCookie XCBFreeColormap (XCBConnection *c, /* The connection */
      -
    • XCBFreeColormap () +
    • xcb_free_colormap ()
    @@ -2843,32 +2787,32 @@ XCBVoidCookie XCBFreeColormap (XCBConnection *c, /* The connection */

     typedef struct {
    -    BYTE response_type;
    -    CARD8 pad0;
    -    CARD16 sequence;
    -    CARD32 length;
    -    CARD16 red;          /* The red component   */
    -    CARD16 green;        /* The green component */
    -    CARD16 blue;         /* The blue component  */
    -    CARD8 pad1[2];
    -    CARD32 pixel;        /* The entry in the color map, supplied by the X server */
    -} XCBAllocColorRep;
    +    uint8_t  response_type;
    +    uint8_t  pad0;
    +    uint16_t sequence;
    +    uint32_t length;
    +    uint16_t red;          /* The red component   */
    +    uint16_t green;        /* The green component */
    +    uint16_t blue;         /* The blue component  */
    +    uint8_t  pad1[2];
    +    uint32_t pixel;        /* The entry in the color map, supplied by the X server */
    +} xcb_alloc_color_reply_t;
     

    XCB supplies these two functions to fill it:

    -XCBAllocColorCookie XCBAllocColor      (XCBConnection *c,
    -                                        XCBCOLORMAP    cmap,
    -                                        CARD16         red,
    -                                        CARD16         green,
    -                                        CARD16         blue);
    -XCBAllocColorRep   *XCBAllocColorReply (XCBConnection        *c,
    -                                        XCBAllocColorCookie   cookie,
    -                                        XCBGenericError     **e);
    +xcb_alloc_color_cookie_t xcb_alloc_color       (xcb_connection_t        *c,
    +                                                xcb_colormap_t           cmap,
    +                                                uint16_t                 red,
    +                                                uint16_t                 green,
    +                                                uint16_t                 blue);
    +xcb_alloc_color_reply_t *xcb_alloc_color_reply (xcb_connection_t        *c,
    +                                                xcb_alloc_color_cookie_t cookie,
    +                                                xcb_generic_error_t    **e);
     

    - The fuction XCBAllocColor() takes the + The fuction xcb_alloc_color() takes the 3 RGB components as parameters (red, green and blue). Here is an example of using these functions:

    @@ -2880,23 +2824,23 @@ XCBAllocColorRep *XCBAllocColorReply (XCBConnection *c, int main (int argc, char *argv[]) { - XCBConnection *c; - XCBSCREEN *screen; - XCBWINDOW win; - XCBCOLORMAP cmap; - XCBAllocColorRep *rep; - + xcb_connection_t *c; + xcb_screen_t *screen; + xcb_window_t win; + xcb_colormap_t cmap; + xcb_alloc_color_reply_t *rep; + /* Open the connection to the X server and get the first screen */ - c = XCBConnect (NULL, NULL); - screen = XCBSetupRootsIter (XCBGetSetup (c)).data; + c = xcb_connect (NULL, NULL); + screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; /* We create the window win here*/ - cmap = XCBCOLORMAPNew (c); - XCBCreateColormap (c, XCBColormapAllocNone, cmap, win, screen->root_visual); + cmap = xcb_colormap_new (c); + xcb_create_colormap (c, XCB_COLORMAP_ALLOC_NONE, cmap, win, screen->root_visual); + + rep = xcb_alloc_color_reply (c, xcb_alloc_color (c, cmap, 65535, 0, 0), NULL); - rep = XCBAllocColorReply (c, XCBAllocColor (c, cmap, 65535, 0, 0), 0); - if (!rep) return 0; @@ -2904,11 +2848,11 @@ main (int argc, char *argv[]) free (rep); - return 1; + return 0; }

    - As XCBAllocColorReply() allocates + As xcb_alloc_color_reply() allocates memory, you have to free rep.

    @@ -2940,7 +2884,7 @@ main (int argc, char *argv[]) looks like a C source file. It contains variables defining the width and the height of the bitmap, an array containing the bit values of the bitmap (the size of the array is - (width+7)/8*height and the bit and byte order are LSB), and + (width+7)/8*height and the bit and byte order are LSB), and an optional hot-spot location (that will be explained later, when discussing mouse cursors).

    @@ -2959,8 +2903,8 @@ main (int argc, char *argv[])

     typedef struct {
    -    CARD32 xid;
    -} XCBPIXMAP;
    +    uint32_t xid;
    +} xcb_pixmap_t;
     

    In order to make the difference between a window and a pixmap, @@ -2968,14 +2912,14 @@ typedef struct {

     typedef union {
    -    XCBWINDOW window;
    -    XCBPIXMAP pixmap;
    -} XCBDRAWABLE;
    +    xcb_window_t window;
    +    xcb_pixmap_t pixmap;
    +} xcb_drawable_t;
     

    in order to avoid confusion between a window and a pixmap. The operations that will work the same on a window or a pixmap - will require a XCBDRAWABLE + will require a xcb_drawable_t

    @@ -2999,21 +2943,21 @@ typedef union {

    To create a new pixmap, we first ask the X server to give an - Id to our pixmap, with this function: + Id to our pixmap, with this function:

    -XCBPIXMAP XCBPIXMAPNew (XCBConnection *c);
    +xcb_pixmap_t xcb_pixmap_new (xcb_connection_t *c);
     

    Then, XCB supplies the following function to create new pixmaps:

    -XCBVoidCookie XCBCreatePixmap (XCBConnection *c,         /* Pointer to the XCBConnection structure */
    -                               CARD8          depth,     /* Depth of the screen */
    -                               XCBPIXMAP      pid,       /* Id of the pixmap */
    -                               XCBDRAWABLE    drawable,
    -                               CARD16         width,     /* Width of the window (in pixels) */
    -                               CARD16         height);   /* Height of the window (in pixels) */
    +xcb_void_cookie_t xcb_create_pixmap (xcb_connection_t *c,         /* Pointer to the xcb_connection_t structure */
    +                                     uint8_t           depth,     /* Depth of the screen */
    +                                     xcb_pixmap_t      pid,       /* Id of the pixmap */
    +                                     xcb_drawable_t    drawable,
    +                                     uint16_t          width,     /* Width of the window (in pixels) */
    +                                     uint16_t          height);   /* Height of the window (in pixels) */
     

    TODO: Explain the drawable parameter, and give an @@ -3025,16 +2969,16 @@ XCBVoidCookie XCBCreatePixmap (XCBConnection *c, /* Pointer to the XCBCo window, using the following function:

    -XCBVoidCookie XCBCopyArea (XCBConnection *c,             /* Pointer to the XCBConnection structure */
    -                           XCBDRAWABLE    src_drawable,  /* The Drawable we want to paste */
    -                           XCBDRAWABLE    dst_drawable,  /* The Drawable on which we copy the previous Drawable */
    -                           XCBGCONTEXT    gc,            /* A Graphic Context */
    -                           INT16          src_x,         /* Top left x coordinate of the region we want to copy */
    -                           INT16          src_y,         /* Top left y coordinate of the region we want to copy */
    -                           INT16          dst_x,         /* Top left x coordinate of the region where we want to copy */
    -                           INT16          dst_y,         /* Top left y coordinate of the region where we want to copy */
    -                           CARD16         width,         /* Width of the region we want to copy */
    -                           CARD16         height);       /* Height of the region we want to copy */
    +xcb_void_cookie_t xcb_copy_area (xcb_connection_t *c,             /* Pointer to the xcb_connection_t structure */
    +                                 xcb_drawable_t    src_drawable,  /* The Drawable we want to paste */
    +                                 xcb_drawable_t    dst_drawable,  /* The Drawable on which we copy the previous Drawable */
    +                                 xcb_gcontext_t    gc,            /* A Graphic Context */
    +                                 int16_t          src_x,          /* Top left x coordinate of the region we want to copy */
    +                                 int16_t          src_y,          /* Top left y coordinate of the region we want to copy */
    +                                 int16_t          dst_x,          /* Top left x coordinate of the region where we want to copy */
    +                                 int16_t          dst_y,          /* Top left y coordinate of the region where we want to copy */
    +                                 uint16_t         width,          /* Width of the region we want to copy */
    +                                 uint16_t         height);        /* Height of the region we want to copy */
     

    As you can see, we could copy the whole pixmap, as well as @@ -3050,7 +2994,7 @@ XCBVoidCookie XCBCopyArea (XCBConnection *c, /* Pointer to the XCBCo depth. If they have a different depth, the operation would fail. The exception to this is if we copy a specific bit plane of the source pixmap using the - XCBCopyPlane function. In such an + xcb_copy_plane_t function. In such an event, we can copy a specific plane to the target window (in actuality, setting a specific bit in the color of each pixel copied). This can be used to generate strange graphic effects @@ -3063,8 +3007,8 @@ XCBVoidCookie XCBCopyArea (XCBConnection *c, /* Pointer to the XCBCo using this function:

    -XCBVoidCookie XCBFreePixmap (XCBConnection *c,        /* Pointer to the XCBConnection structure */
    -                             XCBPIXMAP      pixmap);  /* A given pixmap */
    +xcb_void_cookie_t xcb_free_pixmap (xcb_connection_t *c,        /* Pointer to the xcb_connection_t structure */
    +                                   xcb_pixmap_t      pixmap);  /* A given pixmap */
     

    Of course, after having freed it, we must not try accessing @@ -3074,6 +3018,115 @@ XCBVoidCookie XCBFreePixmap (XCBConnection *c, /* Pointer to the XCBConne TODO: Give an example, or a link to xpoints.c

    +
  • Messing with the mouse cursor +

    + It it possible to modify the shape of the mouse pointer (also + called the X pointer) when in certain states, as we otfen see in + programs. For example, a busy application would often display + the sand clock over its main window, to give the user a visual + hint that he should wait. Let's see how we can change the mouse + cursor of our windows. +

    +
      +
    1. Creating and destroying a mouse cursor +

      + There are two methods for creating cursors. One of them is by + using a set of predefined cursors, that are supplied by the X + server, the other is by using a user-supplied bitmap. +

      +

      + In the first method, we use a special font named "cursor", and + the function xcb_create_glyph_cursor: +

      +
      +xcb_void_cookie_t xcb_create_glyph_cursor_checked (xcb_connection_t *c,
      +                                                   xcb_cursor_t      cid,
      +                                                   xcb_font_t        source_font, /* font for the source glyph */
      +                                                   xcb_font_t        mask_font,   /* font for the mask glyph or XCB_NONE */
      +                                                   uint16_t          source_char, /* character glyph for the source */
      +                                                   uint16_t          mask_char,   /* character glyph for the mask */
      +                                                   uint16_t          fore_red,    /* red value for the foreground of the source */
      +                                                   uint16_t          fore_green,  /* green value for the foreground of the source */
      +                                                   uint16_t          fore_blue,   /* blue value for the foreground of the source */
      +                                                   uint16_t          back_red,    /* red value for the background of the source */
      +                                                   uint16_t          back_green,  /* green value for the background of the source */
      +                                                   uint16_t          back_blue)   /* blue value for the background of the source */
      +
      +

      + TODO: Describe source_char + and mask_char, for example by giving + an example on how to get the values. There is a list there: + X Font Cursors +

      +

      + So we first open that font (see Loading a Font) + and create the new cursor. As for every X ressource, we have to + ask for an X id with xcb_cursor_new + first: +

      +
      +xcb_font_t           font;
      +xcb_cursor_t         cursor;
      +
      +/* The connection is set */
      +
      +font = xcb_font_new (conn);
      +xcb_open_font (conn, font, strlen ("cursor"), "cursor");
      +
      +cursor = xcb_cursor_new (conn);
      +xcb_create_glyph_cursor (conn, cursor, font, font,
      +                         58, 58 + 1,
      +                         0, 0, 0,
      +                         0, 0, 0);
      +
      +

      + We have created the cursor "right hand" by specifying 58 to + the source_font argument and 58 + 1 + to the mask_font. +

      +

      + The cursor is destroyed by using the function +

      +
      +xcb_void_cookie_t xcb_free_cursor (xcb_connection_t *c,
      +                                   xcb_cursor_t      cursor);
      +
      +

      + In the second method, we create a new cursor by using a pair + of pixmaps, with depth of one (that is, two colors + pixmaps). One pixmap defines the shape of the cursor, while + the other works as a mask, specifying which pixels of the + cursor will be actually drawn. The rest of the pixels will be + transparent. +

      +

      + TODO: give an example. +

      +
    2. Setting a window's mouse cursor +

      + Once the cursor is created, we can modify the cursor of our + window by using xcb_change_window_attributes + and using the XCB_CWCURSOR attribute: +

      +
      +uint32_t mask;
      +uint32_t value_list;
      +
      +/* The connection and window are set */
      +/* The cursor is already created */
      +
      +mask = XCB_CWCURSOR;
      +value_list = cursor.xid;
      +xcb_change_window_attributes (conn, window, mask, &value_list);
      +
      +

      + Of course, the cursor and the font must be freed. +

      +
    3. Complete example +

      + TODO: to do... +

      +
  • Translation of basic Xlib functions and macros

    The problem when you want to port an Xlib program to XCB is that @@ -3084,13 +3137,15 @@ XCBVoidCookie XCBFreePixmap (XCBConnection *c, /* Pointer to the XCBConne

    1. Members of the Display structure +

      In this section, we look at how to translate the macros that return some members of the Display structure. They are obtained by using a function that requires a - XCBConnection * or a member of the - XCBSetup structure - (via the function XCBGetSetup), or + xcb_connection_t * or a member of the + xcb_setup_t structure + (via the function xcb_get_setup_t), or a function that requires that structure. +

      1. ConnectionNumber

        @@ -3098,28 +3153,28 @@ XCBVoidCookie XCBFreePixmap (XCBConnection *c, /* Pointer to the XCBConne to the server. You just have to use that function:

        -int XCBGetFileDescriptor(XCBConnection *c);
        +int xcb_get_file_descriptor (xcb_connection_t *c);
         
      2. DefaultScreen

        That number is not stored by XCB. It is returned in the - second parameter of the function XCBConnect. + second parameter of the function xcb_connect. Hence, you have to store it yourself if you want to use - it. Then, to get the XCBSCREEN + it. Then, to get the xcb_screen_t structure, you have to iterate on the screens. The equivalent function of the Xlib's ScreenOfDisplay function can be found below. This is also provided in the - XCBAux library as XCBAuxGetScreen(). OK, here is the + xcb_aux_t library as xcb_aux_get_screen(). OK, here is the small piece of code to get that number:

        -XCBConnection *c;
        -int            screen_default_nbr;
        +xcb_connection_t *c;
        +int               screen_default_nbr;
         
        -/* you pass the name of the display you want to XCBConnect */
        +/* you pass the name of the display you want to xcb_connect_t */
         
        -c = XCBConnect (display_name, &screen_default_nbr);
        +c = xcb_connect (display_name, &screen_default_nbr);
         
         /* screen_default_nbr contains now the number of the default screen */
         
        @@ -3137,56 +3192,56 @@ c = XCBConnect (display_name, &screen_default_nbr);
      3. ScreenCount

        You get the count of screens with the functions - XCBGetSetup + xcb_get_setup_t and - XCBSetupRootsIter + xcb_setup_roots_iterator_t (if you need to iterate):

        -XCBConnection *c;
        -int            screen_count;
        +xcb_connection_t *c;
        +int               screen_count;
         
         /* you init the connection */
         
        -screen_count = XCBSetupRootsIter (XCBGetSetup (c)).rem;
        +screen_count = xcb_setup_roots_iterator (xcb_get_setup (c)).rem;
         
         /* screen_count contains now the count of screens */
         

        If you don't want to iterate over the screens, a better way to get that number is to use - XCBSetupRootsLength: + xcb_setup_roots_length_t:

        -XCBConnection *c;
        -int            screen_count;
        +xcb_connection_t *c;
        +int               screen_count;
         
         /* you init the connection */
         
        -screen_count = XCBSetupRootsLength (XCBGetSetup (c));
        +screen_count = xcb_setup_roots_length (xcb_get_setup (c));
         
         /* screen_count contains now the count of screens */
         
      4. ServerVendor

        You get the name of the vendor of the server hardware with - the functions XCBGetSetup + the functions xcb_get_setup_t and XCBSetupVendor. Beware + class="code">xcb_setup_vendor_t. Beware that, unlike Xlib, the string returned by XCB is not necessarily null-terminaled:

        -XCBConnection *c;
        -char          *vendor = NULL;
        -int            length;
        +xcb_connection_t *c;
        +char             *vendor = NULL;
        +int               length;
         
         /* you init the connection */
        -length = XCBSetupVendorLength (XCBGetSetup (c));
        +length = xcb_setup_vendor_length (xcb_get_setup (c));
         vendor = (char *)malloc (length + 1);
         if (vendor)
        -memcpy (vendor, XCBSetupVendor (XCBGetSetup (c)), length);
        +memcpy (vendor, xcb_setup_vendor (xcb_get_setup (c)), length);
         vendor[length] = '\0';
         
         /* vendor contains now the name of the vendor. Must be freed when not used anymore */
        @@ -3194,48 +3249,48 @@ vendor[length] = '\0';
                   
      5. ProtocolVersion

        You get the major version of the protocol in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD16         protocol_major_version;
        +xcb_connection_t *c;
        +uint16_t          protocol_major_version;
         
         /* you init the connection */
         
        -protocol_major_version = XCBGetSetup (c)->protocol_major_version;
        +protocol_major_version = xcb_get_setup (c)->protocol_major_version;
         
         /* protocol_major_version contains now the major version of the protocol */
         
      6. ProtocolRevision

        You get the minor version of the protocol in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD16         protocol_minor_version;
        +xcb_connection_t *c;
        +uint16_t          protocol_minor_version;
         
         /* you init the connection */
         
        -protocol_minor_version = XCBGetSetup (c)->protocol_minor_version;
        +protocol_minor_version = xcb_get_setup (c)->protocol_minor_version;
         
         /* protocol_minor_version contains now the minor version of the protocol */
         
      7. VendorRelease

        You get the number of the release of the server hardware in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD32         release_number;
        +xcb_connection_t *c;
        +uint32_t          release_number;
         
         /* you init the connection */
         
        -release_number = XCBGetSetup (c)->release_number;
        +release_number = xcb_get_setup (c)->release_number;
         
         /* release_number contains now the number of the release of the server hardware */
         
        @@ -3247,64 +3302,64 @@ release_number = XCBGetSetup (c)->release_number;
      8. BitmapUnit

        You get the bitmap scanline unit in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD8          bitmap_format_scanline_unit;
        +xcb_connection_t *c;
        +uint8_t           bitmap_format_scanline_unit;
         
         /* you init the connection */
         
        -bitmap_format_scanline_unit = XCBGetSetup (c)->bitmap_format_scanline_unit;
        +bitmap_format_scanline_unit = xcb_get_setup (c)->bitmap_format_scanline_unit;
         
         /* bitmap_format_scanline_unit contains now the bitmap scanline unit */
         
      9. BitmapBitOrder

        You get the bitmap bit order in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD8          bitmap_format_bit_order;
        +xcb_connection_t *c;
        +uint8_t           bitmap_format_bit_order;
         
         /* you init the connection */
         
        -bitmap_format_bit_order = XCBGetSetup (c)->bitmap_format_bit_order;
        +bitmap_format_bit_order = xcb_get_setup (c)->bitmap_format_bit_order;
         
         /* bitmap_format_bit_order contains now the bitmap bit order */
         
      10. BitmapPad

        You get the bitmap scanline pad in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD8          bitmap_format_scanline_pad;
        +xcb_connection_t *c;
        +uint8_t           bitmap_format_scanline_pad;
         
         /* you init the connection */
         
        -bitmap_format_scanline_pad = XCBGetSetup (c)->bitmap_format_scanline_pad;
        +bitmap_format_scanline_pad = xcb_get_setup (c)->bitmap_format_scanline_pad;
         
         /* bitmap_format_scanline_pad contains now the bitmap scanline pad */
         
      11. ImageByteOrder

        You get the image byte order in the - XCBSetup - structure, with the function XCBGetSetup: + xcb_setup_t + structure, with the function xcb_get_setup_t:

        -XCBConnection *c;
        -CARD8          image_byte_order;
        +xcb_connection_t *c;
        +uint8_t           image_byte_order;
         
         /* you init the connection */
         
        -image_byte_order = XCBGetSetup (c)->image_byte_order;
        +image_byte_order = xcb_get_setup (c)->image_byte_order;
         
         /* image_byte_order contains now the image byte order */
         
        @@ -3314,13 +3369,13 @@ image_byte_order = XCBGetSetup (c)->image_byte_order; in Xlib, ScreenOfDisplay returns a Screen structure that contains several characteristics of your screen. XCB has a similar - structure (XCBSCREEN), + structure (xcb_screen_t), but the way to obtain it is a bit different. With Xlib, you just provide the number of the screen and you grab it from an array. With XCB, you iterate over all the screens to obtain the one you want. The complexity of this operation is O(n). So the best is to store this structure if you use - it often. See ScreenOfDisplay just below. + it often. See screen_of_display just below.

        Xlib provides generally two functions to obtain the characteristics @@ -3328,7 +3383,7 @@ image_byte_order = XCBGetSetup (c)->image_byte_order; the screen, which calls ScreenOfDisplay, and the other that uses the Screen structure. This might be a bit confusing. As mentioned above, with XCB, it - is better to store the XCBSCREEN + is better to store the xcb_screen_t structure. Then, you have to read the members of this structure. That's why the Xlib functions are put by pairs (or more) as, with XCB, you will use the same code. @@ -3341,13 +3396,13 @@ image_byte_order = XCBGetSetup (c)->image_byte_order; once you get the one you want, you return it:

        
        -XCBSCREEN *ScreenOfDisplay (XCBConnection *c,
        -                            int            screen)
        +xcb_screen_t *screen_of_display (xcb_connection_t *c,
        +                                 int               screen)
         {
        -  XCBSCREENIter iter;
        +  xcb_screen_iterator_t iter;
         
        -  iter = XCBSetupRootsIter (XCBGetSetup (c));
        -  for (; iter.rem; --screen, XCBSCREENNext (&iter))
        +  iter = xcb_setup_roots_iterator (xcb_get_setup (c));
        +  for (; iter.rem; --screen, xcb_screen_next (&iter))
             if (screen == 0)
               return iter.data;
         
        @@ -3361,24 +3416,24 @@ XCBSCREEN *ScreenOfDisplay (XCBConnection *c,
                   

        All the functions below will use the result of that function, as they just grab a specific member of the - XCBSCREEN structure. + xcb_screen_t structure.

      12. DefaultScreenOfDisplay

        It is the default screen that you obtain when you connect to - the X server. It suffices to call the ScreenOfDisplay + the X server. It suffices to call the screen_of_display function above with the connection and the number of the default screen.

        -XCBConnection *c;
        -int            screen_default_nbr;
        -XCBSCREEN     *default_screen;  /* the returned default screen */
        +xcb_connection_t *c;
        +int               screen_default_nbr;
        +xcb_screen_t     *default_screen;  /* the returned default screen */
         
        -/* you pass the name of the display you want to XCBConnect */
        +/* you pass the name of the display you want to xcb_connect_t */
         
        -c = XCBConnect (display_name, &screen_default_nbr);
        -default_screen = ScreenOfDisplay (c, screen_default_nbr);
        +c = xcb_connect (display_name, &screen_default_nbr);
        +default_screen = screen_of_display (c, screen_default_nbr);
         
         /* default_screen contains now the default root window, or a NULL window if no screen is found */
         
        @@ -3386,14 +3441,14 @@ default_screen = ScreenOfDisplay (c, screen_default_nbr);

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -XCBWINDOW      root_window = { 0 };  /* the returned window */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +xcb_window_t      root_window = { 0 };  /* the returned window */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           root_window = screen->root;
         
        @@ -3407,15 +3462,15 @@ if (screen)
                   root window as above:
                   

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_default_nbr;
        -XCBWINDOW      root_window = { 0 };  /* the returned root window */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_default_nbr;
        +xcb_window_t      root_window = { 0 };  /* the returned root window */
         
        -/* you pass the name of the display you want to XCBConnect */
        +/* you pass the name of the display you want to xcb_connect_t */
         
        -c = XCBConnect (display_name, &screen_default_nbr);
        -screen = ScreenOfDisplay (c, screen_default_nbr);
        +c = xcb_connect (display_name, &screen_default_nbr);
        +screen = screen_of_display (c, screen_default_nbr);
         if (screen)
           root_window = screen->root;
         
        @@ -3424,67 +3479,63 @@ if (screen)
                   
      13. DefaultVisual / DefaultVisualOfScreen

        While a Visual is, in Xlib, a structure, in XCB, there are - two types: XCBVISUALID, which is - the Id of the visual, and XCBVISUALTYPE, + two types: xcb_visualid_t, which is + the Id of the visual, and xcb_visualtype_t, which corresponds to the Xlib Visual. To get the Id of the visual of a screen, just get the root_visual - member of a XCBSCREEN: + member of a xcb_screen_t:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -XCBVISUALID    root_visual = { 0 };    /* the returned visual Id */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +xcb_visualid_t    root_visual = { 0 };    /* the returned visual Id */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           root_visual = screen->root_visual;
         
         /* root_visual contains now the value of the Id of the visual, or a NULL visual if no screen is found */
         

        - To get the XCBVISUALTYPE + To get the xcb_visualtype_t structure, it's a bit less easy. You have to get the - XCBSCREEN structure that you want, + xcb_screen_t structure that you want, get its root_visual member, - then iterate over the XCBDEPTHs - and the XCBVISUALTYPEs, and compare - the XCBVISUALID of these XCBVISUALTYPEs: + then iterate over the xcb_depth_ts + and the xcb_visualtype_ts, and compare + the xcb_visualid_t of these xcb_visualtype_ts: with root_visual:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -XCBVISUALID    root_visual = { 0 };
        -XCBVISUALTYPE  *visual_type = NULL;    /* the returned visual type */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +xcb_visualid_t    root_visual = { 0 };
        +xcb_visualtype_t  *visual_type = NULL;    /* the returned visual type */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        -if (screen)
        -  {
        -    XCBDEPTHIter depth_iter;
        -
        -    depth_iter = XCBSCREENAllowedDepthsIter (screen);
        -    for (; depth_iter.rem; XCBDEPTHNext (&depth_iter))
        -      {
        -        XCBVISUALTYPEIter visual_iter;
        -
        -        visual_iter = XCBDEPTHVisualsIter (depth_iter.data);
        -        for (; visual_iter.rem; XCBVISUALTYPENext (&visual_iter))
        -          {
        -            if (screen->root_visual.id == visual_iter.data->visual_id.id)
        -              {
        -                visual_type = visual_iter.data;
        -                break;
        -              }
        -          }
        +screen = screen_of_display (c, screen_nbr);
        +if (screen) {
        +  xcb_depth_iterator_t depth_iter;
        +
        +  depth_iter = xcb_screen_allowed_depths_iterator (screen);
        +  for (; depth_iter.rem; xcb_depth_next (&depth_iter)) {
        +    xcb_visualtype_iterator_t visual_iter;
        +
        +    visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
        +    for (; visual_iter.rem; xcb_visualtype_next (&visual_iter)) {
        +      if (screen->root_visual.id == visual_iter.data->visual_id.id) {
        +        visual_type = visual_iter.data;
        +        break;
               }
        +    }
           }
        +}
         
         /* visual_type contains now the visual structure, or a NULL visual structure if no screen is found */
         
        @@ -3492,48 +3543,47 @@ if (screen)

        This default Graphic Context is just a newly created Graphic Context, associated to the root window of a - XCBSCREEN, + xcb_screen_t, using the black white pixels of that screen:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -XCBGCONTEXT    gc = { 0 };    /* the returned default graphic context */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +xcb_gcontext_t    gc = { 0 };    /* the returned default graphic context */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        -if (screen)
        -  {
        -    XCBDRAWABLE draw;
        -    CARD32      mask;
        -    CARD32      values[2];
        -
        -    gc = XCBGCONTEXTNew (c);
        -    draw.window = screen->root;
        -    mask = XCBGCForeground | XCBGCBackground;
        -    values[0] = screen->black_pixel;
        -    values[1] = screen->white_pixel;
        -    XCBCreateGC (c, gc, draw, mask, values);
        -  }
        +screen = screen_of_display (c, screen_nbr);
        +if (screen) {
        +  xcb_drawable_t draw;
        +  uint32_t       mask;
        +  uint32_t       values[2];
        +
        +  gc = xcb_gcontext_new (c);
        +  draw.window = screen->root;
        +  mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
        +  values[0] = screen->black_pixel;
        +  values[1] = screen->white_pixel;
        +  xcb_create_gc (c, gc, draw, mask, values);
        +}
         
         /* gc contains now the default graphic context */
         
      14. BlackPixel / BlackPixelOfScreen

        It is the Id of the black pixel, which is in the structure - of an XCBSCREEN. + of an xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         black_pixel = 0;    /* the returned black pixel */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          black_pixel = 0;    /* the returned black pixel */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           black_pixel = screen->black_pixel;
         
        @@ -3542,17 +3592,17 @@ if (screen)
                   
      15. WhitePixel / WhitePixelOfScreen

        It is the Id of the white pixel, which is in the structure - of an XCBSCREEN. + of an xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         white_pixel = 0;    /* the returned white pixel */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          white_pixel = 0;    /* the returned white pixel */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           white_pixel = screen->white_pixel;
         
        @@ -3562,17 +3612,17 @@ if (screen)
                   

        It is the width in pixels of the screen that you want, and which is in the structure of the corresponding - XCBSCREEN. + xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         width_in_pixels = 0;    /* the returned width in pixels */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          width_in_pixels = 0;    /* the returned width in pixels */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           width_in_pixels = screen->width_in_pixels;
         
        @@ -3582,17 +3632,17 @@ if (screen)
                   

        It is the height in pixels of the screen that you want, and which is in the structure of the corresponding - XCBSCREEN. + xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         height_in_pixels = 0;    /* the returned height in pixels */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          height_in_pixels = 0;    /* the returned height in pixels */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           height_in_pixels = screen->height_in_pixels;
         
        @@ -3602,17 +3652,17 @@ if (screen)
                   

        It is the width in millimeters of the screen that you want, and which is in the structure of the corresponding - XCBSCREEN. + xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         width_in_millimeters = 0;    /* the returned width in millimeters */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          width_in_millimeters = 0;    /* the returned width in millimeters */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           width_in_millimeters = screen->width_in_millimeters;
         
        @@ -3622,17 +3672,17 @@ if (screen)
                   

        It is the height in millimeters of the screen that you want, and which is in the structure of the corresponding - XCBSCREEN. + xcb_screen_t.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         height_in_millimeters = 0;    /* the returned height in millimeters */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          height_in_millimeters = 0;    /* the returned height in millimeters */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           height_in_millimeters = screen->height_in_millimeters;
         
        @@ -3641,17 +3691,17 @@ if (screen)
                   
      16. DisplayPlanes / DefaultDepth / DefaultDepthOfScreen / PlanesOfScreen

        It is the depth (in bits) of the root window of the - screen. You get it from the XCBSCREEN structure. + screen. You get it from the xcb_screen_t structure.

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD8          root_depth = 0;  /* the returned depth of the root window */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint8_t           root_depth = 0;  /* the returned depth of the root window */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           root_depth = screen->root_depth;
         
        @@ -3661,17 +3711,17 @@ if (screen)
                   

        This is the default colormap of the screen (and not the (default) colormap of the default screen !). As usual, you - get it from the XCBSCREEN structure: + get it from the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -XCBCOLORMAP    default_colormap = { 0 };  /* the returned default colormap */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +xcb_colormap_t    default_colormap = { 0 };  /* the returned default colormap */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           default_colormap = screen->default_colormap;
         
        @@ -3679,17 +3729,17 @@ if (screen)
         
      17. MinCmapsOfScreen

        - You get the minimum installed colormaps in the XCBSCREEN structure: + You get the minimum installed colormaps in the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD16         min_installed_maps = 0;  /* the returned minimum installed colormaps */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint16_t          min_installed_maps = 0;  /* the returned minimum installed colormaps */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           min_installed_maps = screen->min_installed_maps;
         
        @@ -3697,17 +3747,17 @@ if (screen)
         
      18. MaxCmapsOfScreen

        - You get the maximum installed colormaps in the XCBSCREEN structure: + You get the maximum installed colormaps in the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD16         max_installed_maps = 0;  /* the returned maximum installed colormaps */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint16_t          max_installed_maps = 0;  /* the returned maximum installed colormaps */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           max_installed_maps = screen->max_installed_maps;
         
        @@ -3716,17 +3766,17 @@ if (screen)
                   
      19. DoesSaveUnders

        You know if save_unders is set, - by looking in the XCBSCREEN structure: + by looking in the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -BOOL           save_unders = 0;  /* the returned value of save_unders */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint8_t           save_unders = 0;  /* the returned value of save_unders */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           save_unders = screen->save_unders;
         
        @@ -3735,17 +3785,17 @@ if (screen)
                   
      20. DoesBackingStore

        You know the value of backing_stores, - by looking in the XCBSCREEN structure: + by looking in the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -BYTE           backing_stores = 0;  /* the returned value of backing_stores */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint8_t           backing_stores = 0;  /* the returned value of backing_stores */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           backing_stores = screen->backing_stores;
         
        @@ -3754,17 +3804,17 @@ if (screen)
                   
      21. EventMaskOfScreen

        To get the current input masks, - you look in the XCBSCREEN structure: + you look in the xcb_screen_t structure:

        -XCBConnection *c;
        -XCBSCREEN     *screen;
        -int            screen_nbr;
        -CARD32         current_input_masks = 0;  /* the returned value of current input masks */
        +xcb_connection_t *c;
        +xcb_screen_t     *screen;
        +int               screen_nbr;
        +uint32_t          current_input_masks = 0;  /* the returned value of current input masks */
         
         /* you init the connection and screen_nbr */
         
        -screen = ScreenOfDisplay (c, screen_nbr);
        +screen = screen_of_display (c, screen_nbr);
         if (screen)
           current_input_masks = screen->current_input_masks;
         
        @@ -3774,7 +3824,7 @@ if (screen)
               
      22. Miscellaneous macros
        1. DisplayOfScreen -

          +

          in Xlib, the Screen structure stores its associated Display structure. This is not the case in the X Window protocol, @@ -3784,13 +3834,13 @@ if (screen)

        2. DisplayCells / CellsOfScreen

          To get the colormap entries, - you look in the XCBVISUALTYPE + you look in the xcb_visualtype_t structure, that you grab like here:

          -XCBConnection *c;
          -XCBVISUALTYPE *visual_type;
          -CARD16         colormap_entries = 0;  /* the returned value of the colormap entries */
          +xcb_connection_t *c;
          +xcb_visualtype_t *visual_type;
          +uint16_t          colormap_entries = 0;  /* the returned value of the colormap entries */
           
           /* you init the connection and visual_type */
           
          diff --git a/doc/tutorial/xcb.css b/doc/tutorial/xcb.css
          index dd07232..d2ab886 100644
          --- a/doc/tutorial/xcb.css
          +++ b/doc/tutorial/xcb.css
          @@ -101,3 +101,23 @@ span.code
             font-family: monospace;
             font-size: 12px;
           }
          +pre.code type
          +{
          +  color: #44bb44;
          +}
          +pre.code function
          +{
          +  color: #449fb7;
          +}
          +pre.code include
          +{
          +  color: #7d93ae;
          +}
          +pre.code string
          +{
          +  color: #ef6e4b;
          +}
          +pre.code keyword
          +{
          +  color: #00bbbb;
          +}
          -- 
          2.7.4