Skip to content

[macOS] Decorations#setImage() overwrites Dock icon specified in App Bundle #2627

@sratz

Description

@sratz

Describe the bug

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

To Reproduce

Build an RCP product as a macOS Product.App, which defines a macOS-specific icon in the .product configuration and also launches a branded RCP product.

When the product launches, it shortly shows the icon defined in the Product.app/Info.plist file.

As soon as SWT initializes it overwrites the icon with whatever platform-agnostic icon is set in the product branding.

Expected behavior

The icon specified in the Product.App should be shown in the Dock.

Screenshots

During launcher:

Image

After SWT initialization:

Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS

Workaround (or) Additional context

Specifying -Xdock:icon=/path/to/static/image.icns prevents SWT from changing the Dock image, but this is legacy API and does not support modern / dynamic icon features

Metadata

Metadata

Assignees

No one assigned

    Labels

    macOShappens on macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions