Bug 381970 - -Xdock:name does not set the dock tooltip for swt app
Summary: -Xdock:name does not set the dock tooltip for swt app
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.2   Edit
Hardware: PC Mac OS X
: P3 normal with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2012-06-07 05:28 EDT by Klara Ward CLA
Modified: 2020-02-13 08:24 EST (History)
7 users (show)

See Also:


Attachments
Conceptual patch (6.80 KB, patch)
2013-12-05 05:41 EST, Markus Persson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Klara Ward CLA 2012-06-07 05:28:34 EDT
Build Identifier: Version: 3.8.0 Build id: I20120531-0600

Running an swt app with -Xdock:name=Foobar does not set the dock tooltip name, and not the name you see when you cmd+tab or go to Mission Control.

In those places the name will still be java.
In the menu, and in Activity Monitor, Foobar will be shown.

Happens with Apple JDK 60u31 as well as Oracle JDK 7u4 (and latest build of 7u6)

-Xdock:icon seems to work just fine.

Reproducible: Always

Steps to Reproduce:
1. Create an HelloSWT program
2. Export as runnable jar file.
3. Run with java -XstartOnFirstThread -Xdock:name=Foobar -jar helloswt.jar
3. Notice "Foobar" in the menu, and "java" in the dock.
Comment 1 Klara Ward CLA 2012-06-07 05:37:25 EDT
Btw, Same commandline but with a swingapp will set the dock tooltip.
Comment 2 Markus Persson CLA 2013-12-05 05:41:36 EST
Created attachment 238060 [details]
Conceptual patch

By piecing together information from various sources (see  below), I have come up with a conceptual patch to solve this in org.eclipse.swt.widgets.Display.createDisplay(). This seems to work for OS X 10.7 (Lion) and 10.8 (Mountain Lion). At least when started from within Eclipse; I was unable to build an swt fragment jar where this worked, but that might be just me.

For OS X 10.9 (Mavericks), this doesn’t work yet, but AWT cannot set the dock name either. So a fix from Apple is most likely needed there. See https://bugs.openjdk.java.net/browse/JDK-8029440 . More about that below.

First and foremost, it might be that Cocoa doesn't allow the name in the dock to be changed once the NSApplication singleton has been created. The name is at least frozen when the dock tile has appeared. Trying to change it later is pointless. (I'm not sure if something similar applies to Carbon apps.) Since the NSApplication singleton is created whenever asked for, there might be cases where my patch isn't sufficient. For example, if the eclipse executable launcher is compiled for Cocoa. (It is my understanding that Eclipse compiles this binary using Carbon APIs, even with the Cocoa port of SWT.)

Secondly, since Cocoa applications are supposed to provide static information like this in the Info.plist file in the app bundle, there are no public APIs to set the dock name. That is, except in the JavaRuntimeSupport.framework (a sub-framework of the JavaVM.framework), which added support for this in the somewhat unfortunately named JRSAppKitAWT class. I have been assured by Mike Swingler (Apple Java Engineering) that although largely undocumented, this framework, class and the method registerAWTAppWithOptions: is indeed public and not at all specific to any particular GUI toolkit.

Currently, SWT tries to set the dock name using what I assume is a Carbon call, CPSSetProcessName(), that I haven't found any public references to. (Also, this is typically after the NSApplication singleton has been created.)

The needed interface can be found in /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Headers/JRSAppKitAWT.h

It contains four string keys that can be used as option keys in the registerAWTAppWithOptions: call. One is obvious. Two can be figured out by correlating with documented Apple specific system properties and Launch Services keys in Info.plist. I had to ask in the Apple Developer Forums for the last one.

* JRSAppNameKey = The name of the app in the dock.

* JRSAppIsUIElementKey = If true, register as an "agent app", which isn't visible in the dock. Same as the "apple.awt.UIElement" system property or the "LSUIElement" key in Info.plist. (See https://developer.apple.com/library/mac/documentation/Java/Reference/Java_PropertiesRef/Articles/JavaSystemProperties.html and http://developer.apple.com/library/mac/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 )

* JRSAppIsBackgroundOnlyKey = If true, register as a faceless/invisible app. Same as the "LSBackgroundOnly" key in Info.plist, and presumably, an "apple.awt.BackgroundOnly" system property although I found no documentation for that. (See http://developer.apple.com/library/mac/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-109268 )

* JRSAppIsCommandLineKey = If true, use the app name as specified by "JRSAppNameKey". Otherwise, assume the application is bundled and use an ordinary [NSBundle mainBundle] to control dock appearance. (If not true, and not bundled, you'll get the name from the folder where the executable is located, typically the jre/bin folder.) 

SWT already uses this class to try to obtain the AWT app delegate (which, as a side note, does not work well with JDK7).

For OS X 10.9, I tried a slightly different approach by subclassing NSApplication and overriding -init (instead of changing the class on the instance after the NSApp singleton has been created, as SWT does now). In -init, I tried to register the application. But I didn’t see any change in behavior. The name in the dock remained to be that of the executable, typically “java”.
Comment 3 Lakshmi P Shanmugam CLA 2017-07-03 07:46:34 EDT
Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more
information.