Openbox is a Window manager through which we can manage our program windows. Whenever a program is opened, a program box also gets opened with it. The box remains same for all the programs, which runs inside this box. With the help of a Window manager like Openbox we can close, minimize, resize & perform other related operations on our program windows. Furthermore, a desktop environment is not a prerequisite to installing a Window Manager. In this article, we would discuss key bindings in Openbox.
Configuration file in Openbox
Key bindings in Openbox could be created by editing the configuration file ~/.config/openbox/rc.xml. In case you don’t have one in the folder ~/.config/openbox/ then you need to copy it from /etc/xdg/openbox/rc.xml.
Thereafter, all the changes would be made in ~/.config/openbox/rc.xml config file.
In the rc.xml config file, look for <keyboard> section. Changes must be made within <keyboard> section, any changes outside of the section will be ineffective.
Now, before making any changes to our config file we will discuss how key-combinations are formed.
Key combinations for config file
Key combinations can be of the form Modifiers-Modifiers-Key, here modifiers are our shift key, control key, super key, alt key, hyper key and meta key. We can use the following keys to denote the modifiers –
It is worth mentioning here that, we don’t have to provide modifiers key with every key combination. In other words, we can choose to skip modifiers. Also, there are many keys on keyboard which will be difficult to identify. So, in such a scenario it is best to use the xev command. Run the following in terminal –
Thereafter, press the key which you would like to identify. For instance, tab key would get us the outcome –
KeyRelease event, serial 48, synthetic NO, window 0x3200001, root 0x10e, subw 0x0, time 23716338, (165,-9), root:(1264,337), state 0x10, keycode 23 (keysym 0xff09, Tab), same_screen YES, XLookupString gives 1 bytes: (09) " " XFilterEvent returns: False
In the third line of the output, we get both keycode as well as keyname. In this case, keycode is 23 and keyname is Tab. Now, either we can use keycode or keyname for the purpose of mentioning key combinations in our config file.
Keyname could be entered directly but, keycode need to be first converted to hexadecimal value. To convert the decimal value to hexadecimal, we need to run the following in terminal –
printf '0x%x\n' <decimal-value>
for instance, here the decimal value is 23.
printf '0x%x\n' 23
This will result in –
Now, let’s understand the whole idea of key combination with an example. If we want to bind Ctrl+Alt+T with lxterminal terminal emulator. Then, we can write the key combination as –
or, Use the xev command get the value of T.
KeyRelease event, serial 48, synthetic NO, window 0x3200001, root 0x10e, subw 0x0, time 29546219, (648,510), root:(650,1066), state 0x11, keycode 28 (keysym 0x54, T), same_screen YES, XLookupString gives 1 bytes: (54) "T" XFilterEvent returns: False
Then, convert the keycode of T (28) to hexadecimal value.
printf '0x%x\n' 28
We will get the hexadecimal value as-
So, we could write key combination as
Till now, we have understood how to form key combinations.
Edit entries in ~/.config/openbox/rc.xml config file
As already discussed, we can only make changes to <keyboard> section of our config file for the purpose of key bindings. Hence, following entries need to be added just before the </keyboard> end tag. You can add anywhere in-between just make sure not to add anything in between <keybind>…</keybind> already existing tags.
<keybind key="C-A-0x1c"> <action name="Execute"> <command>lxterminal</command> </action> </keybind>
The above lines of code executes (i.e. runs a program) which in this case is lxterminal whenever Ctrl+Alt+T key is pressed. Observe, we are taking hexadecimal value of our keycode for key T.
<keybind> – to bind the key
<action> – to run the program. There are other operations we can perform through <action> tag like SendToDesktop, Maximize, ToggleFullscreen etc. We will discuss all other actions in a separate article. Here, focus of our article is on how to execute a program through key bindings.
<command> – to execute the command
In conclusion, we have discussed how to bind a key in Openbox by editing the ~/.config/openbox/rc.xml configuration file.