mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-27 15:14:35 +00:00
Show the app icon on the macOS Dock via AppKit.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
0397519801
commit
6060a8d874
5 changed files with 97 additions and 6 deletions
55
macos_dock.c
Normal file
55
macos_dock.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "maturita.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <objc/message.h>
|
||||
#include <objc/runtime.h>
|
||||
|
||||
/* Set the macOS Dock tile icon. GTK's window icon-name is ignored on
|
||||
* Quartz, so we talk to AppKit directly via the Objective-C runtime. */
|
||||
void macos_set_dock_icon(const char *path) {
|
||||
Class nsstring;
|
||||
Class nsimage;
|
||||
Class nsapp;
|
||||
id path_str;
|
||||
id image;
|
||||
id app;
|
||||
|
||||
if (!path || !path[0])
|
||||
return;
|
||||
|
||||
nsstring = objc_getClass("NSString");
|
||||
nsimage = objc_getClass("NSImage");
|
||||
nsapp = objc_getClass("NSApplication");
|
||||
if (!nsstring || !nsimage || !nsapp)
|
||||
return;
|
||||
|
||||
path_str = ((id (*)(Class, SEL, const char *))objc_msgSend)(
|
||||
nsstring, sel_registerName("stringWithUTF8String:"), path);
|
||||
if (!path_str)
|
||||
return;
|
||||
|
||||
/* NSImage has -initWithContentsOfFile:, not +imageWithContentsOfFile:. */
|
||||
image = ((id (*)(id, SEL, id))objc_msgSend)(
|
||||
((id (*)(Class, SEL))objc_msgSend)(
|
||||
nsimage, sel_registerName("alloc")),
|
||||
sel_registerName("initWithContentsOfFile:"),
|
||||
path_str);
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
app = ((id (*)(Class, SEL))objc_msgSend)(
|
||||
nsapp, sel_registerName("sharedApplication"));
|
||||
if (!app) {
|
||||
((void (*)(id, SEL))objc_msgSend)(image, sel_registerName("release"));
|
||||
return;
|
||||
}
|
||||
|
||||
((void (*)(id, SEL, id))objc_msgSend)(
|
||||
app, sel_registerName("setApplicationIconImage:"), image);
|
||||
((void (*)(id, SEL))objc_msgSend)(image, sel_registerName("release"));
|
||||
}
|
||||
#else
|
||||
void macos_set_dock_icon(const char *path) {
|
||||
(void)path;
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue