Skip to content

Commit 4025747

Browse files
Move setting of awtAppClassName from MainWindow to Main
Move the setting of awtAppClassName for XToolkit into Main so that it is set before splash and import dialogs are created. This fixes issues with duplicate dock icons caused by incorrect WM_CLASS derived from this field value.
1 parent 4d933a7 commit 4025747

5 files changed

Lines changed: 27 additions & 17 deletions

File tree

nb/ide.branding/build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Contributor(s): Vincent Brabant, Maxym Mykhalchuk
4242
</copy>
4343
<replace file="${build.dir}/branding/core.startup/src/org/netbeans/core/startup/Bundle_nb.properties" value="defaultvalue" propertyFile="${nb_all}/nbbuild/build/netbeansrelease.properties">
4444
<replacefilter token="@@metabuild.ComputedSplashVersion@@" property="metabuild.ComputedSplashVersion"/>
45+
<replacefilter token="@@metabuild.ComputedTitleVersion@@" property="metabuild.ComputedTitleVersion"/>
4546
</replace>
4647
<locjar warnMissingDir="true"
4748
basedir="${build.dir}/branding/core.startup/src"

nb/ide.branding/core.startup/src/org/netbeans/core/startup/Bundle_nb.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ SplashVersionTextHorizontalAlignment=right
6363

6464
LBL_splash_window_title=Starting Apache NetBeans IDE
6565
currentVersion=Apache NetBeans IDE @@metabuild.ComputedSplashVersion@@
66+
AWT_AppClassName=Apache NetBeans IDE @@metabuild.ComputedTitleVersion@@
6667

6768
MSG_warning=NetBeans IDE - Warning
6869
MSG_info=NetBeans IDE - Information

platform/core.startup/src/org/netbeans/core/startup/Bundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ OpenIDE-Module-Long-Description=\
2828
# {0} - build number
2929
currentVersion=Apache NetBeans Platform Dev (Build {0})
3030

31+
# AppClassName - used on Linux for configuring WM_CLASS
32+
AWT_AppClassName=Apache NetBeans Platform
33+
3134
ERR_no_user_directory=netbeans.user is not set.\nPlease check your NetBeans startup script.
3235
# {0} - userdir full path
3336
# {1} - inst full path

platform/core.startup/src/org/netbeans/core/startup/Main.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
package org.netbeans.core.startup;
2121

22+
import java.awt.Toolkit;
2223
import java.io.File;
2324
import java.io.IOException;
25+
import java.lang.reflect.Field;
2426
import java.lang.reflect.InvocationTargetException;
2527
import java.lang.reflect.Method;
2628
import java.net.URL;
@@ -246,6 +248,7 @@ static void start (String[] args) throws SecurityException {
246248
if (CLIOptions.isGui ()) {
247249
try {
248250
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
251+
configureAWTAppClassName();
249252
} catch (java.lang.InternalError exc) {
250253
String s = NbBundle.getMessage(Main.class, "EXC_GraphicsStartFails1", exc.getMessage());
251254
System.out.println(s);
@@ -343,7 +346,7 @@ private static void rm(File f) {
343346
Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to delete {0}", f);
344347
}
345348
}
346-
349+
347350
/** Loads a class from available class loaders. */
348351
private static Class<?> getKlass(String cls) {
349352
try {
@@ -361,6 +364,24 @@ private static Class<?> getKlass(String cls) {
361364
}
362365
}
363366

367+
// moved from MainWindow::init to handle splash, etc.
368+
private static void configureAWTAppClassName() {
369+
Toolkit toolkit = Toolkit.getDefaultToolkit();
370+
Class<?> xtoolkit = toolkit.getClass();
371+
if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) { //NOI18N
372+
// TODO those add --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED
373+
374+
//#183739 / JDK-6528430 - provide proper app name on Linux
375+
try {
376+
final Field awtAppClassName = xtoolkit.getDeclaredField("awtAppClassName"); //NOI18N
377+
awtAppClassName.setAccessible(true);
378+
awtAppClassName.set(null, NbBundle.getMessage(Main.class, "AWT_AppClassName", "").strip()); //NOI18N
379+
} catch (Exception x) {
380+
Logger.getLogger(Main.class.getName()).log(Level.FINE, "can't change X11 application name", x);
381+
}
382+
}
383+
}
384+
364385
/** Does import of userdir. Made non-private just for testing purposes.
365386
*
366387
* @return true if the execution should continue or false if it should

platform/core.windows/src/org/netbeans/core/windows/view/ui/MainWindow.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.awt.*;
2424
import java.awt.event.*;
2525
import java.io.File;
26-
import java.lang.reflect.Field;
2726
import java.util.*;
2827
import java.util.List;
2928
import java.util.logging.Level;
@@ -116,21 +115,6 @@ public static void init() {
116115
if (mainMenuBar == null) {
117116
mainMenuBar = createMenuBar();
118117
ToolbarPool.getDefault().waitFinished();
119-
120-
Toolkit toolkit = Toolkit.getDefaultToolkit();
121-
Class<?> xtoolkit = toolkit.getClass();
122-
if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) { //NOI18N
123-
// TODO those add --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED
124-
125-
//#183739 / JDK-6528430 - provide proper app name on Linux
126-
try {
127-
final Field awtAppClassName = xtoolkit.getDeclaredField("awtAppClassName"); //NOI18N
128-
awtAppClassName.setAccessible(true);
129-
awtAppClassName.set(null, NbBundle.getMessage(MainWindow.class, "CTL_MainWindow_Title_No_Project", "").strip()); //NOI18N
130-
} catch (Exception x) {
131-
LOGGER.log(Level.FINE, "can't change X11 application name", x);
132-
}
133-
}
134118
}
135119

136120
logLookAndFeelUsage();

0 commit comments

Comments
 (0)