Browse Source

comments

pull/5425/head
annes 2 months ago
committed by GitHub
parent
commit
1b03173e2a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      src/_cocoalayer.mm

+ 9
- 0
src/_cocoalayer.mm View File

@ -34,14 +34,23 @@ extern "C" {
void CocoaSetDockIcon(unsigned char* data, int width, int height) void CocoaSetDockIcon(unsigned char* data, int width, int height)
{ {
// Create an empty NSImage
NSImage *dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; NSImage *dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
// Create a CGImage
CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, data, width*height*4, nullptr); CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, data, width*height*4, nullptr);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef cgImage = CGImageCreate(width, height, 8, 32, width*4, colorSpace, CGImageRef cgImage = CGImageCreate(width, height, 8, 32, width*4, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big,
provider, nullptr, false, kCGRenderingIntentDefault); provider, nullptr, false, kCGRenderingIntentDefault);
// Keep the Icon Alive?
[dockIcon addRepresentation:[[NSBitmapImageRep alloc] initWithCGImage:cgImage]]; [dockIcon addRepresentation:[[NSBitmapImageRep alloc] initWithCGImage:cgImage]];
// set the app icon
[NSApp setApplicationIconImage:dockIcon]; [NSApp setApplicationIconImage:dockIcon];
// Free the garbage
CGImageRelease(cgImage); CGImageRelease(cgImage);
CGColorSpaceRelease(colorSpace); CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(provider); CGDataProviderRelease(provider);

Loading…
Cancel
Save