With the coming demise of Ubuntu’s Unity it’s time to look at Gnome3, the supposed successor.
I’m using Dash-to-Dock, and noticed that it did not play nice with Java applications: when I start Oracle SQLDeveloper it shows a second icon for SQLDeveloper, even though the icon is already in the dock. If I start both SQLDeveloper and IntelliJ from the dock it gets worse, as IntelliJ is seen as the second “window” of SQLDeveloper 8-/
The problem is caused by a bug/oversight in the JDK (known for years and of course not fixed) where it assigns the same WM_CLASS to any Java program. WM_CLASS is used by launchers to distinguish between programs, so when all Java programs use the same WM_CLASS things go awry.
To fix this is a bit of work, so let’s delve in.
First check the window IDs of the programs you have trouble with.
Start the program you need to check, then open a terminal and enter
xprop WM_CLASS
Now use CTRL+TAB to move to the program’s main window and click it. That should show the window-ID in the terminal:
WM_CLASS(STRING) = “sun-awt-X11-XFramePeer”, “jetbrains-idea”
For Oracle SQLDeveloper this thingjust shows:
WM_CLASS(STRING) = “sun-awt-X11-XFramePeer”, “”
We need SQLDeveloper to also add a unique string at the end. Sadly enough there is no environment or command line option you can use, but we can use a trick.. A special Java Agent (thanks, jelmerk) can be used to “patch” the Java class that defines the window name at class load time. The page linked to contains a very old version of the code, but there is a push request for a Java 8 version. This results in the following jar that you need to download:
agent.jar
Now we need to fix SQLDeveloper to use this, as follows:
1 2 3 4 5 6 |
Go to the directory where you installed SQLDeveloper Copy the "agent.jar" file you downloaded into ide/lib Edit the file ide/bin/ide.conf Add the line: AddVMOption -javaagent:../lib/agent.jar=SqlDeveloper Save the file |
Now restart SQLDeveloper and again use xprop WM_CLASS to see what the window ID is now, it should answer with:
WM_CLASS(STRING) = “sun-awt-X11-XFramePeer”, “SqlDeveloper”
The second part is to teach Gnome3 to distinguish between these Java programs. For that you need to edit the .desktop files that launch these applications, usually found in your home directory under ~/.local/share/applications. My sqldeveloper.desktop file there reads:
1 2 3 4 5 6 7 8 9 10 11 |
#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=false StartupNotify=true Exec=/home/jal/opt/sqldeveloper/sqldeveloper.sh Icon=/home/jal/opt/sqldeveloper/icon.png Name=SQL Developer #Edit this file, then add the following line at the end: StartupWMClass=SqlDeveloper |
The “SqlDeveloper” there must be the exact same string that you used when you changed the ide.conf file.
We need to do the same for IntelliJ, but we do not need the agent.jar because it already defines a WMCLASS. Just add the following to your intellij.desktop file:
StartupWMClass=jetbrains-idea
After these changes log out and log in again, after that the dash should correctly associate icons with the windows.