Openbox - Customize your Right Click Menu

by Paul Arnote (parnote)

Unless you are running the LXDE Panel (lxpanel) on your copy of Openbox (or even if you are running lxpanel), the “traditional” way of accessing the applications menu in Openbox is by right clicking on an empty spot of your Openbox desktop. Fortunately, it’s quite easy to tweak and tune your Openbox right click menu.

The information for the Openbox right click menu is stored in the menu.xml file, located in your /home/username/.config folder. For a brief description of the XML file format, take a look at the PCLinuxOS Magazine Openbox article on editing your rc.xml file. Use the PCLinuxOS Openbox default text editor Geany to edit any of your Openbox configuration files.

Below is a copy of the menu.xml file from my installation of Openbox:

<?xml version="1.0" encoding="UTF-8"?>

<openbox_menu xmlns="http://openbox.org/3.4/menu">

        <menu id="desktop-app" label="Applications" execute="openbox-menu -x -t 'sakura -e'" />

        

        <menu id="openbox-menu" label="OpenBox">

                  <item label="ObConf">

                          <action name="Execute"><command>obconf</command></action>

                  </item>

                  <item label="Reload Openbox">

                    <action name="Reconfigure" />

                  </item>

        </menu>

        <menu id="preferences" label="Preferences">

                  <item label="Desktop Prefs">

                          <action name="Execute"><command>pcmanfm --desktop-pref</command></action>

                  </item>

                                          <item label="No effects">

                                <action name="Execute">

                                        <execute>

                                                ~/.config/openbox/scripts/xcompmgr.sh unset

                                        </execute>

                                </action>

                        </item>

                        <item label="Transparency">

                                <action name="Execute">

                                        <execute>

                                                ~/.config/openbox/scripts/xcompmgr.sh set

                                        </execute>

                                </action>

                        </item>

                        <item label="Transparency, fadings">

                                <action name="Execute">

                                        <execute>

                                                ~/.config/openbox/scripts/xcompmgr.sh setshaded

                                        </execute>

                                </action>

                        </item>

                        <item label="Transparency, fadings, shadows">

                                <action name="Execute">

                                        <execute>

                                                ~/.config/openbox/scripts/xcompmgr.sh setshadowshade

                                        </execute>

                                </action>

                        </item>

        </menu>

        <menu id="root-menu" label="Openbox 3">

                  <separator label="Menu" />

                <menu id="desktop-app" />

                  <separator />

                  <item label="Firefox">

                          <action name="Execute"><command>firefox</command></action>

                  </item>

                  <item label="File manager">

                          <action name="Execute"><command>pcmanfm</command></action>

                  </item>

                  <item label="Terminal"><action name="Execute">

                          <command>gnome-terminal</command></action>

                  </item>

                <item label="Run Program..."><action name="Execute">

                        <command>gnome-run-dialog</command></action>

                  </item>

                  <separator />

                  <menu id="client-list-menu" />

                  <menu id="openbox-menu" />

                <menu id="preferences" />

                  <separator />

                  <!--<item label="Exit">

                        <action name="Exit" />

                </item>-->

             <item label="Log Out">

                        <action name="SessionLogout">

                                <prompt>yes</prompt>

                        </action>

             </item>

                <item label="Reboot">

                        <action name="Execute">

                                <execute>dbus-send --system --dest=org.freedesktop.Hal --print-reply /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot</execute>

                        </action>

                  </item>          

            <item label="Shutdown">

                        <action name="Execute">

                                <execute>dbus-send --system --dest=org.freedesktop.Hal --print-reply /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown</execute>

                        </action>

                  </item>        

                  <separator />

                <item label="Suspend">

                        <action name="Execute">

                                <execute>dbus-send --system --dest=org.freedesktop.Hal --print-reply /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0</execute>

                                </action>

                </item>

        </menu>

</openbox_menu>

Below is a the basic menu that appears when I right click on my Openbox desktop:


When I hover my mouse over the “Applications” menu, the menu expands, as shown in the screenshot below:


You most likely won’t want to mess much with the “Applications” entry of your installation. This portion of the menu is controlled more by the xdg menu entries, and you can cause chaos to reign by messing around here. The real beauty of the menu.xml file is the ability to customize the rest of your Openbox menu. My menu, depicted above, has been tweaked and customized by me.

After the first separator in the menu, you have a “quick launch” area. You can define applications that you may want quick and ready access to in this area. The changes I made here was to call Gnome Terminal, instead of Sakura, which is the default terminal application in the PCLinuxOS Openbox release. Since Gnome Terminal was pre-installed on my Openbox installation, it was a simple matter of changing the line in menu.xml that executes “sakura” to “gnome-terminal.”

I further expanded the “quick launch” area of my Openbox menu by adding in the “Run Program...” entry. Openbox, as it’s installed from the Live CD, doesn’t have any way of accessing a “Run Program...” dialog box. So, I installed “gnome-run-dialog” from Synaptic, a Python/Gtk+ application that provides you a “Run Program...” dialog box.

Adding it to the “quick launch” section of my Openbox menu was as easy as adding these three lines to my menu.xml file:

<item label="Run Program..."><action name="Execute">

        <command>gnome-run-dialog</command></action>

</item>

To increase the usefulness of the “Run Program...” entry, I also subsequently added a keybinding to launch “gnome-run-dialog” from the keyboard, with the press of the Alt + F2 key combination, to my rc.xml file.

Getting “fancy”

You can just as easily create top level menus populated with sub-menu items. Because of various issues, I tend to switch between the use of Firefox and Chromium browsers for different tasks that I routinely perform on my computers. For example, I prefer to use Chromium for working in Google Docs (the vehicle preferred for magazine article submission). Despite its larger size, Chromium experiences fewer “freezes” than Firefox, which is a problem I’ve experienced with Firefox ever since version 3.2. However, I prefer to use Firefox for the bulk of my web browsing.

As such, I prefer to have both Chromium and Firefox listed in the “quick launch” area of the Openbox right click menu. To keep things neat and tidy (and to prevent the “quick launch” area from becoming too long and unweildly), I prefer to have a top level menu that, when selected, allows me to choose between Firefox and Chromium. It’s easier than you might think. Here’s the new “snippet” from my altered menu.xml file, inserted right after the line that reads <menu id="desktop-app" />:

<menu id="browsers" label="Browsers">

        <item label="Firefox">

    <action name="Execute"><command>firefox</command></action>

        </item>

          <item label="Chromium">

    <action name="Execute"><command>chromium-browser</command></action>

        </item>

</menu>

To start with, you define a new “top level” menu with the <menu …> tag. Be sure to give it a unique menu ID. Here, I called mine “browsers,” which I knew was not already in use. What appears after “label=” is the text that appears in the menu.

Next, add the menu items that you want to populate that top level menu, as I have done with the “item” entries for Firefox and Chromium. Finally, close out the top level menu with the </menu> tag.

If you want to get even fancier – and more complex – you can further define sub menus for top level menus, with each sub menu containing additional sub menus and menu items. How fancy and just how complex you want to make your menu additions is entirely up to you. However, I subscribe to the K.I.S.S. principle (Keep It Super Simple), and this is as complex as I want to get.

Summary

You will find that editing your Openbox menu.xml file will add extra functionality to your Openbox installation. Editing, changing and expanding your Openbox menu is very easy to do, and gives you the opportunity to further customize Openbox to work in a manner that more closely matches the way that you work with your computer.