Window title and task bar icon

Hi, looking at the Juce demo code, I can add a system tray icon easily enough (Windows), but I can’t find a way to add the app try icon on the left of the task bar and on the left of the window of my JuceApplication. I’m using the native title bar.
Can anyone tell me where and when I do this exactly please? Thanks.

1 Like

I’m not totally what you mean by the left of the task bar (?) but does SystemTrayIconComponent::setIconImage do the trick?

For the native title bar:

    //From within your DocumentWindow or similar
    Image myLogoIconImage;
    setIcon (myLogoIconImage);
    getPeer()->setIcon (myLogoIconImage); //To specifically set the native titlebar icon
1 Like

Great, thanks. I looks like the getPeer() sets both the app icon and the Window icon so I don’t need the system tray stuff. So that’s all I needed, thanks again.

edit The system tray stuff adds an icon to the right of the task bar, along with the printer/graphics card/USB stick stuff. Steam is the only App I’ve seen to use that area.

p.s. I’m using a 48x48 image, is that OK?

Oh I see what you mean now!

IIRC, either JUCE or the OS resizes the image as needed.

But for the Mac OSX I use a larger image to keep it looking good?

256px² I believe for macOS

1 Like

Thanks for the info.

Is there a particular reason the OS X code for setIcon() is “Todo” still?

Is it even possible to add an icon to the native window title bar on OS X? I know we can override virtual void drawDocumentWindowTitleBar (DocumentWindow&... and provide an icon there.

Seems like you can:

Setting a Window’s Title and Represented File
A titled window can display an arbitrary title or one derived from a filename. The setTitle: method puts an arbitrary string on the title bar. The setTitleWithRepresentedFilename: method formats a filename in the title bar in a readable format and associates the window with that file. You can set the associated file without changing the title using setRepresentedFilename:. You can use the association between the window and the file in any way you see fit. One convenience offered by the NSWindow class is marking the file as having been changed, so that the user is prompted to save it on closing the window. The method for marking the document as having been changed is setDocumentEdited:. When the window closes, its delegate can check if the files has been changed using isDocumentEdited to see whether the document needs to be saved.

Additionally, starting in OS X version 10.5, you can set a window’s represented document by URL using the setRepresentedURL: method. You can get the URL of the document currently represented by a window using the representedURL method. The window will automatically use the known icon for the file type of the specified file, if one exists. To customize the document icon, you can use the following code segment:

[[NSWindow standardWindowButton:NSWindowDocumentIconButton] setImage:customImage].

By default, a Command-click or Control-click on the rectangle containing a window’s document icon button and title will show a path popup. To customize this behavior, you can implement window:shouldPopUpDocumentPathMenu: in your window’s delegate. You can return NO from this method to stop the window from showing the path popup.

You can also customize the document icon’s default drag behavior by implementing the window:shouldDragDocumentWithEvent:from:withPasteboard: in the window’s delegate. You can return NO to prohibit dragging the document icon.

Here’s the code they suggest:

[[NSWindow standardWindowButton:NSWindowDocumentIconButton] setImage:customImage].

If you can convert a juce::Image to a NSImage * , this is possible.
@jules etc can we get a quick fix pushed for this? I tried to see how you guys do it in CoreGraphicsContext::drawImage but it was way above my pay grade/skill level and gave up lol.

edit: initWithCGImage:size: | Apple Developer Documentation and static CGImageRef juce::CoreGraphicsImage::createImage()

maybe something like this?

void setIcon(const Image& customImage) {
    auto rgbColourSpace = CGColorSpaceCreateDeviceRGB();
    auto greyColourSpace = CGColorSpaceCreateDeviceGray();
    auto cgImageRef = juce_createCoreGraphicsImage(customImage,
                                                  customImage.getFormat() == Image::PixelFormat::SingleChannel ? greyColourSpace : rgbColourSpace,
                                                  false);
    auto nsImage = [[NSImage alloc] initWithCGImage:cgImageRef size:NSMakeSize(customImage.getWidth(), customImage.getHeight())];
    [[window standardWindowButton:NSWindowDocumentIconButton] setImage:nsImage];
}

bump @jules

not even a glance from @jules or @ed95 or @fabian?

it’s still not implemented even on the develop branch:

please check out my comments a few posts ago that provides a possible solution, or at the very least, a direction to get this missing feature on OS X Native Titlebars added.