Roll your own FreeBSD Desktop Using Openbox
Part of the "Exploring FreeBSD on a Laptop" series.
Tested on FreeBSD 14.2
A window manager such as Openbox handles the "drawing" of windows on a display, and they typically run underneath heavier, preconfigured desktop environments.
But Openbox can be run in of itself sans desktop and that is my preferred way to use it. This stalwart window manager is an excellent foundation for crafting a lightweight and delightful FreeBSD desktop just the way I like it!
NOTE
Most of the details below are equally applicable to setting up Openbox on Linux. Only the FreeBSD-specific configuration details, the pkg(8) package manager, and perhaps some of the package names will differ.
Installation
X11
FreeBSD does not include a graphical user interface in its base system. This is how I install and set up the X Window System (X11) before installing Openbox.
Openbox
Install the window manager:
# pkg install openbox
These are the desktop extras I use:
# pkg install adwaita-icon-theme adwaita-qt5 adwaita-qt6 clipit \
dmenu dunst feh fira firacode firefox gnome-icon-theme \
gnome-themes-extra lxappearance-obconf noto-emoji obconf \
papirus-icon-theme py311-xdg qt5ct qt6ct roxterm rofi scrot \
ubuntu-font viewnior xlockmore
Configuration
Groups
User (example: foo
) needs to be a member of the wheel
, operator
, and network
groups:
# pw groupmod wheel -m foo
# pw groupmod operator -m foo
# pw groupmod network -m foo
D-Bus
Enable the dbus
service to start at FreeBSD system boot:
# sysrc dbus_enable="YES"
Openbox
I use xinit(1) to launch any X environment. Open .xinitrc
for editing:
$ vi ~/.xinitrc
Comment out any existing lines that start with exec [x environment]
, then add:
exec dbus-launch --sh-syntax --exit-with-session openbox-session
Save changes and exit.
Run startx(1) to launch Openbox:
$ startx
Behold in all its glory!
Now let's make some modifications to this glorious blank canvas. 😺
Copy the default configuration files to the user's home directory:
$ cp -av /usr/local/etc/xdg/openbox ~/
The bulk of the configuration is contained in two files: rc.xml
and menu.xml
.
rc.xml
DESKTOPS: I create 4 desktops for my work environment.
KEYBOARD SHORTCUTS: These are custom key combinations that perform a range of actions: switch desktops and windows, move windows between desktops, tile windows, toggle window maximization and decorations, display menus, exit Openbox, reboot/shutdown system.
APPLICATION SETTINGS: Configure certain applications and types of windows to behave a certain way: open on certain desktops, always launch maximized, toggle window decorations, etc.
NOTE
To find the class
and name
parameters for the entries, see: Application parameters
menu.xml
Openbox includes a system menu that appears upon a right-click on an empty desktop area or by a keyboard shortcut set in rc.xml
.
autostart
Actions and applications to be launched when starting Openbox are included in this file. I don't use it myself, adding these entries instead to my .xinitrc
. But if I wanted to configure something Openbox-specific this would be the file to use.
environment
Set user-specific environment variables. I don't use this file either. All these settings are configured elsewhere in the system.
Applications
These are the applications I like to use to craft my personal desktop experience.
Application launcher: rofi
To search for and run applications I use rofi(1), a dynamic menu utility.
I set a keyboard shortcut Super + Enter
that opens a horizontal menubar across the top of the display and, as I type the name of the application, the menu zooms in on matching names. The most frequently-used applications move to the beginning of the list for quick access.
Menu behaviour and appearance can be modified by creating the ~/.config/rofi/config.rasi
file.
Desktop background: feh
Image viewer feh(1) is used to display a background image:
$ feh --bg-scale /path/to/your/background/image.jpg
Once an image is set, feh
stores the details in ~/.fehbg
. Add an entry to .xinitrc
to restore the background on next launch:
sleep 1; $HOME/.fehbg &
NOTE
Add sleep 1;
to avoid Openbox overwriting the image at launch with a solid colour background.
Desktop panel: none
Openbox does not have a built-in desktop panel, and currently I haven't felt the need to add one.
Openbox does include a window/desktop menu, which I set to display with the keyboard shortcut Super + Shift + Spacebar
. My terminal prompt displays the time. Everything else I might need is controlled by keyboard shortcuts or terminal commands.
In the past, when I did use a desktop panel with Openbox, I was happy with tint2(1).
Brightness control: backlight
Use backlight(8) to control display luminosity. I've set keyboard shortcuts Super + F6
and Super + F5
to increase and decrease the backlight respectively.
See Brightness for more details.
Clipboard manager: clipit
I use clipit(1) to synchronize the system clipboards and maintain a history of past copy operations.
Add to .xinitrc
:
clipit -n &
After starting Openbox, open the Actions
menu with the keyboard shortcut Ctrl + Alt + A
and select Edit actions
to access Preferences
. In Settings
I enable Synchronize clipboards
and in Hotkeys
I set keyboard shortcuts Super + C
to access the Actions
menu and Super + H
to manage clipboard history.
Network manager: none
Network management on FreeBSD is straightforward and I haven't (yet) felt the need for installing a network management utility. For more details about my ethernet and wireless set up, see Networking on a FreeBSD Laptop.
Notifications: dunst
A nice lightweight notification daemon for desktop events is dunst(1).
Copy the default configuration to your home directory:
$ cp -av /usr/local/etc/dunst ~/.config/
To configure ~/.config/dunst/dunstrc
see dunst(5) for options.
Add entry to .xinitrc
:
dunst -config $HOME/.config/dunst/dunstrc &
Terminal: roxterm
A terminal emulator similar to gnome-terminal
that I like is roxterm(1). It include a few nice things like tabs and my preferred Nord colour palette, and I use Fira Code for my terminal font.
Upon startx
I automatically launch the terminal in a maximized window with no decorations. To do so, first add to rc.xml
:
<!-- APPLICATION SETTINGS -->
<applications>
<application name="roxterm">
<maximized>true</maximized>
<decor>no</decor>
</application>
(... other application settings go here ...)
</applications>
Then add to .xinitrc
:
roxterm &
Volume control: mixer
The mixer(8) command is used to control volume up/down/mute, which I've set to keyboard shortcuts Super + F3
, Super + F2
, and Super + F1
respectively.
See Sound for more details.
Screenshots: scrot, viewnior
Screenshots are captured using scrot(1) and the resulting image is displayed using viewnior(1).
In menu.xml
I created a custom Screenshots
submenu to capture various types of screenshot, save the captured image to ~/image/screenshot
, and display the image:
<menu id="scrot-menu" label="Screenshots">
<item label="Window">
<action name="Execute">
<command>scrot -u '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/image/screenshot & viewnior ~/image/screenshot/$f'</command>
</action>
</item>
<item label="Window in 5 seconds...">
<action name="Execute">
<command>scrot -d 5 -u '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/image/screenshot & viewnior ~/image/screenshot/$f'</command>
</action>
</item>
<item label="Selected area...">
<action name="Execute">
<command>scrot -s '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/image/screenshot & viewnior ~/image/screenshot/$f'</command>
</action>
</item>
<item label="Desktop">
<action name="Execute">
<command>scrot '%Y-%m-%dT%H%M%S.png' -e 'mv $f ~/image/screenshot & viewnior ~/image/screenshot/$f'</command>
</action>
</item>
</menu>
Screen lock: xlock
I created a script that uses xlock
to lock the screen, which I've set to use keyboard shortcut Super + Shift + L
to activate.
Suspend/Resume: acpiconf
Determine which type of sleep states our hardware supports:
$ sysctl hw.acpi.supported_sleep_state
hw.acpi.supported_sleep_state: S3 S4 S5
Command acpiconf(8) can be used to check if the S3 state works correctly. Run this command with these options, and if its successful the machine will suspend:
# acpiconf -s 3
In the vast majority of cases the suspend/resume capability is something that is desirable for a laptop.
I created a script that activates xlock
to first lock the screen, then acpiconf
to put the machine to sleep. I set a keyboard shortcut Super + Shift + Z
to execute the script.
NOTE
I don't use the "suspend on lid closure" feature on my laptop. I'm paranoid about failing to notice that the device might have failed to properly suspend and it subsequently overheats in my bag. Regardless, opening the lid will wake up the (locked) machine.
See: Suspend/Resume in the FreeBSD Handbook.
Appearance
While "pleasing to the eye" is relative, the objective is to get a relatively uniform look across the span of Openbox and the GTK and QT frameworks. I prefer a darker theme and I'm happy with the combination of fonts, icons, and colours outlined below.
Fonts
I use the Ubuntu Mono font for the Openbox menus, Fira Sans font for the Openbox window bar titles, and Ubuntu Regular for GTK and QT applications.
Verify that these fonts are recognized and available for use by using fc-match(1):
$ fc-match "Ubuntu Mono"
UbuntuMono-R.ttf: "Ubuntu Mono" "Regular"
$ fc-match "Fira Sans"
FiraSans-Regular.otf: "Fira Sans" "Regular"
$ fc-match "Ubuntu"
Ubuntu-R.ttf: "Ubuntu" "Regular"
Openbox
Create:
$ mkdir ~/.themes
Download the Nordic Openbox theme, and copy theme to ~/.themes/Nordic-Openbox
.
NOTE
I modified the Nordic-Openbox themerc
file to change the titlebar backgrounds to #000000
.
GTK
NOTE
Adwaita-dark
for GTK is in the gnome-themes-extra
package.
Launch the lxappearance
theme editor. Set the GTK Widget
theme to Adwaita-dark
, Icon Theme
to Papirus-Dark
, and Window Border
to Nordic Openbox
. Click Apply
then Close
.
NOTE
I manually changed gtk-font-name
to Ubuntu 14
in the settings files.
Display settings for GTK2:
$ cat ~/.gtkrc-2.0
# DO NOT EDIT! This file will be overwritten by LXAppearance.
# Any customization should be done in ~/.gtkrc-2.0.mine instead.
include "/home/dwa/.gtkrc-2.0.mine"
gtk-theme-name="Adwaita-dark"
gtk-icon-theme-name="Papirus-Dark"
gtk-font-name="Ubuntu 14"
gtk-cursor-theme-name="Adwaita"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle="hintfull"
Display settings for GTK3:
$ cat ~/.config/gtk-3.0/settings.ini
[Settings]
gtk-theme-name=Adwaita-dark
gtk-icon-theme-name=Papirus-Dark
gtk-font-name=Ubuntu 14
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
gtk-menu-images=1
gtk-enable-event-sounds=1
gtk-enable-input-feedback-sounds=1
gtk-xft-antialias=1
gtk-xft-hinting=1
gtk-xft-hintstyle=hintfull
gtk-cursor-theme-name=Adwaita
QT
Edit .profile
:
$ vi ~/.profile
Add:
# Activate qt5ct settings for desktop theme
export QT_QPA_PLATFORMTHEME=qt5ct
Save changes and exit.
Launch the qt5ct
theme editor and under Appearance
select Style: Adwaita-Dark
, under Fonts
select Ubuntu 14
, and under Icon Theme
select Papirus-Dark
. Click Apply
then OK
.
Launch the qt6ct
theme editor and duplicate the selections chosen in qt5ct
.
Log out and back in to see the modifications.
Finish
From grey screen to good looking!
Exit/Reboot/Shutdown
Requisite commands are placed in menu.xml
:
<item label="Exit">
<action name="Exit"><prompt>no</prompt></action>
</item>
<separator />
<item label="Reboot">
<action name="Execute">
<command>shutdown -r now</command>
</action>
</item>
<item label="Shutdown">
<action name="Execute">
<command>shutdown -p now</command>
</action>
</item>
Resources
- My config files and scripts:
- Openbox rc.xml and menu.xml
- .xinitrc
- dunstrc
- rofi
- x11_lock.sh
- x11_lock_suspend.sh
- Openbox Documentation
- FreeBSD Desktop series by vermaden: Configuration - Openbox
You can like, share, or comment on this post on the Fediverse 💬
» Next: Exploring FreeBSD on a Laptop
« Previous: X Window System on FreeBSD