03 May 2016

Make 'Open class' dialogue of IntelliJ IDEA behave under Awesome WM

There is a quite well known [in narrow circles]  problem in IntelliJ IDEA (as well as other Jetbrains products) with 'Open class'\'Open file' dialogues (AKA Ctrl+N\Ctrl+Shift+N): in some environments the dialogue tend to often disappear\close as you type. For other environments this problem just never happens.

Recently it was demystified for me with the help of Jetbrains developers and support and the community. There appeared to be a long-hanging issue regarding this weird behaviour IDEA-65043. And once it gained some more attention at least exact conditions triggering the issue were discovered.

The problem was caused by sloppy focus (AKA focus-follows-mouse) which is the default in some environments among which Awesome WM is. Now it can easily be solved!

I'm using default configuration of Awesome WM 3.5.9 as a base (which can be found in /etc/xdg/awesome/rc.lua).

Somewhere in the bottom there is a snippet we're looking for

-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c) then
            client.focus = c
        end
    end)
This is the sloppy focus implementation. Need to introduce a flag to switch it on\off. Change it to:
-- {{{ Signals
-- Signal function to execute when a new client appears.
sloppyFocus = true
client.connect_signal("manage", function (c, startup)
    -- Enable sloppy focus
    c:connect_signal("mouse::enter", function(c)
        if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
            and awful.client.focus.filter(c)
            and sloppyFocus then
            client.focus = c 
        end 
    end)

Now we have a switch, and we need to turn it off while we're working with IDEA (or WebStorm, etc) and the turn back on when we're off it. Find awfule.rules section in your config (for me it's right above the sloppy focus implementation snippet) and add a new rule:

{ rule = { class = "jetbrains-%w+" },
      callback = function(c)
          c:connect_signal("focus", function (client)
              sloppyFocus = false
          end)
          c:connect_signal("unfocus", function (client)
              sloppyFocus = true
          end)
      end
    },
This matches any window of virtually any Jetbrains' product and switches sloppy focus off while it's focused, then switches sloppy back on when focus leaves IDE.

Thanks awesome Awesome developers for allowing patterns in rule preconditions! :-)

No comments: