[Xcb] fonts and cursors

Vincent Torri vtorri at univ-evry.fr
Wed Sep 13 10:59:50 PDT 2006


Hey, Jamey

thanks for the answer. I now understand that i have completely 
misunderstood how the fonts and the cursors work together. Now it's 
better, I can get the cursor I want.

BUT (always a but)

i can't get the Plan 7 working :/

I've attached my code. Change the name of the font into whatever you want, 
no error is found.
Or else, I don't use correctly the API.

Also, another question : must we free the error returned by 
XCBRequestCheck ? It's not mentioned in the API doc (and I think that it 
must be added)

Vincent

On Wed, 13 Sep 2006, Jamey Sharp wrote:

> On Wed, Sep 13, 2006 at 10:38:51AM +0200, Vincent Torri wrote:
>> Hey,
>
> Hi Vincent!
>
> My first answer would be that this seems like a good use for Plan 7: if
> you make all three requests Checked and then call XCBRequestCheck on
> each void cookie, you'll find out where the error occurred.
>
>> XCBOpenFont (conn, font, strlen ("XC_hand1"), "XC_hand1");
>
> I believe your bug is that no font exists named "XC_hand1":
>
> ~$ xlsfonts XC_\*
> xlsfonts: pattern "XC_*" unmatched
>
> According to Tronche, "X provides a set of standard cursor shapes in a
> special font named cursor."
>
> http://the-labs.com/X11/XLib-Manual/pixmap-and-cursor/XCreateFontCursor.html
>
> ~$ xlsfonts -l cursor
> DIR  MIN  MAX EXIST DFLT PROP ASC DESC NAME
> -->    0  153   all    0    9  16   17 cursor
>
> Other than that, I don't see anything wrong with your code -- but then
> I've never written cursor-using code for X. :-)
>
> --Jamey
-------------- next part --------------
/* gcc -g -O2 -o xcb_font xcb_font.c `pkg-config --cflags --libs xcb-aux xcb` */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <X11/XCB/xcb.h>
#include <X11/XCB/xcb_aux.h>

int main ()
{
  XCBConnection   *conn;
  XCBSCREEN       *root;
  XCBGenericEvent *e;
  XCBWINDOW        window;
  CARD16           which;
  CARD32           mask;
  CARD32           values[2];
  int              screen_num;

  conn = XCBConnect (NULL, &screen_num);
  root = XCBAuxGetScreen (conn, screen_num);

  /* window */
  window = XCBWINDOWNew (conn);

  mask = XCBCWBackPixel | XCBCWEventMask;
  values[0] = root->white_pixel;
  values[1] = XCBEventMaskKeyRelease | XCBEventMaskExposure;

  XCBCreateWindow(conn,
                  XCBAuxGetDepth (conn, root),
                  window, root->root,
                  20, 200, 150, 150,
                  10, XCBWindowClassInputOutput,
                  root->root_visual,
                  mask, values);

  XCBMapWindow (conn, window);

  XCBAuxSync(conn);

  while (1) {
    e = XCBPollForEvent(conn, NULL);
    if (e) {
      switch (e->response_type) {
      case XCBExpose: {
        XCBVoidCookie cookie_font;
        XCBVoidCookie cookie_cursor;
        XCBVoidCookie cookie_attr;
        XCBGenericError *error;
        CARD32    value_list;
        XCBCURSOR cursor;
        XCBFONT   font;

        printf ("expose\n");
        font = XCBFONTNew (conn);
        cookie_font = XCBOpenFontChecked (conn, font, strlen ("cursor"), "cursor");
        error = XCBRequestCheck (conn, cookie_font);
        if (error) {
          printf ("Error font   : %d\n", error->error_code);
        }
        cursor = XCBCURSORNew (conn);
        which = 58;
        cookie_cursor = XCBCreateGlyphCursorChecked (conn, cursor, font, font,
                                                     which, which + 1,
                                                     255, 0, 0,
                                                     0, 255, 0);
        error = XCBRequestCheck (conn, cookie_cursor);
        if (error) {
          printf ("Error cursor : %d\n", error->error_code);
        }
        mask = XCBCWCursor;
        value_list = cursor.xid;
        cookie_attr = XCBChangeWindowAttributesChecked (conn, window, mask, &value_list);
        error = XCBRequestCheck (conn, cookie_attr);
        if (error) {
          printf ("Error attr   : %d\n", error->error_code);
        }
        XCBAuxSync(conn);
        XCBFreeCursor (conn, cursor);
        XCBCloseFont (conn, font);
        break;
      }
      case XCBKeyRelease: {
        XCBKeyReleaseEvent *ev;

        ev = (XCBKeyReleaseEvent *)e;

        switch (ev->detail.id) {
          /* ESC */
        case 9:
          free (e);
          goto out;
        }
      }
      }
      free (e);
    }
  }

 out:
  XCBDisconnect (conn);

  return 0;
}


More information about the Xcb mailing list