Intellij IDEA losing focus in stumpwm on Linux

Or why Oracle sucks!

I just installed Intellij today, not to replace Emacs (or Eclipse for Liferay stuff), but to use for things like PHP (which sucks) that Emacs doesn’t have very good modes for. In addition in Liferay I often have to use Freemarker and Velocity templates, and neither Eclipse or Emacs handle them well (I want debugging).

Anyhow. When ever switching windows in Stumpwm away from Intellij and back, Intellij loses focus and doesn’t regain focus until I click at a specific place. Basically the problem is that Stumpwm is not a reparenting window manager, combined with the fact that Oracle sucks. Basically they have hard coded a couple of window managers in swing that they support. Anything else, your basically screwed. Furthermore, Oracle say they only support Gnome and KDE. So if you don’t use a mainstream DE, you are basically out in the cold. Here is a bug report that they have marked as “Not an issue”. This doesn’t really come as a surprise. Java GUI has always sucked. Java is fine for backend applications, for desktop applications, not so much. Though, in all fairness they have gotten better over time, but still are barely usable. I really wish people simply would stop making desktop applications in Java.

I spent a whole weekend trying to fix the issue, but came up blank. And yes, I’ve tried both the wmname LG3D trick and setting _JAVA_AWT_WM_NONREPARENTING=1, but nothing works. I finally gave up, and made a really hacky run and raise command that emulates a mouse click in the correct place. It’s really bad, but it works for now. If anybody has a suggestion how to fix this, please, please leave a comment.


I got this sort of working using a really nasty hack I wrote. It fixes most of the focus issues, but not all. It also causes issues with copy/paste from other applications so I have to use xclip to sync clipboards. Basically I start an xterm, start Xephyr and hijack the xterm window. Inside Xephyr I start metacity, and use devilspie to remove window decorations from metacity. Finally I start Intellij inside. Yeah!

killall -9 devilspie & killall -9 Xephyr & xterm -class intellij -name intellij & sleep 1 && Xephyr -keybd ephyr,,,xkbmodel=pc105,xkblayout=us,xkbvariant=altgr-intl,xkboptions=ctrl:nocaps -ac -br :1.0 -parent `xprop -notype -name intellij WM_CLIENT_LEADER | awk '{ print $5 }'` & sleep 2 && DISPLAY=:1.0 /usr/bin/metacity & sleep 3 && DISPLAY=:1.0 /usr/bin/devilspie & sleep 4 && DISPLAY=:1.0 /usr/bin/intellij




  1. Konstantin Bulenkov

    Hi Brendan!
    Thank you for such a detailed story. I feel I’m not alone who’s fighting with Swing Unix Window Managers integration. I’ve spent months writing hacks in IntelliJ against focus issues on Linux and I think 90% of issues come from Native Window Managers. Same WM behaves differently on the different versions of Ubuntu. Why this never happens with different versions of Windows or Mac OS X?

    All major problems and possible solutions are described here (chapter 2.7) Maybe it will be useful

  2. Brendan Johan Lee

    Hi Konstantin!

    Swing applications are more often than not a nightmare in Linux. Some of it is indeed the fact that WMs in Linux are very fragmentet, but it’s far from the only problem. How often do you see issues with native Linux apps because of your WM? Not very often. It’s not really the case that Swing works fine on Windows. I’ve experienced lot’s of issues with Swing in Windows up through the years. However, they are not as common, and Sun/Oracle generally tend to fix them (eventually). On Linux they generally simply ignore them.

    But back to the fragmentation issue. I think my fix is rather illustrative of the problem. I ended up using metacity in Xephyr, not because metacity worked, but because metacity had the least issues of all of the many WMs I tested.

    Finally the situation is complicated even more by the fact that I use a tiling window manager. This is a concept that is radically different than Windows and OSX, and it really only exists in the UNIX world (why that is I’m not quite sure). Basically, the concept is that the WM and you control where, how and when applications are rendered instead of to a large degree the applications. This saves heaps of time. You don’t spend lots of time tweaking window positions with a mouse, which is a flawed input tool. Everything goes where it should go, always, after some initial configuration. Furthermore focus is where you want it, not where some random application or your operating system happens to want to place it at any given time. It is a much better, faster, and more productive concept tha the concepts we know, now mainly from Windows. However, it’s radically different than the norm, and when software developers developing core features (such as Swing) ignore it, that causes lots of bugs and problems.

    Anyhow, I feel your pain. I really loathe working with Swing, and I will do pretty much anything to avoid it.


Leave a Reply