[macOS] Only use Decorations#setImage() in Dock if no app bundle set #2628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there are three possible sources for the Dock icon on macOS in the order of precedence:
An explicitly set icon via
-Xdock:icon=/path/to/icon.icns
which calls
NSApp setApplicationIconImage
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
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
Resolves #2627