Using Xlib to create a colored hardware cursor

Jannik Heller scrawl at baseoftrash.de
Thu Feb 2 08:33:04 PST 2012


I would like to use a different mouse cursor in my application instead 
of the standard X11 one  (it uses Ogre3D)

Here is what I've tried

     // getting the X11 window from OIS (ogre's input library)
     OIS::ParamList::iterator i = pl.find("WINDOW");
     Window window  = strtoul(i->second.c_str(), 0, 10);

     Display* display = XOpenDisplay(0);
     XcursorImage* image;

     Image im;
     im.load("cursor.png", 
ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
     PixelBox pb = im.getPixelBox();

     unsigned int w = pb.getWidth();
     unsigned int h = pb.getHeight();

     image = XcursorImageCreate(w, h);

     int c = 0;
     for (size_t y = 0; y < w; ++y)
     {
         for (size_t x = 0; x < h; ++x)
         {
             const ColourValue& cv = pb.getColourAt(x, y, 0);
             unsigned char r, g, b, a;
             r = cv.r; g = cv.g; b = cv.b; a = cv.a;

             image->pixels[c++] = (a<<24) | (r<<16) | (g<<8) | (b);
         }
     }

     Cursor xcursor = XcursorImageLoadCursor(display, image);
     XcursorImageDestroy(image);

     XDefineCursor(display, window, xcursor);
     XFlush(display);

But when starting my application I still see the standard X cursor, not 
the colored one. What am I doing wrong?

Also, how can I check for any X11 errors that might have occured? I 
couldnt find any good documentation on this.



More information about the xorg mailing list