Roll your own Linux desktop using Openbox

Last edited on 2023-08-31 Tagged under  #openbox   #debian   #linux 

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:

  • pick and mix your own desktop components
  • lower memory requirements, runs quick on older hardware
  • easy to modify by editing text files
  • greater appreciation of how an X environment works

Setup is done on a laptop running Debian.

1. Install

1.1 Xorg

Install ...

$ sudo apt install xorg xbacklight xbindkeys xvkbd xinit xinput xserver-xorg-input-all xterm

1.2 Openbox

Install the window manager and some desktop extras ...

$ sudo apt install openbox obconf dunst dbus-x11 feh hsetroot i3lock libnotify-bin libxcb-xinerama0 lxappearance lximage-qt menu picom rofi scrot tint2 volumeicon-alsa xfce4-power-manager xfce4-terminal
$ sudo apt install alsa-utils firefox-esr fonts-dejavu fonts-firacode fonts-font-awesome fonts-liberation2 fonts-ubuntu gtk2-engines-murrine gtk2-engines-pixbuf network-manager network-manager-gnome papirus-icon-theme pavucontrol pipewire-audio qt5-style-plugins

Copy Openbox's default config files to $HOME ...

$ mkdir -p ~/.config/openbox
$ cp /etc/xdg/openbox/* ~/.config/openbox/

Enable wireplumber.service (running as user, not as root) ...

$ systemctl --user --now enable wireplumber.service

I run startx from the console to launch an X environment. Add exec openbox-session to ~/.xinitrc, run startx, and behold ...

openbox-default

Hmm ... Let's do something with this blank canvas!

Source: .xinitrc

2. rc.xml

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

Source: rc.xml

Desktops

Openbox creates four desktops at launch ...

<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>

Keybindings

I create hotkey keybindings that perform a range of actions: switch desktops, move windows, launch menus, lock/suspend/exit the system.

Decorations

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>

See: Launching windows maximized, and Finding parameters for applications

Lock screen

I use i3lock launched from a keybinding (windows key + l) to lock my screen, or to work in concert with systemctl to lock screen when suspend (windows key + s) is activated. Set a custom lockscreen image in ~/.i3lock.png ...

    <!-- Keybindings for [l]ock screen, [s]uspend, [e]xit -->
    <keybind key="W-l">
      <action name="Execute">
        <command>i3lock -c 000000 -i ~/.i3lock.png</command>
      </action>
    </keybind>
    <keybind key="W-s">
      <action name="Execute">
        <command>sh -c 'i3lock -c 000000 -i ~/.i3lock.png; sync; systemctl suspend'</command>
      </action>
    </keybind>

3. 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 lximage-qt to display it. Add some screenshot options to menu.xml ...

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

Result ...

openbox-menu

Source: menu.xml

4. 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 a good place to do so.

5. Autostart

Actions and applications to be launched when starting Openbox are configured in ~/.config/openbox/autostart.

Source: autostart

6. Application launcher: rofi

For choosing and launching applications I use rofi, a dynamic applications menu utility. I set a keybinding in rc.xml (windows key + spacebar) that launches an applications menubar across the top of the display and, as I type the name of the application, the menu zooms in on matching names. Most frequently-used applications rise to the beginning of the list for quick access.

Menu behaviour and appearance can be modified in ~/.config/rofi.

Source: rofi

7. Desktop background: hsetroot, feh

I use hsetroot to set the background colour, and the feh image viewer to set a background image for the desktop ...

$ 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) &

8. Multi-monitors: dual_display

I created a script to detect when my laptop is connected to an external display, position external above laptop, and set external as PRIMARY display (windows default to opening on PRIMARY).

Add entry to autostart ...

~/bin/dual_display --above &

Source: dual_display

9. Power management: xfce4-power-manager

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

Add entry to autostart ...

xfce4-power-manager &

10. Notifications: dunst

Use dunst - a lightweight notification daemon - for desktop events. Configure the daemon in ~/.config/dunst/dunstrc.

Add entry to autostart ...

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

Source: dunstrc

11. Desktop panel: tint2

Use tint2 as the desktop panel. Highly configurable with few dependencies. Provides items like a taskbar, system tray, battery indicator, and clock. Configure in ~/.config/tint2/tint2rc.

Add entry to autostart ...

tint2 &

Source: tint2rc

12. Clipboard: rofi-greenclip

A simple clipboard manager integrated with rofi.

It's a static binary, so drop it anywhere in your $PATH ...

wget https://github.com/erebe/greenclip/releases/download/v4.2/greenclip

Start ...

$ greenclip daemon

Configuration is set in ~/.config/greenclip.toml. Merge the X Primary selection with the clipboard selection by setting use_primary_selection_as_input = true in this file. See Clipboard for more details about Primary and Clipboard.

To access clipboard history, run ...

$ rofi -modi "clipboard:greenclip print" -show clipboard -run-command '{cmd}'

Set a keyboard shortcut for above in Openbox's rc.xml.

Add entry to Openbox's autostart ...

greenclip daemon &

Source: greenclip.toml

13. Volume control: volumeicon, pavucontrol

Application volumeicon places a control utility in the system tray. Right-click on the icon, select Preferences, and change the external mixer to pavucontrol.

Add entry to autostart ...

(sleep 5; volumeicon) &

14. Network manager: nm-applet

Use network-manager to manage wired and wireless connections, and nm-applet to place a network menu in the system tray.

Add entry to autostart ...

nm-applet &

15. Terminal: xfce4-terminal

Use xfce4-terminal as the terminal with Fira Code fonts.

16. Theme: Nord

Style the different elements of the desktop with a combination of themes, colours, icons, and fonts. I like the Nord colour palette.

GTK

Create ~/.themes ...

$ mkdir ~/.themes

Download the Nordic theme, and copy theme to ~/.themes/Nordic. Select theme using the lxappearance utility. Pairs nicely with the Papirus Dark icon set.

Openbox

Download the Nordic Openbox theme, and copy theme to ~/.themes/Nordic-Openbox. Select theme using the obconf utility.

QT

Use qt5-styleplugins to style QT apps with the chosen GTK theme.

Add entry to ~/.profile ...

export QT_QPA_PLATFORMTHEME=gtk2

Source: .profile

Terminal

Create themes directory for terminal ...

$ mkdir -p ~/.local/share/xfce4/terminal/colorschemes

Download the Nord Xfce Terminal theme, copy nord.theme to colorschemes, open terminal's Edit->Preferences->Colors and select Load Presets->Nord.

17. Finish

From grey screen to the good stuff!

Openbox custom

Thanks for reading! Read other posts?

» Next: Where is the Earth?

« Previous: Chromebook to Bookwormbook