X
The X Window System
This chapter will cover the usual way of giving your Dragonfly BSD system an X Window style Graphical User Interface (GUI).
Quick Start Guide
# (As root) Install xorg and the most common keyboard and mouse drivers
pkg install xorg xf86-input-libinput xf86-input-evdev
# (As root) Add the user that will be running X to the video group
# so that user can use 3D / Hardware / GPU acceleration.
pw groupmod video -M [YOUR_USERNAME]
# Reboot to make sure the group membership is applied
reboot
# (As non-root user) Start an X session
startx
Introduction to X
The X Window System (sometimes just called "X") is the environment which provides graphics services to DragonFly BSD and other Unix-based systems. By itself, X provides very little, since one also must have a window manager to present a user interface. The X11 specification is an open standard, and there are different implementations, some commercial, and some free. X.org is the free implementation of the X11 specification.
It is possible to run X clients on a system without any graphical support. For example, one could have an application (the X client) running on an ARM system, displaying its output on an amd64's graphical display (the X server). Since X is a well-defined, cross-platform protocol, it is even possible to have an X application running on (for example) an OpenBSD machine using a DragonFly BSD machine for its display. The client and server can also be running on the same machine, and for most of this section, that will be the assumption.
Installation
The X Window system is not included in the base system, since server applications do not require X.
pkg install xorg
Install X Drivers for Input and Video
Most users of modern DragonFlyBSD will need to install these two drivers in order for keyboard and mouse to work in X:
pkg install xf86-input-libinput xf86-input-evdev
Some systems will require additional drivers. For example:
Wacom Tablets/Mice - xf86-input-wacom
Synaptics Touchpads - xf86-input-synaptics
VMware Seamless Cursor - xf86-input-vmmouse
Elographics Touchscreen - xf86-input-elographics
If you wish to test legacy BSD input drivers then there are:
xf86-input-keyboard
xf86-input-mouse
There is also an xf86-input-joystick driver for joysticks.
With AMD and Intel GPUs it's usually totally fine to use the default video driver. For other GPUs if you want 1080p video output the xf86-video-vesa driver is required (or the associated user-mode-setting driver. The X driver will still provide some 2D acceleration so its good to know what driver you can have if you want it even though it will usually be provided by your graphics stack already.
amdgpu kernel driver - xf86-video-amdgpu
radeon kernel driver - xf86-video-ati
intel kernel driver - xf86-video-intel
VESA generic HD driver - xf86-video-vesa
NVIDIA GTX 200 Series and older - xf86-video-nv
NVIDIA after GTX 200 series - NONE(use vesa)
Some matrox GPUs - xf86-video-mga
VMware GPU - xf86-video-vmware
There is also an old BSD video driver here:
xf86-video-scfb
This may be useful for syscons if vesa or the default DRM driver provides undesirable modes.
Configuring X
X often requires no configuration at all. You can put your configuration files in /usr/local/etc/X11/ or /usr/local/etc/X11/xorg.conf.d/
Read xorg.conf(5) for more information on configuration files.
3D Hardware / GPU Acceleration
To use 3D acceleration, that is to allow some processes (alacritty as an example) to use the GPU for faster performance, add the user that will be running X to the video group.
pw groupmod video -M [USERNAME_THAT_WILL_BE_RUNNING_X]
reboot
Starting X
There are two common ways to run X: by manually invoking the startx(1) or via xdm(1).
startx
Note: twm(1) window manager is started by default.
Introduction to the X Display Manager
The X Display Manager (XDM) is an optional part of the X Window System that provides services similar to those provided by init(8), getty(8) and login(1) on character terminals: prompting for login name and password, authenticating the user, and running a "session".
# Install xdm if you choose to use it
pkg install xdm
Running the X Display Manager
Manually run /usr/local/bin/xdm as root. Or to run the XDM daemon on a virtual terminal, change field 4 from off to on in /etc/ttys file:
ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure
and restart init(8).
Running a Network Display Server
In order for other clients to connect to the display server, edit the access control rules and enable the connection listener. To make XDM listen for connections, comment out a line in the /usr/local/etc/X11/xdm/xdm-config file:
! SECURITY: do not listen for XDMCP or Chooser requests
! Comment out this line if you want to manage X terminals with xdm
DisplayManager.requestPort: 0
and restart xdm(1). More strict access controls may be desired, so look at the example entries in /usr/local/etc/X11/xdm/Xaccess, and refer to the xdm(1) manual page for further information.
Customizing X
When an X session is started, shell scripts in the user's home directory can be used to start as many programs as desired. Most of the programs in these scripts should run in the background, but the last one (typically the window manager) should run in the foreground. When the window manager exits, the script will exit, and X will shut down or return to the xdm(1) login prompt.
The startx(1) command looks for a $HOME/.xinitrc script. If this script doesn't exist, the system's /usr/local/etc/X11/xinit/xinitrc file is used instead.
After the user logs in from xdm(1), the /usr/local/etc/X11/xdm/Xsession script checks whether there is a $HOME/.xsession script.
In the simplest case, your .xinitrc or .xsession script contains only one line specifying your preferred window manager:
cwm
Or you can get a little more fancy:
export LANG=en_US.UTF-8
setxkbmap -layout us,ru -option grp:sclk_toggle
xconsole -geometry -0+0 -fn 5x7 &
xclock -geometry 75x75-0-0 &
xsetroot -solid grey &
xterm -geometry 100x25-400+250 &
cwm
Note: make sure your .xsession file is executable.
Choosing a Window Manager
The default window manager is twm(1). There are several other window managers available, including xfce, lumina, lxde, windowmaker, mate, i3, and kde.
The examples below overwrite your ~/.xinitrc file. Make a backup if you already have content in it.
lxde:
pkg install lxde-meta
echo 'exec startlxde' > ~/.xinitrc
startx
i3 (Also see Getting Started with i3wm)
pkg install i3
echo 'i3' > ~/.xinitrc
startx
xfce:
pkg install xfce
echo 'exec startxfce4' > ~/.xinitrc
startx
lumina:
pkg install lumina
echo 'exec start-lumina-desktop' > ~/.xinitrc
startx
mate:
pkg install mate
echo 'exec mate-session' > ~/.xinitrc
startx
