+ XcursorImages images = (XcursorImages)Marshal.PtrToStructure (images_ptr, typeof (XcursorImages));
+#if debug
+ Console.WriteLine ("DefineStdCursorBitmap, cursor has {0} images", images.nimage);
+#endif
+
+ if (images.nimage > 0) {
+ // We only care about the first image.
+ XcursorImage image = (XcursorImage)Marshal.PtrToStructure (Marshal.ReadIntPtr (images.images), typeof (XcursorImage));
+
+#if debug
+ Console.WriteLine ("DefineStdCursorBitmap, loaded image <size={0}, height={1}, width={2}, xhot={3}, yhot={4}, pixels={5}", image.size, image.height, image.width, image.xhot, image.yhot, image.pixels);
+#endif
+ // A sanity check
+ if (image.width <= short.MaxValue && image.height <= short.MaxValue) {
+ int [] pixels = new int [image.width * image.height];
+ Marshal.Copy (image.pixels, pixels, 0, pixels.Length);
+ bmp = new Bitmap (image.width, image.height);
+ for (int w = 0; w < image.width; w++) {
+ for (int h = 0; h < image.height; h++) {
+ bmp.SetPixel (w, h, Color.FromArgb (pixels [h * image.width + w]));
+ }
+ }
+ }
+ }
+
+ XplatUIX11.XcursorImagesDestroy (images_ptr);
+
+ } catch (DllNotFoundException ex) {
+ Console.WriteLine ("Could not load libXcursor: " + ex.Message + " (" + ex.GetType ().Name + ")");
+ return null;
+ }
+
+ return bmp;
+ }
+