Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nb/ide.branding/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Contributor(s): Vincent Brabant, Maxym Mykhalchuk
</copy>
<replace file="${build.dir}/branding/core.startup/src/org/netbeans/core/startup/Bundle_nb.properties" value="defaultvalue" propertyFile="${nb_all}/nbbuild/build/netbeansrelease.properties">
<replacefilter token="@@metabuild.ComputedSplashVersion@@" property="metabuild.ComputedSplashVersion"/>
<replacefilter token="@@metabuild.ComputedTitleVersion@@" property="metabuild.ComputedTitleVersion"/>
</replace>
<locjar warnMissingDir="true"
basedir="${build.dir}/branding/core.startup/src"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ SplashVersionTextHorizontalAlignment=right

LBL_splash_window_title=Starting Apache NetBeans IDE
currentVersion=Apache NetBeans IDE @@metabuild.ComputedSplashVersion@@
AWT_AppClassName=Apache NetBeans IDE @@metabuild.ComputedTitleVersion@@

MSG_warning=NetBeans IDE - Warning
MSG_info=NetBeans IDE - Information
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ OpenIDE-Module-Long-Description=\
# {0} - build number
currentVersion=Apache NetBeans Platform Dev (Build {0})

# AppClassName - used on Linux for configuring WM_CLASS
AWT_AppClassName=Apache NetBeans Platform

ERR_no_user_directory=netbeans.user is not set.\nPlease check your NetBeans startup script.
# {0} - userdir full path
# {1} - inst full path
Expand Down
23 changes: 22 additions & 1 deletion platform/core.startup/src/org/netbeans/core/startup/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

package org.netbeans.core.startup;

import java.awt.Toolkit;
import java.beans.Introspector;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
Expand Down Expand Up @@ -247,6 +249,7 @@ static void start (String[] args) throws SecurityException {
if (CLIOptions.isGui ()) {
try {
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
configureAWTAppClassName();
} catch (java.lang.InternalError exc) {
String s = NbBundle.getMessage(Main.class, "EXC_GraphicsStartFails1", exc.getMessage());
System.out.println(s);
Expand Down Expand Up @@ -345,7 +348,7 @@ private static void rm(File f) {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to delete {0}", f);
}
}

/** Loads a class from available class loaders. */
private static final Class getKlass(String cls) {
try {
Expand All @@ -363,6 +366,24 @@ private static final Class getKlass(String cls) {
}
}

// moved from MainWindow::init to handle splash, etc.
private static void configureAWTAppClassName() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Class<?> xtoolkit = toolkit.getClass();
if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) { //NOI18N
// TODO those add --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED

//#183739 / JDK-6528430 - provide proper app name on Linux
try {
final Field awtAppClassName = xtoolkit.getDeclaredField("awtAppClassName"); //NOI18N
Comment on lines +373 to +378
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find it curious that the field isn't final -> we are lucky here since final might mean final in not too far future.

https://github.com/openjdk/jdk/blob/20c3082aac4381a5d38ed3abb34b3651b2d28e08/src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java#L164

I think this is ok since it is only moving code around. But all those hacks have to go away. Every --add-opens flag we set is a red flag.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's such a commonly used workaround that it's probably deliberately kept like that. An API or system property would be great for this, but it doesn't look like it's happening anytime soon! https://bugs.openjdk.org/browse/JDK-6528430 😄 This will also need consideration if/when there's a move from XWayland to Wakefield.

The only other workaround is to ensure the toolkit is initialized from the main thread, but that would lead to a shared WM_CLASS across all platform applications.

awtAppClassName.setAccessible(true);
awtAppClassName.set(null, NbBundle.getMessage(Main.class, "AWT_AppClassName", "").strip()); //NOI18N
} catch (Exception x) {
Logger.getLogger(Main.class.getName()).log(Level.FINE, "can't change X11 application name", x);
}
}
}

/** Does import of userdir. Made non-private just for testing purposes.
*
* @return true if the execution should continue or false if it should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.lang.reflect.Field;
import java.util.*;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -116,21 +115,6 @@ public static void init() {
if (mainMenuBar == null) {
mainMenuBar = createMenuBar();
ToolbarPool.getDefault().waitFinished();

Toolkit toolkit = Toolkit.getDefaultToolkit();
Class<?> xtoolkit = toolkit.getClass();
if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) { //NOI18N
// TODO those add --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED

//#183739 / JDK-6528430 - provide proper app name on Linux
try {
final Field awtAppClassName = xtoolkit.getDeclaredField("awtAppClassName"); //NOI18N
awtAppClassName.setAccessible(true);
awtAppClassName.set(null, NbBundle.getMessage(MainWindow.class, "CTL_MainWindow_Title_No_Project", "").strip()); //NOI18N
} catch (Exception x) {
LOGGER.log(Level.FINE, "can't change X11 application name", x);
}
}
}

logLookAndFeelUsage();
Expand Down
Loading