Browse Source

Implement function to set macOS dock icon

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

+ 20
- 0
src/_cocoalayer.mm View File

@ -0,0 +1,20 @@
#if defined(__APPLE__)
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>
#include "_cocoalayer.h"
// Example: make a global function you can call
extern "C" void _cocoasetdockicon(unsigned char* data, int width, int height)
{
NSImage *dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, data, width*height*4, nullptr);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef cgImage = CGImageCreate(width, height, 8, 32, width*4, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big,
provider, nullptr, false, kCGRenderingIntentDefault);
[dockIcon addRepresentation:[[NSBitmapImageRep alloc] initWithCGImage:cgImage]];
[NSApp setApplicationIconImage:dockIcon];
CGImageRelease(cgImage);
CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(provider);
}
#endif

Loading…
Cancel
Save