How to Customize the Xorg Configuration on FreeBSD Operating System

How to customize the Xorg configuration on FreeBSD operating system

Introduction

Xorg, the X Window System, is the foundation for graphical environments on Unix-like systems, including FreeBSD. By default, Xorg auto-configures itself, but there are cases where manual customization is necessary, such as setting up multiple monitors, configuring input devices, or optimizing performance. This guide walks you through the process of customizing the Xorg configuration on FreeBSD.

Prerequisites

Before diving into customization, ensure you have:

  • FreeBSD installed with root or superuser privileges.
  • Xorg installed (pkg install xorg or via ports).
  • A compatible graphics driver installed (e.g., xf86-video-intel, xf86-video-nouveau, nvidia-driver).
  • A working text editor (such as vi, nano, or ee).

Understanding Xorg Configuration

Xorg’s configuration is usually handled automatically, but if manual intervention is required, settings can be placed in configuration files located in:

  • /etc/X11/xorg.conf (legacy, monolithic configuration file)
  • /usr/local/etc/X11/xorg.conf.d/ (preferred method using modular configuration files)

The modular approach is more flexible and recommended for modern FreeBSD systems.

Generating a Base Xorg Configuration

To create a base configuration file for Xorg, use:

Xorg -configure

This generates /root/xorg.conf.new. You can test it with:

Xorg -config /root/xorg.conf.new

If everything works correctly, move it to /etc/X11/xorg.conf:

mv /root/xorg.conf.new /etc/X11/xorg.conf

However, it’s generally better to create smaller configuration snippets in /usr/local/etc/X11/xorg.conf.d/.

Customizing Display and Graphics Settings

Specifying the Graphics Driver

To manually configure the graphics driver, create a file such as /usr/local/etc/X11/xorg.conf.d/20-gpu.conf:

Section "Device"
    Identifier  "GPU0"
    Driver      "nvidia"  # or "intel", "amdgpu", "vesa" depending on your hardware
    Option      "AccelMethod" "glamor"  # Optional, for improved acceleration
EndSection

If you have an NVIDIA GPU, ensure that the proprietary driver is installed and loaded:

pkg install nvidia-driver
sysrc kld_list+="nvidia-modeset"
service kldload start

Configuring Monitor and Screen Resolution

To set specific resolutions or multiple monitors, create /usr/local/etc/X11/xorg.conf.d/10-monitor.conf:

Section "Monitor"
    Identifier  "Monitor0"
    Modeline    "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
    Option      "PreferredMode" "1920x1080_60.00"
EndSection

Section "Screen"
    Identifier  "Screen0"
    Device      "GPU0"
    Monitor     "Monitor0"
    DefaultDepth 24
    SubSection "Display"
        Depth 24
        Modes "1920x1080"
    EndSubSection
EndSection

Use the cvt command to generate a modeline for a custom resolution:

cvt 1920 1080 60

Multi-Monitor Setup

For dual monitors, modify the configuration:

Section "Monitor"
    Identifier "Monitor0"
    Option "LeftOf" "Monitor1"
EndSection

Section "Monitor"
    Identifier "Monitor1"
    Option "RightOf" "Monitor0"
EndSection

This aligns Monitor1 to the right of Monitor0.

Configuring Input Devices

Keyboard Layout

To set a specific keyboard layout, create /usr/local/etc/X11/xorg.conf.d/30-keyboard.conf:

Section "InputClass"
    Identifier "Keyboard Defaults"
    MatchIsKeyboard "on"
    Option "XkbLayout" "us"
    Option "XkbVariant" "dvorak"  # Change layout as needed
EndSection

Mouse and Touchpad

For configuring touchpads (especially on laptops), create /usr/local/etc/X11/xorg.conf.d/40-touchpad.conf:

Section "InputClass"
    Identifier "Touchpad"
    MatchIsTouchpad "on"
    Driver "libinput"
    Option "Tapping" "on"
    Option "NaturalScrolling" "true"
    Option "DisableWhileTyping" "on"
EndSection

Troubleshooting Xorg Issues

Checking Xorg Logs

If Xorg fails to start, examine the log file at:

less /var/log/Xorg.0.log

Look for error messages (EE) or warnings (WW) to identify configuration issues.

Running Xorg in Failsafe Mode

If Xorg is misconfigured and won’t start, try running it with a basic setup:

Xorg -retro

Or temporarily remove custom configurations:

mv /usr/local/etc/X11/xorg.conf.d /usr/local/etc/X11/xorg.conf.d.bak

Ensuring Proper Permissions

Ensure your user is in the video group for proper access to GPU devices:

pw groupmod video -m yourusername

Then restart your session.

Conclusion

Customizing Xorg on FreeBSD allows for greater control over display settings, graphics performance, and input devices. While automatic configuration works well in most cases, manual configuration is useful for specific hardware setups. By properly structuring configuration files and troubleshooting issues using logs, you can achieve an optimized graphical environment on FreeBSD.