Tuesday, September 20, 2011

Openbox: Defining a Keyboard Shortcut

The Openbox Window Manager has quickly become my favorite way to use my computer. It use it almost exclusively on all the machines that I use (Ubuntu at work, Mint at home).

Here I'll describe how to add a keyboard shortcut so that we do not have to reach for the mouse to do something common. As I spend most of my time in the terminal, one shortcut I make the most use of is Alt+T to open a terminal program, mrxvt.

The keyboard shortcuts, along with many other things, are defined in ~/.config/openbox/rc.xml. The keyboard element is a child element of the root openbox element. Below is a snippet of an example showing the default shortcut for switching to the desktop to the left. The shortcut C-A-Left describes pressing the Ctrl, Alt, and left arrow keys with the default mappings:

<?xml version="1.0" encoding="UTF-8"?>
<openbox_config xmlns="http://openbox.org/3.4/rc">
<!-- some config omitted... -->
<keyboard>
<chainQuitKey>C-g</chainQuitKey>
<!-- Keybindings for desktop switching -->
<keybind key="C-A-Left">
<action name="DesktopLeft">
<dialog>no</dialog>
<wrap>no</wrap>
</action>
</keybind>
<!-- some keyboard config omitted... -->
</keyboard>
<!-- some config omitted... -->
</openbox>

To add our terminal shortcut, we add a keybind entry with the Execute action, followed by the command to execute. The key of A-t corresponding to pressing the Alt key along with the t key:

<?xml version="1.0" encoding="UTF-8"?>
<openbox_config xmlns="http://openbox.org/3.4/rc">
<!-- some config omitted... -->
<keyboard>
<chainQuitKey>C-g</chainQuitKey>
<!-- my keybindings -->
<keybind key="A-t">
<action name="Execute">
<execute>mrxvt</execute>
</action>
</keybind>
<!-- some keyboard config omitted... -->
</keyboard>
<!-- some config omitted... -->
</openbox>

We can reload the new configuration from the command line with:

  $ openbox --reconfigure

Or by right-clicking on the desktop and selecting Reconfigure from the Openbox menu.




Note: In order to take the screenshot with the menu shown, I ran gnome-screenshot with a delay of 5 seconds:

  $ gnome-screenshot -d 5

During the delay, you can right click on the desktop to get the menu in the picture.


No comments:

Post a Comment