XMonad and IntelliJ

This post describes how to resolve two common issues with running IntelliJ IDEA in the xmonad window manager. You’ll make minor changes to xmonad’s configuration and will need to run IntelliJ on the JRE packaged with Oracle’s JDK 6.

Software Configuration

This solution was tested with the following software:

Problems with Default Configuration

The default IntelliJ and xmonad configurations on Arch Linux (and presumeably other Linux distributions) cause two problems that make IntelliJ unuseable:

  1. The IntelliJ window is displayed as an empty grey box, and when this issue is resolved
  2. Text boxes do not recieve the cursor focus so you cannot fill in any text box.

Configuring Xmonad

This minimal xmonad configuration will resolve issue with xmonad only painting IntelliJ as a grey box and part of the focus issue.

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ICCMFocus
import XMonad.Hooks.SetWMName

main = do
  xmonad =<< xmobar defaultConfig
            { modMask = mod4Mask
        , startupHook = setWMName "LG3D"
        , logHook = takeTopFocus
	}

Setting the Window Manager Name

Java has a hardcoded list of window manager configurations and XMonad isn’t one of them. The solution, as described in the xmonad FAQ, is to lie to Java about what window manager is in use. Add the import statement import XMonad.Hooks.SetWMName to top of your xmonad.hs and the line

startupHook = setWMName "LG3D"

to the xmonad configuration section. Recompile the configuration file, restart xmonad and start IntelliJ. You should see IntelliJ paint correctly.

The FAQ’s recommended solution to the grey-box issue is to use the OpenJDK and the _JAVA_AWT_WM_NONREPARENTING environment variable. I did not test this solution because IntelliJ recommends against using the OpenJDK for performance reasons. I did not test this environment variable with Oracle’s JDK.

Partially Fixing the Focus Issue

Solving the focus issue begins with making more changes to the xmonad configuration. Add import XMonad.Hooks.ICCMFocus to the top of your xmonad.hs and

logHook = takeTopFocus

to the xmonad configuration section. The xmonad configuration should recompile correctly, but the focus issue will not be resolved without changes to the JDK that IntelliJ runs under.

Use JDK 6

Once you’ve configured xmonad you’ll need to install Oracle’s JDK 6. I already have Oracle’s JDK 7 installed as my primary JDK and didn’t want to change that so I manually installed JDK 6 to /opt/java6. Making IntelliJ run under a custom JDK is as simple as setting the IDEA_JDK environment variable in your .bashrc. This line should work assuming you’ve installed the JDK 6 to /opt/java6.

export IDEA_JDK=/opt/java6

I am not sure why this works with JDK 6 and not JDK 7.

Alternatives to xmonad

Right now I prefer xmonad, but it does take an investment to understand it and get your software to work well in some cases. IntelliJ runs without any headache under xfce4 with JDK 7 (and JDK 6).


© 2012