19#import <AppKit/AppKit.h>
23#include <winpr/assert.h>
25#include "mac_cursor.h"
30 memset(image, 0,
sizeof(*image));
35 NSCursor *cursor = [NSCursor currentSystemCursor];
36 NSImage *picture = cursor.image;
40 const NSSize size = picture.size;
41 const NSPoint hot = cursor.hotSpot;
42 const double width = ceil(size.width);
43 const double height = ceil(size.height);
44 if ((width < 1.0) || (height < 1.0) || (width > maxSize) || (height > maxSize))
49 NSRect rect = NSMakeRect(0, 0, width, height);
50 CGImageRef cgImage = [picture CGImageForProposedRect:&rect context:nil hints:nil];
54 const size_t w = (size_t)width;
55 const size_t h = (size_t)height;
56 BYTE *pixels = calloc(w * h, 4);
61 CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
62 CGContextRef context =
63 CGBitmapContextCreate(pixels, w, h, 8, w * 4, space,
64 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
65 CGColorSpaceRelease(space);
71 CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
72 CGContextRelease(context);
74 image->width = (UINT32)w;
75 image->height = (UINT32)h;
76 image->xHot = (UINT32)MIN(MAX(hot.x, 0.0), width - 1.0);
77 image->yHot = (UINT32)MIN(MAX(hot.y, 0.0), height - 1.0);
78 image->pixels = pixels;