Wayland

Wayland

Introduction

Wayland is a modern display server protocol designed to replace the X Window System (Xorg). Rather than routing all display communication through a central X server, Wayland compositors act as both the display server and the window manager, communicating directly with client applications and the kernel's Direct Rendering Manager (DRM). This architecture reduces latency, improves security by isolating application windows from each other, and eliminates many of the legacy layers in the X11 stack.

Wayland support on MidnightBSD is functional but still maturing. Users comfortable with configuring BSD systems manually will find it workable. Those who prefer a more polished out-of-the-box experience may wish to continue using Xorg until support matures further. Some hardware and some applications may still require Xorg or XWayland compatibility.

Prerequisites

Before setting up Wayland, ensure the following is in place:

Add your user to the video group as root:

pw groupmod video -m username

Enable dbus in /etc/rc.conf and start it:

sysrc dbus_enable="YES" service dbus start

GPU Drivers

Wayland requires kernel-level GPU support through DRM and KMS. The drm-kmod package provides the necessary kernel modules for Intel and AMD GPUs.

Install drm-kmod from mports:

mport install drm-kmod

Enable the appropriate module for your GPU in /etc/rc.conf.

For Intel integrated graphics (Haswell and newer):

sysrc kld_list="i915kms"

For AMD GPUs (Southern Islands and newer):

sysrc kld_list="amdgpu"

For older AMD GPUs (pre-Southern Islands):

sysrc kld_list="radeonkms"

Load the module immediately without rebooting:

kldload i915kms

After loading, verify the DRM device nodes are present:

ls /dev/dri/

You should see entries such as card0 and renderD128. If /dev/dri/ is empty or missing, the GPU module did not load correctly. Check dmesg for errors.

NVIDIA GPUs are not currently supported through the open DRM path. NVIDIA users should use Xorg with the proprietary nvidia driver from mports.

Seat Management

Wayland compositors need permission to open DRM and input devices without running as root. On MidnightBSD, this is handled by seatd, a lightweight seat management daemon. It grants compositors privileged device access on behalf of logged-in users.

Install seatd from mports:

mport install seatd

Enable and start seatd:

sysrc seatd_enable="YES" service seatd start

Add your user to the _seatd group so the compositor can communicate with the daemon:

pw groupmod _seatd -m username

You must log out and log back in for group membership changes to take effect.

Set the LIBSEAT_BACKEND environment variable so compositors use seatd:

export LIBSEAT_BACKEND=seatd

Add this to your shell startup file (~/.profile, ~/.bashrc, or ~/.zshrc) so it is set automatically at login.

Compositors

A Wayland compositor combines the roles of display server and window manager. Several compositors are available in mports. The right choice depends on whether you prefer a tiling or stacking (floating) window layout.

Sway

Sway is a tiling Wayland compositor that is a drop-in replacement for the i3 window manager. It is the most widely used and tested Wayland compositor on BSD systems. Sway arranges windows automatically in a non-overlapping tiled layout and is configured through a plain text file.

Install sway and its status bar:

mport install sway swaybar

Copy the default configuration as a starting point:

mkdir -p ~/.config/sway cp /usr/local/etc/sway/config ~/.config/sway/config

Start sway from the console:

sway

The default configuration sets the Super (Windows) key as the modifier. Key bindings of note from the default config:

The sway configuration file at ~/.config/sway/config uses the same syntax as i3. Refer to man 5 sway for all available options.

Wayfire

Wayfire is a stacking (floating) compositor with a plugin-based architecture and visual effects. It is suitable for users who prefer a more traditional desktop layout where windows can overlap freely.

Install Wayfire from mports:

mport install wayfire

Copy the example configuration:

mkdir -p ~/.config cp /usr/local/share/doc/wayfire/wayfire.ini ~/.config/wayfire.ini

Start Wayfire from the console:

wayfire

Wayfire is configured through ~/.config/wayfire.ini. Plugins for window decorations, a panel, a background, and other features are enabled and configured in this file. Refer to man wayfire and the project documentation for the full list of available plugins.

labwc

labwc is a lightweight stacking compositor modeled after Openbox. It uses XML configuration files in the same format as Openbox and is well suited for users migrating from an Openbox-based setup or who want a minimal, traditional floating window manager under Wayland.

Install labwc from mports:

mport install labwc

Create the configuration directory and copy the default files:

mkdir -p ~/.config/labwc cp /usr/local/etc/xdg/labwc/rc.xml ~/.config/labwc/rc.xml cp /usr/local/etc/xdg/labwc/menu.xml ~/.config/labwc/menu.xml

Start labwc from the console:

labwc
Weston

Weston is the reference Wayland compositor maintained by the Wayland project. It is primarily intended as a demonstration and testing environment rather than a daily-use desktop, but it is stable and useful for verifying that your Wayland setup is working correctly before configuring a more full-featured compositor.

Install Weston from mports:

mport install weston

Start Weston from the console:

weston

Weston can also be started with a specific backend if needed, for example to run inside an existing X session for testing:

weston --backend=x11

XWayland

XWayland is an X server that runs as a Wayland client, providing backward compatibility for applications that have not yet been ported to Wayland. It allows X11 applications to run inside a Wayland compositor session without a separate Xorg server. Most compositors start XWayland automatically when an X11 application requests it.

Install XWayland from mports:

mport install xwayland

In sway, XWayland can be disabled if you do not need X11 application support, which reduces the attack surface. Add to ~/.config/sway/config:

xwayland disable

To force a specific application to use XWayland even within a Wayland session, set GDK_BACKEND=x11 for GTK applications or QT_QPA_PLATFORM=xcb for Qt applications before launching them.

Environment Variables

Several environment variables must be set for a Wayland session to work correctly. Add these to your shell startup file (~/.profile for login shells) so they are available in all applications launched from the compositor.

Required

XDG_RUNTIME_DIR points to a per-user directory for runtime files such as the Wayland socket. It must be set before starting a compositor:

export XDG_RUNTIME_DIR=/var/run/user/$(id -u)

Create the directory if it does not exist and set the correct permissions:

mkdir -p /var/run/user/$(id -u) chmod 700 /var/run/user/$(id -u)

The Wayland compositor sets WAYLAND_DISPLAY automatically. It is typically wayland-0 and points to the compositor's socket inside XDG_RUNTIME_DIR.

Toolkit Integration

Tell GTK applications to use the Wayland backend:

export GDK_BACKEND=wayland

Tell Qt applications to use the Wayland platform plugin:

export QT_QPA_PLATFORM=wayland

Tell SDL2 applications to use Wayland:

export SDL_VIDEODRIVER=wayland

Enable native Wayland rendering in Firefox:

export MOZ_ENABLE_WAYLAND=1

Enable Wayland rendering in Electron applications such as VS Code:

export ELECTRON_OZONE_PLATFORM_HINT=wayland

Enable Wayland rendering in Chromium and Chromium-based browsers:

export CHROMIUM_FLAGS="--ozone-platform=wayland"
Seat Management
export LIBSEAT_BACKEND=seatd

Application Compatibility

Most GTK3, GTK4, and Qt5/Qt6 applications support Wayland natively. Applications still using older toolkits or hardcoded X11 calls will run through XWayland automatically as long as XWayland is installed and enabled.

Terminal emulators with native Wayland support available in mports include:

Application launchers compatible with Wayland:

Status bars for use with sway and other wlroots compositors:

Screen capture and screenshot tools:

Clipboard management:

Troubleshooting

Compositor fails to start: no DRM device

If the compositor exits immediately with an error about DRM or KMS, the GPU kernel module may not be loaded. Verify with:

ls /dev/dri/ dmesg | grep drm

If /dev/dri/ is empty, load the appropriate module manually and check for errors:

kldload i915kms dmesg | tail -20
Permission denied on /dev/dri or /dev/input

Ensure your user is a member of the video group and that seatd is running. Group changes require logging out and back in to take effect.

id service seatd status
XDG_RUNTIME_DIR not set or wrong permissions

The directory must exist, be owned by your user, and have mode 700. Check with:

ls -ld /var/run/user/$(id -u)

If it is missing, create it:

mkdir -p /var/run/user/$(id -u) && chmod 700 /var/run/user/$(id -u)
X11 applications show a blank window or crash

Ensure XWayland is installed and that the compositor has started it. Check for a Wayland socket and an X display socket in the runtime directory:

ls $XDG_RUNTIME_DIR

You should see both wayland-0 and a file like .X0-lock when XWayland is running.

Enabling verbose logging

Start sway with debug logging to diagnose startup failures:

sway -d 2> ~/sway-debug.log

For weston, verbose output is enabled with:

weston --log=~/weston.log