Prerequisites
Required Dependencies
The Linux build requires X11 development libraries:- Ubuntu/Debian
- Fedora/RHEL
- Arch Linux
Build Tools
Ensure you have CMake and a C++17 compiler:Building for Linux
Using the Build Script
The quickest way to build for Linux:build.sh
Using CMake Directly
Linux Renderer Implementation
The Linux renderer (linux_renderer.cpp) implements the PlatformRenderer interface using X11.
Key Features
X11 Window Management
X11 Window Management
Creates a native X11 window with support for:
- Window resizing
- Close events (WM_DELETE_WINDOW)
- Focus management (WM_TAKE_FOCUS)
- Window title updates
Direct Pixel Rendering
Direct Pixel Rendering
Uses
XImage for direct pixel buffer manipulation:linux_renderer.cpp:316-325
Input Method Support
Input Method Support
Supports complex text input using X Input Method (XIM):
linux_renderer.cpp:122-134
Event Handling
Event Handling
Processes X11 events including:
- Mouse motion and clicks
- Keyboard input (key presses, text input)
- Window resize and configuration
- Focus changes
Compilation Flags
The build script uses these flags for Linux:build.sh:139-146
CMake Configuration
CMake automatically finds X11 libraries:CMakeLists.txt:84-98
Key Code Translation
The Linux renderer translates X11 KeySyms to Fern’s cross-platform KeyCode enum:linux_renderer.cpp:34-83
Running Linux Applications
After building, run the executable:Troubleshooting
Cannot connect to X server
Cannot connect to X server
Error:
Cannot connect to X server. Is DISPLAY set?Solution: Ensure DISPLAY is set:Missing X11 libraries
Missing X11 libraries
Error:
X11/Xlib.h: No such file or directorySolution: Install X11 development packages:Font rendering issues
Font rendering issues
Error: Font-related compilation or runtime errorsSolution: Install fontconfig and freetype:
Performance Considerations
Pixel Buffer Updates
The renderer usesmemcpy for efficient pixel buffer transfers:
linux_renderer.cpp:174
Event Processing
Events are processed in batches duringpollEvents():
linux_renderer.cpp:196-198
Platform Detection at Runtime
Your application can query the platform at runtime:Next Steps
Web/WASM
Compile the same code to WebAssembly
Platform Overview
Learn about cross-platform architecture