Peter Addy
Peter Addy

Reputation: 53

How to create a cursor in X11 from raw data c++

I have been searching around about this problem for awhile. I am making a cross platform program and I have figured out how to load an animated cursor with the windows API and how to create a cursor during run time from raw bitmap data. However I can't find good documentation for this for X11, for my Unix/Linux build of my program. I know I need to use the XRender extension functions, XRenderCreateCursor and XRenderCreateAnimCursor from this documentation https://www.x.org/releases/X11R7.6/doc/libXrender/libXrender.txt but I do not know how to use these functions and the documentation does now show any examples.

Also the raw image data is in the ARGB format, and I want to support the Alpha channel if possible with these cursors.

Could someone show me how to use the X11 and XRender (or XCursor) Library to create a cursor, static and animated, and possibly how to do it so the cursor can be used with any X11 window.

Thanks!

PS.

I am acually editing a open source libary for cross platfrom Gui that I am using for my program, and I am trying to add this feature into the libary but I am not used to programing with X11.

Upvotes: 1

Views: 1250

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118292

When it comes to X, nothing is simple.

First, review the specification of the X render extension.

The steps for creating an animated cursor are as follows.

  1. First, you need to create a PICTURE for each frame of the animated cursor, using CreatePicture.

  2. Use CreateCursor to create a CURSOR from each PICTURE. CreateCursor returns a CURSOR handle.

  3. Then, you take the list of all CURSORs for all of the frames, and then use CreateAnimCursor to create a single CURSOR representing the animated cursor.

This all comes down to creating a PICTURE for each frame. A PICTURE is created using CreatePicture from a DRAWABLE and a PICTFORMAT. DRAWABLE would be the PIXMAP with the actual bitmask for the cursor's frame, and PICTFORMAT specifies which channels in the pixmap represent the red, color, and green channels, and must be one of the enumerated PICTFORMATs returned from QueryPictformat.

For more information, see the aforementioned X render extension specification.

Upvotes: 1

Related Questions