Skip to content

Commit 0f31d33

Browse files
committed
[macOS] Only use Decorations#setImage() in Dock if no app bundle set
Currently, there are three possible sources for the Dock icon on macOS in the order of precedence: 1) An explicitly set icon via -Xdock:icon=/path/to/icon.icns which calls NSApp setApplicationIconImage 2) An implicitly set icon via org.eclipse.swt.widgets.Decorations.setImage(Image) org.eclipse.swt.widgets.Decorations.setImages(Image[]) which in passed down to the Dock also via NSApp setApplicationIconImage 3) An implicitly set icon in a Bundled.app distrubution via CFBundleIconName / CFBundleIconFile in the Info.plist file 1) and 2) use legacy API NSApp setApplicationIconImage which only supports a single fixed NSImage, i.e. there is no support for dark/light mode and or modern look & feel such as Liquid Glass. Only 3) (app bundle) supports dynamic icons. The problem is that 2) currently overwrites whatever 3) has set. On top of that, the Decorations are typically cross-platform, so in fact this will prevents using a macOS-specific icon at all. We want to prefer 3) over 2), i.e. only pass down the decorations whenever we are *not* an app bundle with a declared image. Similar coding also exists in the JVM, where the dock icon is only set if we are *not* in an app bundle that specifies an icon: https://github.com/openjdk/jdk21u/blob/8c322f5953ae161d793213f92d13a1f53d995883/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m#L280-L290
1 parent 79e74c7 commit 0f31d33

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Decorations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void setImage (Image image) {
515515
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
516516
this.image = image;
517517
if (parent != null) return;
518-
if (display.dockImage == null) {
518+
if (display.dockImage == null && !display.isBundledIconSet()) {
519519
display.application.setApplicationIconImage (image != null ? image.handle : null);
520520
}
521521
}
@@ -552,7 +552,7 @@ public void setImages (Image [] images) {
552552
}
553553
this.images = images;
554554
if (parent != null) return;
555-
if (display.dockImage == null) {
555+
if (display.dockImage == null && !display.isBundledIconSet()) {
556556
if (images != null && images.length > 1) {
557557
Image [] bestImages = new Image [images.length];
558558
System.arraycopy (images, 0, bestImages, 0, images.length);

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,17 @@ boolean isBundled () {
34413441
return false;
34423442
}
34433443

3444+
boolean isBundledIconSet () {
3445+
NSBundle mainBundle = NSBundle.mainBundle();
3446+
if (mainBundle != null) {
3447+
NSDictionary info = mainBundle.infoDictionary();
3448+
if (info != null) {
3449+
return info.objectForKey(NSString.stringWith("CFBundleIconName")) != null || info.objectForKey(NSString.stringWith("CFBundleIconFile")) != null ;
3450+
}
3451+
}
3452+
return false;
3453+
}
3454+
34443455
static boolean isValidClass (Class<?> clazz) {
34453456
String name = clazz.getName ();
34463457
int index = name.lastIndexOf ('.');

0 commit comments

Comments
 (0)