Friday, September 6, 2013

Creating your own key-binds in Openbox

Introduction

I love being able to control any and every aspect of my computer by utilizing key-binds and macros to do certain tasks. This post is going to go over how to create key-binds in the Openbox desktop environment. Again as my last post I'll be running Crunch Bang as my distribution of choice which comes preconfigured with Openbox. Also because I don't like to steer too far away from the CLI; I will be calling the configs from the per this post.

The Configuration

As I discussed in my last tutorial, you can locate the config file by using the find command.

$ find ~/ -iname rc.xml
In this case we're going to edit the rc.xml file. Before we can edit that file we need to know which keys we're going to use as shortcuts along with the task that we want that key sequence to execute. So we're going to use a built in tool called 'xev' to find out what keys are called. For the sake of this post I'm going to use left shift and f1 to make a key-bind. So open a terminal and type xev and press enter, then push left shift and you should see an output like this:


KeyPress event, serial 46, synthetic NO, window 0x4000001,
    root 0x370, subw 0x0, time 326988347, (-740,188), root:(572,1005),
    state 0x11, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

Now lets push f1 and see what happens:

KeyPress event, serial 46, synthetic NO, window 0x4000001,
    root 0x370, subw 0x0, time 327135703, (-576,193), root:(736,1010),
    state 0x10, keycode 67 (keysym 0xffbe, F1), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

What information does this give us? First we have the X11 key name, and we also have the keycode which if we change to hex can be used in place of the X11 key name. So back to the rc.xml file. For simplicity reasons we'll just use the X11 key names, Shift_L and F1 respectively. In the xml file, we need to find the area where keybinds are defined. You should see comments that talks about keybinds like:


<!-- Keybindings for desktop switching -->
Now we need to create our own. You can create your keybinds anywhere in the keybind portion of the config file. Use the following format as an example:
<keybind key="">
     <action name="">
          <command>command goes here</command>
     </action>
</keybind>
Remember in this example we're using Shift_L and F1 for the keybind key, openbox has used modifiers for certain keys such as Shift which is an uppercase S and that's what we'll insert instead of Shift_L:
<keybind key="S-F1">
For the action name we want it to execute a command:
<action name="Execute">
And for the command we'll have it open Iceweasel:
<command>iceweasel</command>
Our keybind alltogether should look like this
<keybind key="S-F1">
     <action name="Execute">
          <command>iceweasel</command>
     </action>
</keybind>

Reload Openbox Configs

Now that the keybinds have been changed, whenever we use shift + f1 iceweasel opens up. These keybinds can be configured to do anything you want with endless combinations of keybinds and actions. Once you're happy with your current configuration, we need to have openbox reload the config files. In order to accomplish this, type the following into your terminal:
$ openbox --reconfigure

No comments:

Post a Comment