godotengine/godot
Linux / BSD
Purpose
platform/linuxbsd/ is the Linux and BSD platform layer. It supplies an OS_LinuxBSD subclass, two display server implementations (X11 and Wayland), Linux-specific exporters, and crash handler / joypad / accessibility integration. The same codebase covers Linux distros and BSD variants where supported toolchains exist.
Layout
platform/linuxbsd/
├── godot_linuxbsd.cpp Application entry: instantiate OS, create DisplayServer, run Main
├── os_linuxbsd.{cpp,h} OS_LinuxBSD subclass (file system, environment, processes)
├── x11/ X11 display server (DisplayServerX11 + key codes + DnD + IME)
├── wayland/ Wayland display server (DisplayServerWayland + EGL/Vulkan integration)
├── crash_handler_linuxbsd.{cpp,h} Backtrace via libbacktrace + signal handler
├── joypad_linux.{cpp,h} evdev-based joypad / gamepad
├── freedesktop_screensaver.{cpp,h} D-Bus calls to inhibit the screen saver
├── freedesktop_portal_desktop.{cpp,h} XDG Desktop Portal integration (file dialogs, inhibitors)
├── tts_linux.{cpp,h} speech-dispatcher TTS bindings
├── export/ Linux exporter (binary stripping + AppImage-style packaging)
├── detect.py Build options (use_pulseaudio, use_alsa, use_dbus, …)
└── SCsubDisplay server choices
DisplayServer for Linux comes in two flavours selected at runtime by --display-driver:
- X11 (
x11/display_server_x11.cpp) — the historical Linux backend. Mature, ubiquitous, good fallback. Handles XInput2 for tablet / multi-touch, XRandR for screen enumeration, the X clipboard primary/secondary distinction, and IME via XIM/IBus. - Wayland (
wayland/display_server_wayland.cpp) — the modern Linux compositor protocol. Uses xdg-shell, xdg-decoration, wlr-output-management, fractional-scale-v1 where compositors expose them. Builds againstwayland-client+ the auto-generated protocol marshalling.
The default is X11 on legacy distros, Wayland where the compositor advertises support; the user can override with DISPLAY / WAYLAND_DISPLAY and --display-driver.
Both servers create graphics contexts:
- Vulkan via
VK_KHR_xlib_surface/VK_KHR_wayland_surface. - OpenGL ES 3 via EGL on both backends, or GLX on X11.
OS_LinuxBSD
OS_LinuxBSD (os_linuxbsd.cpp) implements:
- File system root (
/), user data dir (~/.local/share/godot/), config dir (~/.config/godot/). - Process spawning via
execvp+posix_spawn. - Environment variables, command-line argument parsing, locale detection (
setlocale,nl_langinfo). - Dynamic library loading via
dlopen. - Power management (battery info via UPower or
/sys). - Stack-trace capture for crash handler via libbacktrace.
The implementation often falls back gracefully when optional libraries (D-Bus, speech-dispatcher, libudev) are absent; build flags in detect.py control whether they are linked at all.
D-Bus integration
Two D-Bus integrations:
- Screensaver inhibition (
freedesktop_screensaver.cpp) — callsorg.freedesktop.ScreenSaver.Inhibitso games don't get blanked. - XDG Desktop Portal (
freedesktop_portal_desktop.cpp) — calls portals for native file dialogs (in flatpak / sandboxed environments where direct fs access is restricted), and for accessibility / inhibitor APIs.
Joypad
joypad_linux.cpp walks /dev/input/event* via libevdev, probes capabilities (axes, buttons, force feedback), and reports devices to Input. The Steam controller and most Bluetooth gamepads work out of the box; SDL game controller mappings (gamecontrollerdb.txt) are honored.
TTS / accessibility
tts_linux.cpp integrates speech-dispatcher when present so the engine can speak text via DisplayServer::tts_*. The accesskit module (cross-platform) plus AT-SPI provides the screen-reader bridge.
Audio
Linux ships with two audio drivers, both under drivers/:
- PulseAudio — default; works alongside PipeWire's PulseAudio compatibility layer.
- ALSA — direct hardware access; lower latency for users with non-Pulse setups.
- MIDI — ALSA MIDI (
drivers/alsamidi/).
Export
export/export_plugin.cpp packages a Linux build:
- Strips the binary if requested.
- Bundles the PCK alongside (or appends it to the binary).
- Optionally embeds an icon via PNG metadata for desktop environments that read it.
Toolchain
detect.py configures GCC / Clang, with optional cross-compilation via MinGW (Linux → Windows) handled by the Windows platform's detect.py.
Key abstractions
| Abstraction | File | Role |
|---|---|---|
OS_LinuxBSD |
platform/linuxbsd/os_linuxbsd.cpp |
OS subclass |
DisplayServerX11 |
platform/linuxbsd/x11/display_server_x11.cpp |
X11 backend |
DisplayServerWayland |
platform/linuxbsd/wayland/display_server_wayland.cpp |
Wayland backend |
JoypadLinux |
platform/linuxbsd/joypad_linux.cpp |
evdev gamepad input |
CrashHandlerLinuxBSD |
platform/linuxbsd/crash_handler_linuxbsd.cpp |
Stack trace on signals |
EditorExportPlatformLinuxBSD |
platform/linuxbsd/export/export_plugin.cpp |
Linux exporter |
Entry points for modification
- New display protocol → drop a new directory next to
x11/andwayland/, implementDisplayServer, register inos_linuxbsd.cpp. - New exporter feature →
export/export_plugin.cpp. - Joypad mapping fixes →
joypad_linux.cppor updategamecontrollerdb.txt.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.