diff --git a/src/classes/PMacDockIcon.mm b/src/classes/PMacDockIcon.mm new file mode 100644 index 00000000..2229f593 --- /dev/null +++ b/src/classes/PMacDockIcon.mm @@ -0,0 +1,43 @@ +/*************************************************************************** + + PMacDockIcon.mm + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2026 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#import + +#include "PMacDockIcon.h" + +void SetMacDockIcon(const unsigned char *pngData, unsigned int pngDataLen) +{ + @autoreleasepool { + NSData *data = [NSData dataWithBytes:pngData length:pngDataLen]; + NSImage *image = [[[NSImage alloc] initWithData:data] autorelease]; + if (image != nil) { + [NSApplication sharedApplication].applicationIconImage = image; + } + } +} diff --git a/src/include/PMacDockIcon.h b/src/include/PMacDockIcon.h new file mode 100644 index 00000000..d5ab1d9d --- /dev/null +++ b/src/include/PMacDockIcon.h @@ -0,0 +1,41 @@ +/*************************************************************************** + + PMacDockIcon.h + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2026 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _PMACDOCKICON_H_ +#define _PMACDOCKICON_H_ + +// On macOS, ROOT's Cocoa backend (TGCocoa) implements TVirtualX::SetIconPixmap() +// and TVirtualX::SetClassHints() as no-ops: Cocoa windows do not carry an +// X11-style per-window icon/class hint, and the Dock icon is process-wide, +// set once via [NSApp setApplicationIconImage:]. This helper provides that +// macOS-specific replacement so musrview/musrFT/musrt0 show their own Dock +// icon instead of the generic ROOT one. It is a no-op on all other platforms. +void SetMacDockIcon(const unsigned char *pngData, unsigned int pngDataLen); + +#endif // _PMACDOCKICON_H_