Linux Desktop

Devices/linux-desktop runs Tactility on 64-bit Linux computers, with the hardware of the computer instead of mock devices. See Linux Desktop for how users install and run it. This page is about how it's built and put together.

Selecting the device

The POSIX build is the simulator by default. Select another device from Devices/ with TT_POSIX_DEVICE:

cmake -B build-linux-desktop -G Ninja -DTT_POSIX_DEVICE=linux-desktop

The vendor and name in device.properties set the device name that System Info shows, and the device id is the folder name.

Building for this computer

Install the development files of D-Bus (e.g. dbus-devel on Fedora or libdbus-1-dev on Debian), and the dependencies of the simulator. The DRM headers come with the kernel headers.

The code generators need these Python packages, in the Python that CMake finds first:

python3 -m venv ~/.venvs/tactility
~/.venvs/tactility/bin/pip install -r Libraries/mbedtls/scripts/driver.requirements.txt lark==1.3.1 pyyaml==6.0.3

Don't build in an ESP-IDF shell: with ESP_IDF_VERSION set, the top-level CMakeLists.txt takes the ESP32 path.

env -u ESP_IDF_VERSION -u IDF_PATH PATH=$HOME/.venvs/tactility/bin:/usr/local/bin:/usr/bin cmake -B build-linux-desktop -G Ninja -DTT_POSIX_DEVICE=linux-desktop
env -u ESP_IDF_VERSION -u IDF_PATH PATH=$HOME/.venvs/tactility/bin:/usr/local/bin:/usr/bin ninja -C build-linux-desktop Tactility
./build-linux-desktop/Tactility/Tactility --windowed

CMake caches the Python that it found, so delete the build folder after changing it.

Building releases

Release builds run in a container (podman or docker), so that the binary runs on Debian 12 and newer, whatever the host runs:

Buildscripts/build-linux.sh <aarch64|x86_64> [device] [build_dir] [targets...]

For example, Buildscripts/build-linux.sh aarch64 builds linux-desktop for 64-bit ARM into build-linux-aarch64. The targets default to Tactility.

The recipe is in Buildscripts/linux/:

  • build-image.sh <engine> <architecture> <image>: builds the images below, in this order. build-linux.sh and tt both use it.
  • Containerfile.sysroot: the libraries and headers of Debian bookworm for the target architecture. The platform is passed on the command line (--platform linux/arm64), because older container engines, such as the podman of the GitHub runners, ignore it in a Containerfile and then use the host's architecture. The file checks the architecture and fails when it's wrong. It runs under qemu when the architecture isn't the host's, which is only slow once.
  • Containerfile: GCC 14 from Debian trixie, which C++23 needs, with the sysroot copied from the first image. The binary therefore needs glibc 2.36 at the most. The architecture is a build argument.
  • toolchain.cmake: uses the sysroot, links libstdc++ statically, and puts the sysroot's library folder before the compiler's own.
  • isoc23_compat.c: the static libstdc++ of GCC 14 calls the C23 variants of strtol and friends, which glibc 2.36 doesn't have. This forwards them to the classic ones.

Buildscripts/release-linux-desktop.sh <build_dir> <target_path> packages the build with install.sh, the icon and the version. The "Build Linux Desktop" job of the build workflow does both for aarch64 and x86_64, and uploads Tactility-linux-desktop-<architecture>.tar.gz as the workflow artifact LinuxDesktop-<architecture>.

Publishing

The simulator (simulator-linux-x86_64, simulator-macos-arm64) and the Linux desktop builds (linux-desktop-aarch64, linux-desktop-x86_64) are published to the CDN with the firmwares, to firmware/<channel>/<device id>.json. The manifest has the name, version, git commit, creation time, and the file, size and sha256 of a single zip. They're not listed in index.json, which is for the firmwares that the web installer flashes.

The zip is named <device id>-<commit>-Tactility.zip, so every build has files of its own and a manifest that was read before the next publish still refers to existing files. The uploader keeps the files of the newest build and of one older build, and deletes the rest. The zips are made by Buildscripts/CDN/generate-firmware-files.py from the artifacts Simulator-<os>-<architecture> and LinuxDesktop-<architecture>, and mark Tactility and *.sh as executable again, as workflow artifacts lose permissions.

Project Purpose
Devices/linux-desktop The device: startup, modes, DRM display, evdev input and battery
Drivers/sdl-module The SDL display, input and audio drivers and the SDL main loop. Shared with the simulator
Platforms/platform-posix posix_host_start() (starts FreeRTOS next to the main thread) and the Linux GPIO driver posix,linux-gpio
Drivers/networkmanager-module Wi-Fi through NetworkManager (freedesktop,networkmanager-wifi)
Drivers/bluez-module Bluetooth through BlueZ (bluez,bluetooth)

The devicetree (linux-desktop.dts) only lists the hardware that exists on every computer or that Tactility can find: gpio0 (/dev/gpiochip0, 28 lines), wifi0 and bluetooth0. Their drivers have a probe() function that reports ERROR_NOT_FOUND when the computer doesn't have the hardware, so those devices are left out and the boot continues. The display, input and battery are created in code, because they depend on the mode.

Modes

prepare() in LinuxDesktop.cpp picks the mode from the arguments and prepares the process: the data/ folder next to the executable and the screen size.

Desktop Kiosk (--kiosk)
Display sdl-display, a window of the desktop drm-display, the first DRM card with a connected screen at its preferred mode
Input sdl-touch (mouse) and sdl-keyboard evdev-touch, evdev-mouse and evdev-keyboard
Main thread The SDL main loop Waits for the exit event
Power off Exits systemctl poweroff, which needs the active console session

The SDL window of the desktop mode has one pixel of the display per pixel of the screen (native_pixels in SdlDisplayConfig), unlike the simulator, which sizes its window by the DPI to imitate the physical size of a device.

The kiosk mode takes over the console: it sets the console to graphics mode and the keyboard to off, and restores both at exit, also when the process gets SIGTERM or SIGHUP. A handler writes to an eventfd that the main thread waits on, because the signal can arrive on any FreeRTOS thread. The DRM driver uses the kernel's ioctls directly, without libdrm. The frame buffer is RGB565 in a dumb buffer.

The evdev driver reads /dev/input/event* on one thread, and picks up devices that appear later. When the kinds of input devices change, it adds or removes the touch, mouse and keyboard devices. A device that is still referenced when it disappears (e.g. by standby) is destructed later. The mouse cursor stays hidden until the mouse moves or a button is pressed, as some keyboards report a mouse that is never used.

Threads on POSIX

Tasks and threads of Tactility run on the POSIX port of FreeRTOS, and it only runs one task at a time. A task that blocks in a system call, or on an operating system mutex, can stop the whole scheduler. Code in drivers for POSIX therefore:

  • polls without waiting (e.g. poll() with a timeout of 0, followed by delay_millis()) instead of blocking
  • uses the kernel's Mutex (tactility/concurrent/mutex.h), not std::mutex
  • keeps its blocking calls short, like the D-Bus calls of the NetworkManager and BlueZ drivers

Wi-Fi and Bluetooth drivers

Both drivers talk to the system bus of D-Bus with libdbus. A worker thread reads the state of NetworkManager or BlueZ every 200 to 250 ms, compares it with the last state, and sends the differences to the subscribers as WifiEvents and BtEvents. The system keeps the pairings and the saved networks.

  • The Wi-Fi driver gives each connection attempt a generation, so that a state that was read before the attempt can't complete it. The new connection of a password replaces the old saved ones when it connects, and is deleted when it doesn't. The attempt and the scan have deadlines that also apply when NetworkManager can't be read.
  • The Bluetooth driver registers a pairing agent with the capability NoInputNoOutput. The agent only approves pairings that Tactility started, and services of devices that are paired already. A new subscriber gets the HID devices that are connected already. The Bluetooth service attaches to the Bluetooth device when it starts, also when that's after the service, because the driver's probe() runs after boot.

Testing on a Raspberry Pi

  1. Build with Buildscripts/build-linux.sh aarch64 and package with release-linux-desktop.sh.
  2. Copy the folder to the Pi, for example with rsync -a --exclude data <folder>/ <user>@<host>:tactility/.
  3. For the desktop mode, start it from a terminal on the Pi, or over ssh with DISPLAY=:0. Without DISPLAY, SDL picks its Wayland backend, and creating the window hangs on Raspberry Pi OS (Wayfire). That isn't solved yet. With DISPLAY set, SDL uses XWayland.
  4. For kiosk mode, stop the display manager first (e.g. sudo systemctl stop lightdm).