Openbox: change keybind action depending on active window
The situation under Xorg: I have an application with keybinds that cannot be changed, namely Signal for Linux desktop. One of these keybinds has been my probably most used keybind for a long time, namely Shift-Return to open an application launcher.
Solution: Openbox allows me to execute different actions depending on which window is focused via the If action.
Find out where your Openbox config is (usually
$XDG_CONFIG_HOME/openbox/rc.xml, but this differs slightly for e.g. LXDE users)
and locate the
<keybind> that you want to modify. In my case, it looks like this after the modification:
<keybind key="S-Return"> <action name="If"> <query target="focus"> <class type="exact">Signal</class> </query> <then> <action name="Execute"><command>xdotool type " "</command></action> </then> <else> <action name="Execute"><command>~/bin/dmenu_run_hist</command> </action> </else> </action> </keybind>
- If the window with the exact class name "Signal" is focused, type Return (Shift is not required since the user invoking this keybind is still holding it down).
Xdotool does not always play perfectly with all applications; I tried
key Returnwith and without Shift but it didn't work, so I resorted to making it type out a newline.
- Otherwise, open the app launcher
Simple enough despite the obnoxious XML syntax.
One niggle remains: I see no way to let the key combination pass through if the "If" query returns False - neither implicitly (Openbox "eats" the event) nor explicitly with xdotool.
xdotool key does not work (as expected) on all windows/applications.