% pciconf -lv | grep -B3 display
Chapter 5. The X Window System
Table of Contents
5.1. Synopsis
An installation of FreeBSD using bsdinstall(8) does not automatically install a graphical user interface. This chapter describes how to install and configure the Xorg(1) server, which provides the open source X Window System (colloquially X11) used to provide a graphical environment.
Before reading this chapter, you should:
Know how to install additional third-party software as described in Installing Applications: Packages and Ports.
After reading this chapter, you will know:
How to select and install drivers for your graphics processor (GPU).
The various components of the X Window System, and how they interoperate.
How to install and configure the X.org server.
How to install fonts for the X Window System.
5.2. Graphics Drivers
abstract: Identify your GPU, the port providing a driver for it, install it, then enable it to run at subsequent boot with sysrc(8).
Before FreeBSD can render a graphical environment, it needs a kernel module to drive the graphics processor. Graphics drivers are a fast-moving, cross-platform target, which is why this is developed and distributed separately from the FreeBSD base system.
The following table shows the different graphics processors supported by FreeBSD, their corresponding module, and which port provides it:
Type | License | Module | Port |
---|---|---|---|
Intel® | Open Source |
| |
AMD® | Open Source |
| |
NVIDIA® | Proprietary |
| |
System Console Framebuffer | Open Source |
| |
VESA BIOS Extension | Open Source |
| |
VirtualBox® | Open Source |
| |
VMware® | Open Source |
|
There are several generations of driver technologies supported.
Direct Rendering drivers allowing PRIME offloading. PRIME allows for multiple providers of graphics processing to coexist. PRIME is described further in Graphics Configuration.
Kernel Modesetting (KMS) This allows the driver to directly specify the display mode. This is required to support suspend and resume when using the vt(4) console driver.
User Modesetting The oldest class of drivers is still supported, however they may only be used with sc(4) console and older versions of the Xorg(1) graphical environment.
The following command can be used to identify which graphics processor is installed in the system:
The output should be similar to the following:
vgapci1@pci0:0:2:0: class=0x030000 rev=0x0c hdr=0x00 vendor=0x8086 device=0x46a6 subvendor=0x1028 subdevice=0x0b29 vendor = 'Intel Corporation' device = 'Alder Lake-P GT2 [Iris Xe Graphics]' class = display
Detailed instructions on installing and enabling these drivers are in the subsequent subsections.
If the graphics processor is not supported by Intel®, AMD®, or NVIDIA® drivers, then SCFB or VESA modules should be used. SCFB module must be used when booting in UEFI mode. VESA module must be used when booting in BIOS mode. This command can be used to check the booting mode:
The output should be similar to the following: machdep.bootmethod: UEFI |
5.2.1. Intel® Graphics
The graphics/drm-kmod package indirectly provides a range of kernel modules for use with Intel® Graphics. Recent versions of these modules can be used in conjunction with other graphics processors in PRIME with no special configuration.
The Intel® Graphics driver can be installed by executing the following command:
# pkg install drm-kmod
Then add the module to /etc/rc.conf file, by executing the following command:
# sysrc kld_list+=i915kms
5.2.2. AMD® Graphics
The graphics/drm-kmod package indirectly provides
kernel modules for a range of AMD® Graphics processors.
The modules amdgpu
or radeonkms
can be used
depending the generation of the hardware.
The FreeBSD project maintains a AMD graphics support matrix
showing support levels and to determine which driver must be used.
The AMD® Graphics drivers can be installed by executing the following command:
# pkg install drm-kmod
Enable the current module by adding it to the /etc/rc.conf file, executing the following command:
# sysrc kld_list+=amdgpu
For older graphics (pre-HD7000/Tahiti), instead enable the legacy module by adding it to the /etc/rc.conf file, executing the following command:
# sysrc kld_list+=radeonkms
5.2.3. NVIDIA® Graphics
NVIDIA® produces standalone or discrete graphics processors, and provides a proprietary driver for FreeBSD. The FreeBSD Ports Collection provides over a decade of drivers for supporting generations of NVIDIA graphics.
Administrators should install the latest driver supported by their hardware.
The following table shows the port containing the driver, the kernel module recommended for loading, and a link to the list of hardware supported by that driver:
Port | Module | Supported hardware |
---|---|---|
| ||
| ||
| ||
| ||
|
The latest NVIDIA® Graphics driver can be installed by running the following command:
# pkg install nvidia-drm-kmod
To enable the driver, add the module to /etc/rc.conf file, by executing the following command:
# sysrc kld_list+=nvidia-drm
This is the direct rendering KMS driver.
Kernel modesetting is the option to set the graphics mode in the kernel. Enable it for subsequent boots with the following loader.conf(5) tunable:
hw.nvidiadrm.modeset="1'
Both PRIME and Wayland require kernel modesetting.
Prior versions of the driver do not support Direct Rendering. Instead use the modesetting module, by executing the following command:
# sysrc kld_list+=nvidia-modeset
If requiring Nvidia drivers prior to 390, note that they do not support kernel modesetting, and thus they must be used with the legacy sc(4) console driver, and a x11/xorg-server version prior to 1.20.
Enable them in /etc/rc.conf with the following command:
# sysrc kld_list+=nvidia
5.3. X Window System Overview
The X Window System is the heritage graphical stack for UNIX® platforms, supporting the latest technologies while maintaining support for generations of applications. Applications, including the components of the desktop, are hosted by the Xorg(1) server. This system is network aware and its various components can interoperate across networks.
5.4. Installing The X.org Server
abstract: The X.org server
must be installed to host the desktop.
Users must be added to the video
group to use it.
Once a graphics driver is installed and enabled, the X.org server can be installed as a meta-package, or compiled locally with the ports tree.
The full meta-package can be installed quickly but with fewer options for customization:
# pkg install xorg
This installation results in the complete X Window System being installed, including a traditional window manager, twm(1), and surrounding traditional desktop suite. Most users will want to install and configure a contemporary desktop of their choice.
The current user must be a member of the video
group
to run a graphical environment.
To add a user to the video
group, execute the following command:
# pw groupmod video -m username
To run the X Window System, use startx(1) from x11/xinit, or install and configure a display manager to start a graphical login on boot.
A smaller version of the X Window System suitable for experienced users is available in x11/xorg-minimal. Most of the documents, libraries, and applications will not be installed. Some applications require these additional components to function. |
5.5. X.org Configuration
abstract: If the defaults for your monitor or input devices, are not satisfactory, desktops include GUIs for configuring them, or they can be configured manually.
The X.org server supports most common graphics processors, monitors, and input devices. First, try the defaults. This subsection provides an overview of their configuration.
5.5.1. X.org Configuration Files
Historically, the X.org server was configured with files in /usr/local/etc/X11/. This is still supported for edge cases, but conflicts with dynamic autoconfiguration.
Do not create configuration for the X.org server in
xorg.conf
or run Xorg -configure
unless automatic configuration fails.
X.org server looks in several directories for configuration files. /usr/local/etc/X11/ is the recommended directory for these files on FreeBSD. Using this directory helps keep application files separate from operating system files.
It is easier to use multiple files that each configure a specific setting than the traditional single xorg.conf. These files are stored in the /usr/local/etc/X11/xorg.conf.d/ subdirectory.
5.5.2. Graphics Configuration
Direct rendering provides the ability to seamlessly use a discrete graphics processor (dGPU) alongside an integrated graphics processor (iGPU), called PRIME. The drivers will automatically offload intensive tasks to the dGPU when required, and power it down when able.
To launch applications on the more powerful GPU in PRIME,
use the DRI_PRIME=1
enviroment variable.
If multiple graphics drivers are conflicting, the driver for the graphics processor can be specified in the /usr/local/etc/X11/xorg.conf.d/ directory.
To configure the Intel® driver in a configuration file:
/usr/local/etc/X11/xorg.conf.d/20-intel.conf
Section "Device" Identifier "Card0" Driver "intel" EndSection
To configure the AMD® driver in a configuration file:
/usr/local/etc/X11/xorg.conf.d/20-radeon.conf
Section "Device" Identifier "Card0" Driver "radeon" EndSection
To configure the NVIDIA® driver in a configuration file:
/usr/local/etc/X11/xorg.conf.d/20-nvidia.conf
Section "Device" Identifier "Card0" Driver "nvidia-modeset" EndSection
x11/nvidia-xconfig can also be used to perform basic control over configuration options available in the NVIDIA driver. |
To configure the SCFB driver in a configuration file:
/usr/local/etc/X11/xorg.conf.d/20-scfb.conf
Section "Device" Identifier "Card0" Driver "scfb" EndSection
To configure the VESA driver in a configuration file:
/usr/local/etc/X11/xorg.conf.d/20-vesa.conf
Section "Device" Identifier "Card0" Driver "vesa" EndSection
To configure multiple graphics processors, the BusID
can be added.
A list of graphics processor bus ID
s can be displayed by executing:
% pciconf -lv | grep -B3 display
The output should be similar to the following:
vgapci0@pci0:0:2:0: class=0x030000 rev=0x0c hdr=0x00 vendor=0x8086 device=0x46a6 subvendor=0x1028 subdevice=0x0b29 vendor = 'Intel Corporation' device = 'Alder Lake-P GT2 [Iris Xe Graphics]' class = display -- vgapci0@pci0:1:0:0: class=0x030200 rev=0xa1 hdr=0x00 vendor=0x10de device=0x25b9 subvendor=0x1028 subdevice=0x0b29 vendor = 'NVIDIA Corporation' device = 'GA107GLM [RTX A1000 Laptop GPU]' class = display
/usr/local/etc/X11/xorg.conf.d/20-drivers.conf
Section "Device" Identifier "Card0" Driver "intel" BusID "pci0:0:2:0" EndSection Section "Device" Identifier "Card1" Driver "nvidia-modeset" BusID "pci0:0:2:1" EndSection
5.5.3. Monitor Configuration
Almost all monitors support the Extended Display Identification Data
standard (EDID
).
X.org uses EDID
to communicate with the monitor
and detect the supported resolutions and refresh rates.
Then it selects the most appropriate combination of settings
to use with that monitor.
Other resolutions supported by the monitor can be selected atomically after the X server has been started with xrandr(1), or in the X.org server configuration files.
5.5.3.1. Using RandR (Resize and Rotate)
Run xrandr(1) in an X session without any parameters to see a list of video outputs and detected monitor modes:
% xrandr
The output should be similar to the following:
Screen 0: minimum 320 x 200, current 2560 x 960, maximum 8192 x 8192 LVDS-1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 261mm x 163mm 1280x800 59.99*+ 59.81 59.91 50.00 1280x720 59.86 59.74 1024x768 60.00 1024x576 59.90 59.82 960x540 59.63 59.82 800x600 60.32 56.25 864x486 59.92 59.57 640x480 59.94 720x405 59.51 58.99 640x360 59.84 59.32 VGA-1 connected primary 1280x960+1280+0 (normal left inverted right x axis y axis) 410mm x 257mm 1280x1024 75.02 60.02 1440x900 74.98 60.07 1280x960 60.00* 1280x800 74.93 59.81 1152x864 75.00 1024x768 75.03 70.07 60.00 832x624 74.55 800x600 72.19 75.00 60.32 56.25 640x480 75.00 72.81 66.67 59.94 720x400 70.08 HDMI-1 disconnected (normal left inverted right x axis y axis) DP-1 disconnected (normal left inverted right x axis y axis) HDMI-2 disconnected (normal left inverted right x axis y axis) DP-2 disconnected (normal left inverted right x axis y axis) DP-3 disconnected (normal left inverted right x axis y axis)
This shows that the VGA-1
output is being used to display
a screen resolution of 1280x960 pixels at a refresh rate of about 60 Hz.
The LVDS-1
is being used as a secondary monitor to display
a screen resolution of 1280x800 pixels at a refresh rate of about 60 Hz.
Monitors are not attached to the HDMI-1
, HDMI-2
, DP-1
, DP-2
, and
DP-3
connectors.
Any of the other display modes can be selected with xrandr(1). For example, to switch to 1280x1024 at 60 Hz:
% xrandr --output LVDS-1 --mode 1280x720 --rate 60
Oftentimes, a black screen upon starting X can be fixed
by adding an |
5.5.3.2. Using the X.org Configuration Files
The monitor configuration can also be set in a configuration file.
To set a screen resolution of 1024x768 in a configuration file:
/usr/local/etc/X11/xorg.conf.d/10-monitor.conf
Section "Screen" Identifier "Screen0" Device "Card0" SubSection "Display" Modes "1024x768" EndSubSection EndSection
5.5.4. Input Configuration
The X.org server provides the x11/libinput library, a cross-platform effort to support all touch, pointing, and keyboard devices under a unified library. Unless specified otherwise, this is loaded automatically.
Individual device settings for libinput(4) can be tuned in your desktop’s GUI, or manually with xinput and setxkbmap.
Alternatively, there are older, lightweight, individual drivers for specific input devices available in the x11-drivers catagory named x11/xf86-input-[foo]. This approach requires manual configuration of the X.org server. Both are described in this subsection.
5.5.4.1. Using Atomic Input Configuration
Devices supported by libinput(4) can be configured with graphical utilities included with your desktop of choice, or manually and atomically at runtime with x11/xinput and x11/setxkbmap.
To ask libinput(4) what devices it’s currently attached to, run xinput(1) with no arguments:
$ xinput
Its output should be similar to the following:
⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ System mouse id=7 [slave pointer (2)] ⎜ ↳ VEN_0488:00 0488:1031 Mouse id=11 [slave pointer (2)] ⎜ ↳ VEN_0488:00 0488:1031 TouchPad id=12 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ System keyboard multiplexer id=6 [slave keyboard (3)] ↳ Power Button id=8 [slave keyboard (3)] ↳ Sleep Button id=9 [slave keyboard (3)] ↳ AT keyboard id=10 [slave keyboard (3)]
All settings supported by these devices are provided as properties, which can be listed and set atomically. Pointing devices have many configurable properties, keyboards usually need none.
To customize your keyboard, take a look at setxkbmap(1).
Once satisfied with your configuration, simply add the lines to your X initialization script such as ~/.Xsession or ~/.xinitrc.
5.5.4.2. Using X.org Configuration Files
Some desktop environments (such as KDE Plasma) provide a graphical UI for setting these parameters. Check if this is the case before resorting to manual configuration editing. |
For example, to manually configure the X.org server for the keyboard layout:
/usr/local/etc/X11/xorg.conf.d/00-keyboard.conf
Section "InputClass" Identifier "Keyboard1" MatchIsKeyboard "on" Option "XkbLayout" "es, fr" Option "XkbModel" "pc104" Option "XkbVariant" ",qwerty" Option "XkbOptions" "grp:win_space_toggle" EndSection
5.6. Using Fonts in the X Window System
abstract: Additional fonts can be installed from the x11-fonts category or placed in ~/.fonts. They are available immediately to modern applications. Configuration for older applications is available and described as well.
The X Window System provides the X FreeType interface library (Xft(3)) to render vector or outline fonts, as well as the traditional X Logical Font Description system maintaining compatibility with generations of applications and fonts.
There are primarily two types of fonts users will be interested in:
OpenType fonts or TrueType® fonts are for displaying on a screen.
Adobe® PostScript® Type 1 fonts are for printing to paper.
These are both vector or outline fonts, there are also bitmap fonts.
The FreeBSD Ports Collection includes a wide and growing catalog of free, high quality fonts available for installation in the x11-fonts catagory.
System-wide font packages installed from the ports collection
live in /usr/local/share/fonts/
.
Fonts for a single user can be placed in ~/.fonts/
,
or ~/.local/share/fonts/
.
Fonts in either directory or subdirectories will be available for immediate use when the font information cache is rebuilt. To trigger this manually, issue:
% fc-cache
Plenty of free, high quality fonts of both types are available in the ports tree which can be readily used with X Window System. This chapter provides a brief overview of both, as well as configuring the X FreeType interface.
For more information about how to install and configure fonts on FreeBSD, please read the article Fonts and FreeBSD.
5.6.1. TrueType® Fonts
X.org has built in support for rendering TrueType® fonts.
There are two different modules that can enable this functionality.
The freetype module is used in this example because it is more consistent with the other font rendering back-ends.
To enable the freetype module just add the following line to the "Module"
section of /usr/local/etc/X11/xorg.conf.d/90-fonts.conf.
Load "freetype"
Now make a directory for the TrueType® fonts (for example, /usr/local/share/fonts/TrueType) and copy all of the TrueType® fonts into this directory.
Keep in mind that TrueType® fonts cannot be directly taken from an Apple® Mac®; they must be in UNIX®/MS-DOS®/Windows® format for use by X.org.
Once the files have been copied into this directory, use mkfontscale to create a fonts.dir, so that the X font renderer knows that these new files have been installed.
mkfontscale
can be installed as a package:
# pkg install mkfontscale
Then create an index of X font files in a directory:
# cd /usr/local/share/fonts/TrueType
# mkfontscale
Now add the TrueType® directory to the font path. This is just the same as described in Type1 Fonts:
% xset fp+ /usr/local/share/fonts/TrueType
% xset fp rehash
or add a FontPath
line to xorg.conf.
Now Gimp, LibreOffice, and all of the other X applications should now recognize the installed TrueType® fonts. Extremely small fonts (as with text in a high resolution display on a web page) and extremely large fonts (within LibreOffice) will look much better now.
5.6.2. Type1 Fonts
The URW font collection (x11-fonts/urwfonts) includes high quality versions of standard type1 fonts (Times Roman™, Helvetica™, Palatino™ and others). The Freefonts collection (x11-fonts/freefonts) includes many more fonts, but most of them are intended for use in graphics software such as the Gimp, and are not complete enough to serve as screen fonts.
To install the above Type1 font collections from binary packages, run the following commands:
# pkg install urwfonts
And likewise with the freefont or other collections. To have a manually configured X server detect these fonts, add an appropriate line to the X server configuration file (/usr/local/etc/X11/xorg.conf.d/90-fonts.conf), which reads:
Section "Files" FontPath "/usr/local/share/fonts/urwfonts/" EndSection
Alternatively, at the command line in the X session run:
% xset fp+ /usr/local/share/fonts/urwfonts
% xset fp rehash
This will work but will be lost when the X session is closed, unless it is added to the startup file (~/.xinitrc for a normal startx
session, or ~/.xsession when logging in through a graphical login manager like XDM).
A third way is to use the new /usr/local/etc/fonts/local.conf as demonstrated in Anti-Aliased Fonts.
5.6.3. Anti-Aliased Fonts
All fonts in X.org that are found in /usr/local/share/fonts/ and ~/.fonts/ are automatically made available for anti-aliasing to Xft-aware applications. Most recent applications are Xft-aware, including KDE, GNOME, and Firefox.
To control which fonts are anti-aliased, or to configure anti-aliasing properties, create (or edit, if it already exists) the file /usr/local/etc/fonts/local.conf. Several advanced features of the Xft font system can be tuned using this file; this section describes only some simple possibilities. For more details, please see fonts-conf(5).
This file must be in XML format.
Pay careful attention to case, and make sure all tags are properly closed.
The file begins with the usual XML header followed by a DOCTYPE definition, and then the <fontconfig>
tag:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig>
As previously stated, all fonts in /usr/local/share/fonts/ as well as ~/.fonts/ are already made available to Xft-aware applications. To add another directory outside of these two directory trees, add a line like this to /usr/local/etc/fonts/local.conf:
<dir>/path/to/my/fonts</dir>
After adding new fonts, and especially new font directories, rebuild the font caches:
# fc-cache -f
Anti-aliasing makes borders slightly fuzzy, which makes very small text more readable and removes "staircases" from large text, but can cause eyestrain if applied to normal text. To exclude font sizes smaller than 14 point from anti-aliasing, include these lines:
<match target="font"> <test name="size" compare="less"> <double>14</double> </test> <edit name="antialias" mode="assign"> <bool>false</bool> </edit> </match> <match target="font"> <test name="pixelsize" compare="less" qual="any"> <double>14</double> </test> <edit mode="assign" name="antialias"> <bool>false</bool> </edit> </match>
Spacing for some monospaced fonts might also be inappropriate with anti-aliasing. This seems to be an issue with KDE, in particular. One possible fix is to force the spacing for such fonts to be 100. Add these lines:
<match target="pattern" name="family"> <test qual="any" name="family"> <string>fixed</string> </test> <edit name="family" mode="assign"> <string>mono</string> </edit> </match> <match target="pattern" name="family"> <test qual="any" name="family"> <string>console</string> </test> <edit name="family" mode="assign"> <string>mono</string> </edit> </match>
(this aliases the other common names for fixed fonts as "mono"
), and then add:
<match target="pattern" name="family"> <test qual="any" name="family"> <string>mono</string> </test> <edit name="spacing" mode="assign"> <int>100</int> </edit> </match>
Certain fonts, such as Helvetica, may have a problem when anti-aliased. Usually this manifests itself as a font that seems cut in half vertically. At worst, it may cause applications to crash. To avoid this, consider adding the following to local.conf:
<match target="pattern" name="family"> <test qual="any" name="family"> <string>Helvetica</string> </test> <edit name="family" mode="assign"> <string>sans-serif</string> </edit> </match>
After editing local.conf, make certain to end the file with the </fontconfig>
tag.
Not doing this will cause changes to be ignored.
Users can add personalized settings by creating their own ~/.config/fontconfig/fonts.conf.
This file uses the same XML
format described above.
One last point: with an LCD screen, sub-pixel sampling may be desired. This basically treats the (horizontally separated) red, green and blue components separately to improve the horizontal resolution; the results can be dramatic. To enable this, add the line somewhere in local.conf:
<match target="font"> <test qual="all" name="rgba"> <const>unknown</const> </test> <edit name="rgba" mode="assign"> <const>rgb</const> </edit> </match>
Depending on the sort of display, |
Last modified on: December 19, 2024 by Alexander Ziaee