Openbox: disable Alt-F4 on per application basis

lxdeopenbox

I am using LXDE and in my .config/openbox/lxde-rc.xml I have action for ALT-F4 defined:

<keybind key="A-F4">
  <action name="Close"/>
</keybind>

This works, as expected, for all applications. When ALT-F4 is pressed, the window is closed.

I have one application, lets call it foo, which I would like to be unaffected by ALT-F4. i.e. when ALT-F4 is pressed, I want the window to stay open (the action should be completely ignored).

Is it possible to create such rule?

EDIT:
Based on the answer from @Michael Homer I have added following into my .config/openbox/lxde-rc.xml:

<keybind key="A-F4">
  <action name="If">
    <title>foo</title>
    <then>
      <!-- Do nothing for foo -->
    </then>
    <else>
      <action name="Close"/>
    </else>
  </action>
</keybind>

This works great, but I would need to match foo or bar.

What would be the simplest solution to achieve that?

Best Answer

It is possible with an If action:

<keybind key="A-F4">
 <action name="If">
  <title>* foo</title>
  <then><!-- Do nothing for foo --></then>
  <else>
   <action name="Close" />
  </else>
 </action>
</keybind>

The <title> condition will match a window title ending " foo". There are variations <title type="regex"> and <title type="exact"> for other kinds of match. When the window matches, the action will do nothing, and when it doesn't (for every other window) it will close as usual.

Openbox 3.6 and newer include additional selector tags <class>, <name>, and <role> which can help to identify your window more precisely if the title isn't unique. They support the same type attribute and content as <title>, but are tested against the relevant X property instead.


If you're using an earlier version of Openbox and your window can't be identified by title, you're in less luck, but it's possible to hack something together with xdotool: bind the A-F4 action to a script that identifies the window more precisely, and then send a secret key combination that's bound to the actual close action if it doesn't match.

Related Question