Skip to Content

Roll your own Linux desktop using Openbox

Posted on

A window manager like Openbox handles the “drawing” of windows on a display, and typically run underneath heavier full-desktop X environments. However - given a few tweaks, add a few applications, and a fresh splash of “paint” (themes) - Openbox can run in standalone mode and makes an excellent foundation for a custom lightweight and delightful Linux desktop!

Let’s go!

I start with a bare display and pick and choose components to make a desktop just the way I like it. Some advantages of a self-assembled Openbox desktop:

  • lower memory requirements than heavyweights Gnome and KDE
  • runs quick on older hardware
  • easy to modify by editing text files
  • a greater appreciation of how an X environment works!

Setup is done on a Thinkpad T430s running Debian.

0. Install

Install Openbox and copy default config files to $HOME …

$ sudo apt install openbox obconf menu
$ mkdir -p ~/.config/openbox
$ cp /etc/xdg/openbox/* ~/.config/openbox/

My default mode is to login via console, then run startx to launch an X environment. Add openbox-session to ~/.xinitrc

exec openbox-session

Liftoff!

openbox-default

Ladies and gentleman, I present a screenshot of an out-of-box Openbox session. Grey never looked so good! 🐧

But let’s make some changes nonetheless …

1. Config: rc.xml

Most of the desktop configuration details for the user are set in ~/.config/openbox/rc.xml.

1.1 Desktops

At startup create four desktops …

<desktops>
    <number>4</number>
    <firstdesk>1</firstdesk>
    <names>
      <name>1</name>
      <name>2</name>
      <name>3</name>
      <name>4</name>
    </names>
    <popupTime>0</popupTime>
</desktops>

1.2 Keybindings

I create keybindings that perform a range of actions: switch desktops, move windows, launch menus, lock and suspend system …

Keybindings for desktop switching

Alt+1        goto desktop 1
Alt+2        goto desktop 2
Alt+3        goto desktop 3
Alt+4        goto desktop 4
Shift+Alt+d        toggle show desktop

<keyboard>
    <keybind key="A-1">
      <action name="GoToDesktop">
        <to>1</to>
      </action>
...
    <keybind key="S-A-d">
      <action name="ToggleShowDesktop"/>
    </keybind>

Keybindings for windows

Shift+Alt+1        send window to desktop 1
Shift+Alt+2        send window to desktop 2
Shift+Alt+3        send window to desktop 3
Shift+Alt+4        send window to desktop 4
Shift+Alt+Left        send window to monitor 1
Shift+Alt+Right        send window to monitor 2
Alt+F10        toggle decorations
Ctrl+Alt+q        close window

<keybind key="S-A-1">
    <action name="SendToDesktop">
        <to>1</to>
        <wrap>no</wrap>
    </action>
</keybind>
...
<keybind key="S-A-Left">
    <action name="MoveResizeTo">
        <monitor>2</monitor>
    </action>
</keybind>
<keybind key="S-A-Right">
    <action name="MoveResizeTo">
        <monitor>1</monitor>
    </action>
</keybind>
<keybind key="A-F10">
    <action name="ToggleDecorations"/>
</keybind>
<keybind key="C-A-q">
    <action name="Close"/>
</keybind>

Keybindings for window switching

Alt+Tab        switch between windows on current desktop
Shift+Alt+Tab        switch between windows on all desktops

<keybind key="A-Tab">
    <action name="NextWindow">
    <finalactions>
    <action name="Focus"/>
    <action name="Raise"/>
    <action name="Unshade"/>
    </finalactions>
    </action>
</keybind>
<keybind key="S-A-Tab">
    <action name="NextWindow">
        <allDesktops>yes</allDesktops>
    <finalactions>
    <action name="Focus"/>
    <action name="Raise"/>
    <action name="Unshade"/>
    </finalactions>
    </action>
</keybind>

Keybindings to launch applications

Alt+F2        run applications menu (rofi)
Shift+Alt+F2        root menu

<keybind key="A-F2">
    <action name="Execute">
        <command>rofi -monitor primary -show run</command>
    </action>
</keybind>
<keybind key="S-A-F2">
    <action name="ShowMenu">
        <menu>root-menu</menu>
    </action>
</keybind>

Keybindings for [l]ock screen, [s]uspend, [e]xit

Ctrl+Shift+l        lock screen
Ctrl+Shift+s        suspend
Ctrl+Shift+e        exit to console

<keybind key="C-A-l">
    <action name="Execute">
        <command>i3lock -c 000000 -i ~/.i3lock.png</command>
    </action>
</keybind>
<keybind key="C-A-s">
    <action name="Execute">
        <command>sh -c 'i3lock -c 000000 -i ~/.i3lock.png; sync; systemctl suspend'</command>
    </action>
</keybind>
<keybind key="C-A-e">
    <action name="Exit">
        <prompt>no</prompt>
    </action>
</keybind>
</keyboard>

1.3 Applications

Set default condition that matches all application windows and maximize + remove decorations when launched. Leave things like dialog windows or panels untouched …

<applications>
<application type="normal">
    <maximized>true</maximized><decor>no</decor>
</application>

… except for VLC media player …

<application class="vlc">
    <maximized>false</maximized><decor>yes</decor>
</application>

Links: Launching windows maximized; Finding parameters

2. Config: menu.xml

Openbox includes a system menu that appears on a right-click on the desktop. Modifications go in ~/.config/openbox/menu.xml.

Example: I add a screenshot sub-menu that calls on scrot to capture the image and mirage viewer to display it. First, install these programs …

$ sudo apt install scrot mirage

… then add some screenshot options to menu.xml

<menu id="scrot-menu" label="Screenshots">
<item label="Now">
    <action name="Execute"><execute>
    scrot -u -z '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/Downloads/ & mirage ~/Downloads/$f'
    </execute></action>
</item>
<item label="In 5 Seconds...">
    <action name="Execute"><execute>
    scrot -d 5 -u -z '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/Downloads/ & mirage ~/Downloads/$f'
    </execute></action>
</item>
<item label="Selected Area...">
    <action name="Execute"><execute>
    scrot -s '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/Downloads/ & mirage ~/Downloads/$f'
    </execute></action>
</item>
<item label="Desktop">
    <action name="Execute"><execute>
    scrot '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/Downloads/ & mirage ~/Downloads/$f'
    </execute></action>
</item>
</menu>

Result …

openbox-menu

2.1 Dynamic applications menu

For choosing and launching applications I don’t use the main menu or click on icons, but rely instead on the excellent rofi dynamic applications menu. Dynamic in the sense of using a hotkey combo (see above) to open the menu of all apps available, and as I type the menu narrows the list of matching apps. Most frequently-used apps rise to the top of the list for quick access.

Install …

$ sudo apt install rofi

Menu behaviour and appearance can be modified in ~/.Xresources.

rofi-menu

3. Config: environment

Set user-specific environment variables in ~/.config/openbox/environment. I don’t use it myself because most of the relevant settings are configured elsewhere. But if I wanted to configure something to be Openbox-specific this is probably a good place to do so.

4. Config: autostart + Applications

Actions to be done at startup are configured in ~/.config/openbox/autostart.

4.1 Background

I use hsetroot (plays nice with compton - see below) to set the background colour, and the feh image viewer to set a background image for the desktop. Install and set image …

$ sudo apt install hsetroot feh
$ feh --bg-scale /path/to/your/background/image.jpg

Once an image is chosen, feh stores its name in ~/.fehbg. Add entry to autostart to restore the background on next launch …

hsetroot -solid "#000000"
(sleep 1; ~/.fehbg) &

4.2 Laptop + external display

I created a shell script to detect when my laptop is connected to an external display, and make that secondary (larger) display register as PRIMARY display (windows default to opening on PRIMARY).

Add entry to autostart

~/bin/dldsply -r &

4.3 Compositor

Compositing provides windows with an off-screen buffer to minimize screen distortions and artifacts on the desktop. Openbox does not include a built-in compositing manager. Install compton to serve in that role …

$ sudo apt install compton compton-conf

Add entry to autostart

compton -b -c &

4.4 Keyboard

I created another shell script that detects a few different keyboards I use (laptop keyboards, USB keyboard) and loads the appropriate xbindkeys + xmodmap config files for hotkey combos and key remappings.

Install …

$ sudo apt install xbindkeys x11-xserver-utils

Add entry to autostart

(sleep 5; ~/bin/keyboardconf) &

4.5 Power management

Use xfce4-power-manager to handle AC and battery power events, screen brightness, suspend system, suspend-on-lid-closure for laptops, etc. Install …

$ sudo apt install xfce4-power-manager

Add entry to autostart

xfce4-power-manager &

4.6 Notifications

Dunst is a lightweight notification daemon for desktop events. Install …

$ sudo apt install dunst dbus-x11 libnotify-bin

… and configure the daemon in ~/.config/dunst/dunstrc and ~/.Xresources.

Add entry to autostart

dunst -config ~/.config/dunst/dunstrc &

4.7 Panel

I use tint2 as my desktop panel. Highly configurable with few dependencies. Provides items like a taskbar, system tray, battery indicator, and clock. Install …

$ sudo apt install tint2

Configuration is set in ~/.config/tint2/tint2rc. My own config was inspired by these colourful samples.

Add entry to autostart

tint2 &

4.8 Clipboard

Desktop clipboard clipit for multiple-entry copy-paste operations. Install …

$ sudo apt install clipit

Add entry to autostart

clipit &

4.9 Volume control

I use a combination of tools to control volume on my laptop:

  • volume keys are controlled by pactl (set in ~/.xbindkeysrc)
  • volumeicon-alsa places an icon in the system tray, and right-clicking that icon …
  • … launches the pavucontrol mixer for more detailed sound control

Install …

$ sudo apt install pulseaudio-utils volumeicon-alsa pavucontrol

Add entry to autostart

volumeicon &

Right-click on the volume icon, select Preferences, and change the external mixer to pavucontrol.

4.10 Network manager

Network-Manager is my choice to manage wired and wireless connections. Use nm-applet to place a network menu in the system tray. Install …

$ sudo apt install network-manager network-manager-gnome

An autostart desktop file in /etc/xdg/autostart/nm-applet.desktop launches nm-applet whenever an Openbox session begins.

Comment out and disable entries in /etc/network/interfaces for any network devices to be managed instead by network-manager

# The primary network interface
#allow-hotplug enp0s25
#iface enp0s25 inet dhcp

Restart network-manager

$ sudo systemctl restart network-manager

5. Lock screen

I use i3lock launched from a hotkey combo (see above) to lock my screen, or to work in concert with systemctl to lock screen when suspend is activated. Install …

$ sudo apt install i3lock

Set a custom lockscreen image in ~/.i3lock.png.

6. Themes

Style the desktop with a combination of themes, colours, icons, and fonts.

6.1 GTK2+3

I like the Arc-theme

$ sudo apt install arc-theme 

6.2 Openbox

There is an Arc-friendly theme for Openbox. Install in ~/.themes (using git) …

$ mkdir ~/.themes; cd ~/.themes
$ git clone https://github.com/dglava/arc-openbox.git

6.3 QT

Use qt5-style-plugins to style QT apps with the chosen GTK theme. Install …

$ sudo apt install qt5-style-plugins

Add entry to ~/.profile

export QT_QPA_PLATFORMTHEME=gtk2

6.4 Icons

I like the Papirus icon set. Install in ~/.icons

$ mkdir ~/.icons
$ wget -qO- https://raw.githubusercontent.com/PapirusDevelopmentTeam/papirus-icon-theme/master/install.sh | DESTDIR="$HOME/.icons" sh

6.5 Fonts

Install a few extra fonts (including the nice Ubuntu fonts) …

$ sudo apt install fonts-liberation fonts-noto-mono
$ wget -c http://ftp.us.debian.org/debian/pool/non-free/f/fonts-ubuntu/fonts-ubuntu_0.83-4_all.deb
$ sudo dpkg -i fonts-ubuntu_0.83-4_all.deb

6.6 Configure utility

Use the lxappearance graphical config utility (with the extra openbox plugin) to setup your new theme. Details are stored in ~/.gtkrc-2.0.

Install …

$ sudo apt install lxappearance lxappearance-obconf

7. My custom desktop

From grey screen to the good stuff …

openbox-custom

Happy hacking!