---
title: "LinuxKMS Backend"
description: "LinuxKMS Backend"
---
{/* cSpell: ignore linuxkms libinput libseat chvt libudev libgbm libxkbcommon xkbcommon noseat keymap xkeyboard udevadm DMABUF logind CRTC */}

import { Tabs, TabItem } from '@astrojs/starlight/components';

The LinuxKMS backend runs only on Linux and eliminates the need for a windowing system such as Wayland or X11.
Instead it uses the following libraries and interface to render directly to the screen and react to touch, mouse,
and keyboard input.

 - OpenGL via KMS/DRI.
 - Vulkan via wgpu and the Vulkan KHR Display Extension, or GBM buffers where the driver lacks it.
 - DRM dumb buffers for software rendering, as well as legacy LinuxFB rendering.
 - libinput/libudev for input event handling from mice, touch screens, or keyboards. (optional)
 - libseat for GPU and input device access without requiring root access. (optional)

## Dependencies

For compilation, pkg-config is used to determine the location of the system libraries needed by the
features you select. None of them are needed by every configuration:

| pkg-config package name | Package name on Debian based distros | Needed for                          |
|-------------------------|--------------------------------------|-------------------------------------|
| `gbm`                   | `libgbm-dev`                         | the FemtoVG and Skia renderers on OpenGL and Vulkan |
| `libseat`               | `libseat-dev`                        | libseat support                     |
| `libinput`              | `libinput-dev`                       | libinput support                    |
| `libudev`               | `libudev-dev`                        | libinput support                    |
| `xkbcommon`             | `libxkbcommon-dev`                   | libinput support                    |
| `libdlmclient`          | part of [drm-lease-manager](https://github.com/AGLExport/drm-lease-manager) | drm-lease-manager support |

The software renderer needs none of these: it renders through DRM dumb buffers, which Slint drives
directly without a C library. Font handling is separate from this table and needs fontconfig
(`libfontconfig-dev`) in every configuration.

## Selecting libseat and libinput

libseat provides access to the GPU and to input devices without running as root. libinput delivers
mouse, touch, and keyboard events. Both are optional, and how you select them differs between Rust
and C++.

<Tabs syncKey="dev-language">
<TabItem label="Rust" icon="seti:rust">

Disable the default features, select the `compat-1-18` feature, and then combine
`backend-linuxkms` with the capabilities you need:

| Cargo features                                             | libseat | libinput |
|------------------------------------------------------------|---------|----------|
| `backend-linuxkms`                                         | no      | no       |
| `backend-linuxkms-libseat`                                 | yes     | no       |
| `backend-linuxkms-libinput`                                | no      | yes      |
| `backend-linuxkms-libseat` and `backend-linuxkms-libinput` | yes     | yes      |

```toml
[dependencies]
slint = { version = "1.18.0", default-features = false, features = [
    "compat-1-18",
    "backend-linuxkms",
    "backend-linuxkms-libinput",
    "renderer-software",
] }
```

With the default features instead, the `compat-1-2` feature is enabled and `backend-linuxkms`
implies libseat and libinput, as it did before Slint 1.18.

The `backend-linuxkms-noseat` feature is deprecated; use `backend-linuxkms-libinput`, which selects
the same combination.

</TabItem>
<TabItem label="C++" icon="seti:cpp">

`SLINT_FEATURE_BACKEND_LINUXKMS` enables the backend with both libraries and turns either off
when you don't need it. `_LIBSEAT` and `_LIBINPUT` also enable the backend on their own and
combine, so `SLINT_FEATURE_BACKEND_LINUXKMS` is not a prerequisite:

| CMake options                                                               | libseat | libinput |
|-----------------------------------------------------------------------------|---------|----------|
| `SLINT_FEATURE_BACKEND_LINUXKMS`                                            | yes     | yes      |
| `SLINT_FEATURE_BACKEND_LINUXKMS` and `..._LIBSEAT=OFF`                      | no      | yes      |
| `SLINT_FEATURE_BACKEND_LINUXKMS` and `..._LIBSEAT=OFF` `..._LIBINPUT=OFF`   | no      | no       |
| `SLINT_FEATURE_BACKEND_LINUXKMS_LIBSEAT`                                    | yes     | no       |
| `SLINT_FEATURE_BACKEND_LINUXKMS_LIBINPUT`                                   | no      | yes      |
| `SLINT_FEATURE_BACKEND_LINUXKMS_LIBSEAT` and `..._LIBINPUT`                 | yes     | yes      |

```bash
cmake -DSLINT_FEATURE_BACKEND_LINUXKMS=ON ..
```

The configure output reports which of the two libraries the build ends up with.

`SLINT_FEATURE_BACKEND_LINUXKMS_NOSEAT` is deprecated; use
`SLINT_FEATURE_BACKEND_LINUXKMS_LIBINPUT`, which selects the same combination.

</TabItem>
</Tabs>

### Device Access With libseat

libseat manages access to the GPU and input devices through a seat manager such as logind or seatd.
It also manages the virtual console's keyboard and display modes.

Without libseat, run the application as a user with access to the input and DRM/KMS device files, typically root.
When libinput is enabled, Slint disables the active virtual console's keyboard while the event loop runs.
This prevents keystrokes, including passwords, from also reaching the shell on that console.
When your application renders to a legacy framebuffer device, such as `/dev/fb0`, Slint also switches the console to graphics mode while the event loop runs.
Graphics mode stops the text console from drawing over your user interface.
When the event loop exits, including during panic unwinding, Slint restores the console.
It flushes queued console input, restores the previous keyboard mode, and switches back to text mode.
Caught panics and panics in other threads don't restore the console while the event loop is still running.
If disabling the keyboard fails, Slint warns and continues; keystrokes may still reach the console.

Slint also restores the console before terminating on `SIGINT`, `SIGTERM`, or `SIGHUP`.
The process still terminates by the original signal.
Signals already handled or ignored by the application keep their existing behavior.
Install application handlers before starting the event loop.
Set `SLINT_KMS_NO_SIGNAL_HANDLER=1` before launching the application to disable Slint's signal handlers.
The application then owns restoration on signals; normal event-loop cleanup still restores the console.

`SIGKILL` and aborting panics can't restore the console through this cleanup.
If your application renders to a legacy framebuffer device, switch to a different console from SSH to recover.
For example, if `/dev/tty1` is affected, run `sudo chvt 2`.
The switch resets the affected console to text mode and re-enables its keyboard.
Otherwise, if the keyboard stays disabled, run `sudo kbd_mode -f -u -C /dev/tty1` from SSH or another console.
Replace `/dev/tty1` with the affected console; `-u` selects Unicode mode.

### Input Events With libinput

libinput reads mouse, touch, and keyboard events from input devices.
Without libinput, the application renders but receives no input events.
The <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Backspace</kbd> shortcut for quitting the application is then unavailable.
Quit the event loop from a timer or another thread instead.

## Renderers

The LinuxKMS backend supports different renderers. They can be explicitly selected for use through the
`SLINT_BACKEND` environment variable.

| Renderer name  | Required Graphics APIs | `SLINT_BACKEND` value to select renderer                                    |
|----------------|------------------------|-----------------------------------------------------------------------------|
| FemtoVG        | OpenGL ES 2.0          | `linuxkms-femtovg`                                                          |
| FemtoVG (wgpu) | Vulkan                 | `linuxkms-femtovg-wgpu`                                                     |
| Skia           | OpenGL ES 2.0, Vulkan  | `linuxkms-skia-opengl` or `linuxkms-skia-vulkan` |
| Skia software  | None                   | `linuxkms-skia-software` |
| Software       | None                   | `linuxkms-software`                                                         |

The Skia Vulkan and FemtoVG wgpu renderers show their frames through the Vulkan KHR Display Extension where the driver offers `VK_EXT_acquire_drm_display`.
Elsewhere they render into GBM buffers and show them with a DRM page flip.
Set the `SLINT_KMS_WGPU_DMABUF` environment variable, to any value, to use GBM buffers even where the extension is available.

:::note[Note]
This backend is still experimental. The backend has not undergone a great variety of testing on different devices
and there are [known issues](https://github.com/slint-ui/slint/labels/a%3Abackend-linuxkms).
:::

Enable the Rust `renderer-skia-software` feature together with a Linux KMS backend feature
to compile Skia's CPU rendering path without a GPU renderer.

## Display Selection

All renderers use Linux's direct rendering manager (DRM) subsystem to configure display outputs. Slint defaults to selecting the first connected
display and configures it at its preferred mode.
Without a preferred mode, Slint keeps the mode the display already shows, for example from the console or a boot splash.
Otherwise it picks the highest resolution at its highest refresh rate.
Set the `SLINT_DRM_OUTPUT`
environment variable to select a specific display. To get a list of available outputs, set `SLINT_DRM_OUTPUT`
to `list`, run your program, and observe the output.

For example, the output may look like this on a laptop with a built-in screen (eDP-1) and an externally
connected monitor (DP-3):

```
DRM Output List Requested:
eDP-1 (connected: true)
DP-1 (connected: false)
DP-2 (connected: false)
DP-3 (connected: true)
DP-4 (connected: false)
```

Setting `SLINT_DRM_OUTPUT` to `DP-3` will render on the second monitor.

To select a specific resolution and refresh rate (mode), set the `SLINT_DRM_MODE` variable. Set it to `list` and
run your program to get a list of available modes. For example the program output could look like this:

```
DRM Mode List Requested:
Index: 0 Width: 3840 Height: 2160 Refresh Rate: 60
Index: 1 Width: 3840 Height: 2160 Refresh Rate: 50
Index: 2 Width: 3840 Height: 2160 Refresh Rate: 30
Index: 3 Width: 2560 Height: 1440 Refresh Rate: 59
Index: 4 Width: 1920 Height: 1080 Refresh Rate: 60
Index: 5 Width: 1680 Height: 1050 Refresh Rate: 59
...
```

Set `SLINT_DRM_MODE` to `4` to select 1920x1080@60.

To select a resolution without depending on its index, set `SLINT_DRM_MODE` to
`WIDTHxHEIGHT`, for example `1920x1080`.
The resolution must match a mode advertised by the selected output; this doesn't create a custom mode.
When several modes match, preferred modes take precedence, then the highest refresh rate wins.
To select a specific refresh rate, append it in whole hertz as `list` shows it, for example `1920x1080@50`.
An unavailable resolution or invalid value fails DRM initialization.
Software renderers may then fall back to the legacy Linux framebuffer, where this setting has no effect.

## DRM Leasing

Instead of opening a card from `/dev/dri` itself, the backend can render on a pre-leased DRM device:
a [DRM *lease*](https://www.kernel.org/doc/html/latest/gpu/drm-uapi.html#drm-leases) that exposes
only a specific connector, CRTC and planes. This lets Slint drive one output while another DRM
master (for example a Wayland compositor, or another application) owns the rest of the same GPU, and
is how Slint runs as a native application under the
[AGL drm-lease-manager](https://github.com/AGLExport/drm-lease-manager).

Set the `SLINT_DRM_LEASE_FD` environment variable to the number of an already-open, inherited DRM
lease file descriptor. When set, the backend uses that descriptor directly and skips the `/dev/dri`
scan as well as `SLINT_DRM_OUTPUT`-based selection (a lease only contains its own connector). The
backend takes ownership of the descriptor.

This is typically used together with a launcher that creates the lease and passes the descriptor to
the Slint process. For example, a launcher that obtained lease descriptor `7` would run the
application with `SLINT_DRM_LEASE_FD=7`.

### drm-lease-manager

Alternatively, the backend can obtain the lease directly from the
[AGL drm-lease-manager](https://github.com/AGLExport/drm-lease-manager) instead of receiving a file
descriptor. This needs the manager's client library, `libdlmclient`: enable the
`backend-linuxkms-libdlmclient` Cargo feature (`SLINT_FEATURE_BACKEND_LINUXKMS_LIBDLMCLIENT` in
CMake), which links it via pkg-config. If pkg-config can't find the library, the build prints a
warning and the feature does nothing. Set the `SLINT_DRM_LEASE_NAME` environment variable to the
lease name managed by the daemon (for example `card0-HDMI-A-1`); the backend then requests that
lease and renders on it. `SLINT_DRM_LEASE_FD` takes precedence if both are set.

## Configuring the Keyboard

By default the keyboard layout and model is assumed to be a US model and layout. Set the following
environment variables to configure support for different keyboards:

* `XKB_DEFAULT_LAYOUT`: A comma separated list of layouts (languages) to include in the keymap.
  See the layouts section in [xkeyboard-config(7)](https://manpages.debian.org/testing/xkb-data/xkeyboard-config.7.en.html) for a list of accepted language codes.
  for a list of supported layouts.
* `XKB_DEFAULT_MODEL`: The keyboard model by which to interpreter keys. See the models section in
  [xkeyboard-config(7)](https://manpages.debian.org/testing/xkb-data/xkeyboard-config.7.en.html) for a list of accepted model codes.
* `XKB_DEFAULT_VARIANT`: A comma separated list of variants, one per layout, which configures layout specific variants. See the values in parentheses in the layouts section in [xkeyboard-config(7)](https://manpages.debian.org/testing/xkb-data/xkeyboard-config.7.en.html) for a list of accepted variant codes.
* `XKB_DEFAULT_OPTIONS`: A comma separated list of options to configure layout-independent key combinations. See the
  options section in
  [xkeyboard-config(7)](https://manpages.debian.org/testing/xkb-data/xkeyboard-config.7.en.html) for a list of accepted option codes.

## Display Rotation

If your display's default orientation does not match the desired orientation of your user interface, then you can
set the `SLINT_KMS_ROTATION` environment variable to instruct Slint to rotate at rendering time. Supported values
are the rotation in degrees: `0`, `90`, `180`, and `270`.

Note that this variable merely rotates the rendering output. If you're using a touch screen attached to the same
display, then you may need to configure it to also apply a rotation on the touch events generated. For configuring
libinput's `LIBINPUT_CALIBRATION_MATRIX` see the [libinput Documentation](https://wayland.freedesktop.org/libinput/doc/latest/device-configuration-via-udev.html#static-device-configuration-via-udev)
for a list of valid values. Values can typically be set by writing them into a rules file under `/etc/udev/rules.d`.

The following example configures libinput to apply a 90 degree clockwise rotation for any attached touch screen:

```bash
echo 'ENV{LIBINPUT_CALIBRATION_MATRIX}="0 -1 1 1 0 0"' > /etc/udev/rules.d/libinput.rules
udevadm control --reload-rules
udevadm trigger
```

## Legacy LinuxFB Interface

For software rendering, DRM dumb buffers are the preferred default way of posting frame buffers to the display. If DRM dumb buffers are not supported, the LinuxKMS backend falls back to using the Linux legacy
framebuffer interface (`/dev/fbX`).

To override this default and use only the legacy framebuffer interface, set the `SLINT_BACKEND_LINUXFB=1` environment variable.