Trifork Blog

Make Intellij IDEA behave properly in linux docks

January 9th, 2011 by
|

One of my pet peeves when working on Linux has always been that java applications do not work well with popular docks like Docky and Cairo dock. When you add a Java application as a launcher to the dock and use it to launch the application it will still create another icon in the dock, which in a way defeats the purpose of a dock. Reading the comments in following bugreport made it apparent to me, that this is not something that can be easily fixed by the dock’s authors, since the problem lies within the jdk. A workaround exists but it does not apply to all Java applications.

One of the applications the workaround does not work for, unfortunately is Intellij IDEA. The one application I use most on a day to day basis.

When you request the WM_CLASS for Intellij it will identify itself as java-lang-Thread

xprop | grep WM_CLASS | awk '{print $4}'
"java-lang-Thread"

Which is not something that can be used to identify all windows belonging to Intellij. So I decided to see if I could work around this problem, and succeeded. Here’s what you do to make Intellij behave properly

UPDATE 23-01-2010 : whoah seems my original approach had some issues with classloading. (Who needs to create new classes anyway 😉 ) So here are the new and improved instructions.

1. Download  agent.jar and copy it to Intellij’s bin folder.

I wont describe in detail what this jar does. But it’s something i created that changes the default value sun.awt.X11.XToolkit assigns to WM_CLASS. The sources are included in the jar

2. Open idea.sh  And change the line  that looks like

exec $IDEA_JDK/bin/java $JVM_ARGS $IDEA_MAIN_CLASS_NAME $*

to

exec $IDEA_JDK/bin/java -javaagent:agent.jar=Intellij_IDEA $JVM_ARGS $IDEA_MAIN_CLASS_NAME $*

3. Find the .desktop file that is used to start intellij by executing the following command from your home folder

find . -name '*.desktop' -exec grep -H idea.sh {} \;

4. Edit the file you found in step 3 and add the following line

StartupWMClass=Intellij_IDEA

Done!

24 Responses

  1. January 10, 2011 at 13:46 by testing123

    Eens kijken of dit ook werkt…

  2. January 10, 2011 at 13:50 by Jelmer Kuperus

    works on my pc ™ 😉

  3. January 10, 2011 at 17:15 by Krzysztof Zalewski

    Hi! It works great for Intellij, but could You please make such launchers for RubyMine and PyCharm?

    I would be very thankfull 🙂 Thanks in advance 🙂

  4. January 11, 2011 at 22:41 by Thai Dang Vu

    Are you able to provide the source code of launcher.jar? Who knows if you put some Java-based virus inside 🙂

  5. January 11, 2011 at 22:58 by Jelmer Kuperus

    Hi Thai Dang Vu, like i mention in my post, the sources are included in the jar file.

  6. January 11, 2011 at 23:04 by Jelmer Kuperus

    Hi Krzysztof, RubyMine and PyCharm are just specialized versions of Intellij i wouldn’t be surprised if my launcher works for those apps without modification. Did you try that yet ?

  7. January 12, 2011 at 01:28 by Krzysztof Zalewski

    @Jelmer Kuperus
    I think that Your launcher would work, but the problem is, that I’m using both RubyMine and PyCharm (sometimes even Intellij :P) and they’re all named “Intellij IDEA” (i’ve checked source code). It could cause some problems (i think).

    Maybe You could create one launcher which would take the name of application (“rubymine”, “pycharm”, “phpstorm” etc.) from some config files.

  8. January 12, 2011 at 23:39 by Krzysztof Zalewski

    @Jelmer Kuperus
    I’ve just checked – it doesn’t work with RubyMine 3.0.1 (maybe with other versions too, i don’t know).

  9. January 23, 2011 at 15:13 by Jelmer Kuperus

    @Krzysztof Zalewski

    I had to redo my fix due to some classloading issues, and in the process made it a bit more generic. The new one should work with any java app. Just change

    -javaagent:agent.jar=Intellij_IDEA

    to

    -javaagent:agent.jar=SOMETHING_ELSE

    for another application

  10. January 30, 2011 at 23:23 by Krzysztof Zalewski

    @Jelmer Kuperus
    Now it works with Intellij, RubyMine, PyCharm and PhpStorm (2.0-pre) (I’ve checked them all)
    Thanks
    🙂

  11. April 25, 2011 at 15:57 by Stanislav Chekalin

    Tried to do this in Ubuntu 10.10 with IntellJ IDEA 10.0.3 and it doesn’t work. There is no line that starts with exec… but I have changed the following loop:
    while true ; do
    $IDEA_JDK/bin/java $JVM_ARGS -Djb.restart.code=88 $IDEA_MAIN_CLASS_NAME $*
    test $? -ne 88 && break
    done

    to

    while true ; do
    $IDEA_JDK/bin/java -javaagent:agent.jar=Intellij_IDEA $JVM_ARGS -Djb.restart.code=88 $IDEA_MAIN_CLASS_NAME $*
    test $? -ne 88 && break
    done

    has someone managed to configure Idea 10 this way or am I doing something wrong?

  12. April 25, 2011 at 16:06 by Stanislav Chekalin

    I have checked with xprop | grep WM_CLASS | awk ‘{print $4}’ and it is still “java-lang-Thread”

  13. June 20, 2011 at 21:18 by Krzysztof Zalewski

    Stanizlav Chekalin, I’ve got Ubuntu 11.04 (tried on Fedora 15 too) and IDEA 10.5 and this one works: http://goo.gl/ix8sD

  14. October 19, 2011 at 16:23 by Rubens Mariuzzo

    Super, it works like a charm in Ubuntu 11.10! Thanks, awesome work!

  15. October 24, 2011 at 02:17 by Dziamid

    Thank you so much, I wonder if you could submit your patch to JetBrains developers, who are now willing to take care about the problem that you’ve solved.

  16. November 5, 2011 at 20:03 by Alessandro

    With PhpStorm 2.15 had to apply your fix here:

    $WEBIDE_JDK/bin/java $JVM_ARGS -Djb.restart.code=88 -javaagent:agent.jar=JetBrains_PhpStorm $WEBIDE_MAIN_CLASS_NAME $*

    now it works like a charm, thanks!

  17. December 8, 2011 at 10:48 by Alan Franzoni

    I did some work over your solution and created a Linux launcher! I just wrote a post about it.

    http://ollivander.franzoni.eu/2011/12/jetbrains-ides-dock-aware-launcher-for.html

  18. December 14, 2011 at 10:34 by Alan Franzoni

    Just one more update:

    IDEA 11 and above and PyCharm 2 and above don’t need the agent anymore, the WM_CLASS is set correctly by the IDE itself, and the .desktop entry can be created via Tools -> Create desktop entry menu.

  19. December 17, 2011 at 15:15 by topr

    For Intellij Idea 11 under Ubuntu 11.10 is enough to add at .desktop file the line:

    StartupWMClass=jetbrains-idea

  20. December 22, 2011 at 14:53 by Marcus

    Hello

    I tested on Ubuntu Unity Launcher, adding “-javaagent” arg into the idea.vmoptions file; and it works perfectly! Great

    As long as I understood, it should work for any Java application, shouldn’t it?

    Thanks

  21. February 17, 2012 at 15:07 by autra

    Hi,

    Thanks for this tips, works like a charme, except that when you click the icon or hit super+the number corresponding to the icon, Idea does not take the focus. Any solution to this?

  22. January 22, 2013 at 16:15 by John

    Got it to work under Linux Mint 13 (Maya) and IntelliJ IDEA 12 and Cairo Dock! There was no line beginning with ‘exec’ in idea.sh but I changed:

    eval “$JDK/bin/java” $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*

    to

    eval “$JDK/bin/java” -javaagent:/home/john/Software/idea-IU-123.94/bin/agent.jar=Intellij_IDEA $ALL_JVM_ARGS -Djb.restart.code=88 $MAIN_CLASS_NAME $*

    Note that I included the full path to agent.jar. It did NOT work UNTIL i did that.

    Thanks Jelmer!

  23. May 19, 2013 at 20:12 by Sean

    Thanks. One thing I had to do was put in the full path to agent.jar. Also, it’s possible to add that line to the .vmoptions file instead of editing the .sh startup script.