This document is for contributors and maintainers. End-user docs live in docs/. The README has the user-facing tour; this file explains how the launcher is built and why the boundaries are where they are.
Goals
The launcher is a desktop Linux app, not a server, so the design priorities are:
- Daily-driver reliability. The user's library, save state, and playtime are not allowed to corrupt under crashes, mid-launch interrupts, or concurrent edits.
- Headless-testable core. Everything that isn't UI rendering is in core/ and links into a static library (gamelauncher_core) the test suite consumes without spinning up Qt widgets.
- Replaceable UI. The ui/qt/ frontend depends on gamelauncher_core but never the other way around. A different frontend (GTK, terminal) could be added without touching core/.
- Predictable concurrency. The launcher runs several long-lived background threads (Steam process monitor, game-detection scanner, frame-metrics reader, image loader). Each has a well-defined lock that protects its mutable state, and the rules for crossing thread boundaries are documented per-service rather than ad hoc.
Layers
┌────────────────────────────────────┐
│ ui/qt/ (Qt 6) │
│ MainWindow + dialogs + widgets │
│ (presentation only) │
└─────────────┬──────────────────────┘
│ (no reverse arrow)
▼
┌────────────────────────────────────┐
│ core/{include,src}/controllers/ │
│ Coordinate models + services │
│ for the UI; emit events │
└─────────────┬──────────────────────┘
▼
┌────────────────────────────────────┐
│ core/src/{models,services, │
│ integrations,util}/ (logic) │
│ Game, GameLibrary, ProtonDB, │
│ SteamIntegration, logger, … │
└─────────────┬──────────────────────┘
▼
┌────────────────────────────────────┐
│ core/src/platform/{linux,windows} │
│ POSIX / Win32 wrappers, fork+exec, │
│ /proc walking, paths │
└────────────────────────────────────┘
The arrows are strictly downward. CMake enforces this with a static-lib boundary: gamelauncher_core is a regular static library; the Qt UI target links against it but the reverse can never compile because core/ doesn't list any UI sources or Qt6::* link dependencies.
core/include/, core/src/
The whole core library follows a strict header / implementation split: public headers under core/include/<subdir>/, implementations under core/src/<subdir>/. Subdirectories are mirrored across both roots so every core/include/<x>/foo.h has a matching core/src/<x>/foo.cpp (or a templated header-only file with no impl).
- core/include/models/ + core/src/models/ — pure data / state classes. Just five pairs: game, game_library, launch_manager, proton_cache, frame_metrics. Anything that does something (I/O, orchestration, third-party integration) lives in one of the sibling subdirs below.
- core/include/controllers/ + core/src/controllers/ — thin glue between models and the UI. Controllers don't own data; they coordinate models, expose callback-based event APIs, and handle threading transitions (typically: model edits on a worker thread, callbacks marshalled back to the Qt main thread).
- core/include/services/ + core/src/services/ — two flavours of service co-locate here:
- Abstract Qt-bridge interfaces (INotificationService, IImageService) implemented by the Qt UI as QtNotificationService / QtImageService. This is what makes the core layer UI-replaceable.
- Concrete domain services — behaviour, I/O, orchestration that isn't tied to a specific UI: protondb_service, hltb_service, steamgriddb_service, runner_download_service, game_database (SQLite), game_session_service, performance_profile_service, system_info_service, task_scheduler, etc. (~22 pairs.)
- core/include/integrations/ + core/src/integrations/ — third-party adapters. Each translates between this project's data/services and an external system: steam_integration (libraryVDF, Proton compat tools), steam_appinfo_parser (binary VDF decoder), lutris_config (installer-script runtime), gog_integration, legendary_integration (Epic), umu_launcher, wine_dependency_manager, game_process (POSIX launch orchestration).
- core/include/platform/ + core/src/platform/{linux,windows}/ — POSIX/Linux + Win32 bits factored out so the cross-platform port has somewhere to live. Selected at compile time via PLATFORM_LINUX / PLATFORM_WINDOWS defines.
- core/include/util/ + core/src/util/ — small cross-cutting helpers: atomic_write, safe_enum_cast, logger, lru_cache, shell_utils, desktop_entry_utils, file_handle, steam_paths, steam_constants.
ui/qt/
Qt 6 frontend. ~41,600 LoC total (find ui/qt -name '*.cpp' | xargs
wc -l). The largest single TU is still mainwindow.cpp (~4,800 LoC), down from a peak of ~9,900 LoC after a multi-step decomposition pass. Each phase pulled responsibility into its own translation unit owned by MainWindow as a std::unique_ptr<...>:
| Manager / controller | Owns | Translation unit |
| DetailsPanelManager | Right-hand details panel + hero image rendering | ui/qt/managers/details_panel_manager.{h,cpp} |
| GameThumbnailCache | LRU pixmap cache for the game grid + async refresh worker | ui/qt/managers/game_thumbnail_cache.{h,cpp} |
| ToolbarManager | Top toolbar tree (search, view modes, panel toggles, drag handles) | ui/qt/managers/toolbar_manager.{h,cpp} |
| SidebarManager | Left sidebar — categories / sources / runners / collections lists | ui/qt/managers/sidebar_manager.{h,cpp} |
| MenuBarManager | Full File / Game / View / Tools / Help menubar | ui/qt/managers/menubar_manager.{h,cpp} |
| ContextMenuManager | Game-list right-click menu (uses GameActionFactory) | ui/qt/managers/context_menu_manager.{h,cpp} |
| GameActionFactory | Shared per-game action construction reused by menubar + context | ui/qt/managers/game_action_factory.{h,cpp} |
| ShortcutsController | All keyboard-shortcut + command-palette registration (friend class) | ui/qt/shortcuts_controller.{h,cpp} |
mainwindow.cpp is still the central composition root — it holds the unique_ptr<...Controller> instances and the manager unique_ptrs, owns the splitter layout, and wires manager signals to controller callbacks. The remaining 4,800 LoC is mostly composition-level logic that doesn't naturally peel out: panel geometry, pop-out windows, the gaming-layout state machine, tray-icon plumbing, and the start/stop event-loop bridges between controller signals and the UI.
Subdirectory layout
ui/qt/
├── main.cpp # entry point (CLI parsing, QApplication setup,
│ # SIGTERM self-pipe, theme/style init)
├── mainwindow.{h,cpp} # composition root — owns controllers + managers
├── theme_manager.{h,cpp} # ThemeManager singleton consumed everywhere
├── shortcut_manager.{h,cpp}# ShortcutManager singleton (registry of shortcuts)
├── command_palette.{h,cpp} # global Ctrl-P palette (registers commands)
├── env_var_mapping.{h,cpp} # static registry of "known" env vars used by
│ # the launch path + dialogs
├── a11y_utils.h # AccessibleRoles helpers, header-only
├── dpr_utils.h # device-pixel-ratio scaling helpers, header-only
├── icon_font.h # Font Awesome glyph constants, header-only
├── shortcuts_controller.{h,cpp} # friend class — keyboard shortcuts +
│ # command-palette registration
├── managers/ # composition-level managers (own subwidgets)
│ ├── details_panel_manager.{h,cpp}
│ ├── game_thumbnail_cache.{h,cpp}
│ ├── toolbar_manager.{h,cpp}
│ ├── sidebar_manager.{h,cpp}
│ ├── menubar_manager.{h,cpp}
│ ├── context_menu_manager.{h,cpp}
│ └── game_action_factory.{h,cpp}
├── dialogs/ # modal/non-modal dialogs + first-run wizard
│ ├── settingsdialog.{h,cpp} gameconfigdialog.{h,cpp}
│ ├── addgamedialog.{h,cpp} gameimportdialog.{h,cpp}
│ ├── lutrissearchdialog.{h,cpp} lutrisinstallpreviewdialog.{h,cpp}
│ ├── lutrisinstallprogressdialog.{h,cpp}
│ ├── runner_manager_dialog.{h,cpp}
│ ├── prefix_snapshot_dialog.{h,cpp}
│ ├── performance_profile_dialog.{h,cpp}
│ ├── library_export_dialog.{h,cpp}
│ ├── game_verification_dialog.{h,cpp}
│ ├── game_statistics_dialog.{h,cpp}
│ ├── download_queue_dialog.{h,cpp}
│ ├── wine_dependency_dialog.{h,cpp}
│ ├── steamgriddb_selector_dialog.{h,cpp}
│ ├── shortcut_cheatsheet.{h,cpp}
│ └── first_run_wizard.{h,cpp}
├── widgets/ # custom widgets, list models + delegates
│ ├── game_list_model.{h,cpp} game_list_proxy_model.{h,cpp}
│ ├── game_list_delegate.{h,cpp}
│ ├── sidebar_models.{h,cpp} # QAbstractListModels for the sidebar
│ ├── async_image_loader.{h,cpp} loading_widgets.{h,cpp}
│ ├── frame_metrics_widget.{h,cpp}
│ ├── running_game_status_widget.{h,cpp}
│ ├── recommendations_widget.{h,cpp}
│ ├── system_readiness_widget.{h,cpp}
│ ├── status_indicators.{h,cpp}
│ ├── homeassistant_panel.{h,cpp}
│ ├── terminalpanel.{h,cpp}
│ ├── draggable_toolbar.{h,cpp} toolbar_drag_handle.{h,cpp}
│ ├── env_var_checkbox.{h,cpp}
│ └── collapsible_section.h (header-only)
└── services/ # Qt implementations of core service interfaces
├── qt_image_service.{h,cpp}
└── qt_notification_service.{h,cpp}
Cross-includes use the subdirectory path (#include "dialogs/settingsdialog.h", #include "widgets/game_list_model.h") since ui/qt/ is the only include root for the Qt UI target.
Tests
tests/ builds a separate set of executables that link gamelauncher_core (and selectively a few ui/qt/*.cpp files for QAbstractListModel tests, but never mainwindow.cpp). Tests use GoogleTest 1.15.2 fetched at configure time. See CONTRIBUTING.md for the test-discovery details.
Threads
The launcher process runs the Qt main thread plus several long-lived background threads. Each one has its own lock (or atomic state) and its rules for crossing back to the main thread.
| Thread | Owner | Purpose | How it talks to the main thread |
| Qt main | QApplication | UI events, painting, slot dispatch | (it is the main thread) |
| Game detection | GameProcessManager | Walks /proc, scans pgrep for running games every ~1s | getGameCallback_ (lock-protected callback set by LaunchController) |
| Steam process monitor | SteamProcessMonitor | Polls pgrep -x steam to fire RUNNING/NOT_RUNNING transitions | setStateCallback() — the callback runs on the monitor thread; consumers QMetaObject::invokeMethod(..., QueuedConnection) |
| Frame metrics reader | MangoHudLogReader / GamescopeMetricsReader | Tails MangoHud CSV / reads SysV msgqueue every 100ms | getMetrics() returns a struct copy under a per-reader mutex |
| Image loader pool | AsyncImageLoader | QtConcurrent pool for decoding cover art | Qt signals (auto-marshalled queued) |
| Steam-update monitor | SteamUpdateMonitor | 5-minute poll for available updates | Callback set by MainWindow; signals queued via QMetaObject |
| Download workers | RunnerDownloadService / FileDownloadService | One std::future per active download, libcurl per-download | Progress via std::function callbacks invoked on the worker thread |
| Cleanup timer (logs) | MainWindow QTimer | Re-runs cleanupOldLogs() every 6h | (already on the main thread) |
Synchronisation primitives the project uses
- std::mutex + std::lock_guard — most service-level locks. Each service documents what its mutex protects. Locks are held for short durations only; never across blocking I/O.
- std::recursive_mutex — only GameDatabase::mutex_, because the API has methods that legitimately call other public methods internally (e.g. addGameToCollection → addGameToCollectionInternal).
- std::atomic<bool> — cancel flags on long-running operations (downloads, verifications, snapshots). Convention: release store on the canceller, acquire load on the worker. See runner_download_service.cpp for the documented pattern.
- std::atomic<int> — counters (e.g. pendingRequests_).
- std::call_once — one-shot global init (curl_global_init, OpenSSL digest registration).
Snapshot-scan-mutate pattern
Several services follow this pattern when they need to do slow I/O under a guard that's also serving fast UI lookups:
- Acquire the lock.
- Copy the data you need to operate on into a local vector.
- Release the lock.
- Do the slow work (popen, /proc walk, network call).
- Re-acquire the lock to apply mutations, with a re-check that the state hasn't been replaced concurrently.
GameProcessManager::pollRunningSteamGames is the canonical example. Use this pattern when clang-tidy flags clang-analyzer-unix.BlockInCriticalSection.
Persistence
State is split across the XDG data, config, and state roots per the XDG Base Directory Spec:
| Location | Format | Contents |
| ~/.local/share/gamelauncher/games.db | SQLite 3 | Game library, collections, statistics. Schema version pinned in schema_version table. |
| ~/.config/gamelauncher/settings.json | JSON | App settings, theme, default runner, panel/gaming-layout preferences |
| ~/.local/state/gamelauncher/window-state.json | JSON | Panel visibility, window geometry (Base64), last view mode |
| ${XDG_STATE_HOME:-~/.local/state}/gamelauncher/ | per-feature | Logs, MangoHud per-launch configs, MangoHud CSV captures (when isolateMangoHudLogs=true). Per XDG Base Directory Spec. |
Schema migrations are explicitly NOT supported. GameDatabase::createSchema checks schema_version against the pinned SCHEMA_VERSION; on mismatch it logs an error and refuses to open. This is conservative — we'd rather fail loud than corrupt the user's library with a buggy migration. Bumping SCHEMA_VERSION requires the user to delete or back up their games.db.
Game objects round-trip to SQLite via per-field serialisation: Game::serializeRunnerConfig / serializeMetadata produce JSON for the nested struct columns; the inverse deserialize* re-parse them. There's no monolithic Game::serialize — that lived only in the removed .game text format and was deleted along with its callers.
A game launch, end-to-end
Tracing what happens when the user clicks Launch on a Steam game. Everything else is a variation of this flow.
User clicks Launch
│
▼
LaunchController::launchGame(gameId, game)
│ (publishes "PreparingLaunch" event,
│ fires onLaunchError if already running)
▼
GameLaunchManager::requestLaunch(game) (singleton, async)
│
▼ performLaunch() runs on its own thread
│
├─ checkAndSyncSettings()
│ └─ Build "<env vars> <wrappers> %command%" string
│ └─ Compare to current Steam VDF launch options
│ └─ Write via SteamLibraryScanner::writeSteamLaunchOptions
│ └─ If Proton version changed, restart Steam
│
├─ waitForSteam() (only for Steam games)
│
├─ executeLaunch()
│ └─ GameProcess::launch()
│ ├─ Steam game → launchProtonSteamGame
│ │ ├─ Direct mode (default off) → buildDirectProtonCommand
│ │ └─ Steam-managed (default on) → launchViaSteamApplaunch
│ │ └─ exec "steam -applaunch <appid>"
│ ├─ Wine game → launchWine
│ ├─ Native → launchNative
│ └─ DOSBox / ScummVM → respective handlers
│
├─ verifyGameStarted()
│ └─ GameProcessManager::isGameRunning(gameId)
│ └─ Checks runningSteamGames_ + runningProcesses_
│
└─ transitionTo(RUNNING) → COMPLETED
│
▼
UI receives state event, shows running game
Key invariants that fall out of this:
- runningSteamGames_ is the source of truth for Steam-managed launches. Every Steam-via--applaunch launch must register in this map before the launch returns; otherwise the background detection thread will re-discover the running game and double-track it.
- Direct-Proton vs Steam-managed routing must agree at every layer. GameProcessManager::launchGame's canDirectLaunch flag and GameProcess::launchProtonSteamGame's routing both read useSteamLaunchByDefault from the settings file. If they disagreed (which they did before commit 7f0ddd4), one path adds to runningProcesses_ while the other path adds to runningSteamGames_, and Stop hangs because neither map's kill* matches.
- Stop must mop up orphans the reaper missed. Some games (MTGA, certain Battle.net wrappers) double-fork the actual game process out of the Steam reaper's tree. killSteamGame runs three strategies in order: reaper-tree kill, then /proc/*/environ scan for SteamAppId=<id>, then steam://gamepadui/killgame/<id>. The detect-set (isSteamGameRunningOnSystem) uses the same env-scan so the kill-set and detect-set always match.
Subsystems worth knowing about
Frame metrics
Two readers behind a common interface (IFrameMetricsReader):
- MangoHudLogReader — the default. Tails MangoHud's CSV log file. We inject our own MangoHud config via MANGOHUD_CONFIGFILE (rather than the additive MANGOHUD_CONFIG env var) so user-installed ~/.config/MangoHud/MangoHud.conf doesn't override our log_duration=0. Per MangoHud's parseConfigFile, MANGOHUD_CONFIGFILE replaces the standard hierarchy rather than augmenting it.
- GamescopeMetricsReader — reads the SysV message queue gamescope publishes when run with --mangoapp. Note: this queue is destructive (msgrcv consumes), so it competes with the actual mangoapp binary; this reader is only useful when mangoapp itself isn't running.
Runner downloads
RunnerDownloadService handles Proton GE / Wine GE / DXVK / VKD3D fetches from GitHub Releases. Hardened against the libcurl foot-guns documented in curl.se docs: CURLOPT_PROTOCOLS_STR="https" (no scheme switch via redirect), CURLOPT_MAXREDIRS=10, explicit CURLOPT_SSL_VERIFY{PEER,HOST}, CRYPTO_memcmp for checksum comparison (constant-time), std::call_once + atexit for curl_global_{init,cleanup} balance.
Steam config sync
GameLaunchManager::checkAndSyncSettings reads the user's per-game launch options from localconfig.vdf, computes what we want them to be (env vars + wrappers + command%), and writes the diff back via SteamLibraryScanner::writeSteamLaunchOptions. We also write a MANGOHUD_CONFIGFILE=<our generated config> line into the launch options so MangoHud-related config follows the game even when Steam launches it via steam -applaunch.
writeSteamProtonVersion updates Steam's CompatToolMapping for the game. Every value goes through SteamLibraryScanner::normalizeProtonName first — display annotations like " (system)", " (custom)", " (Steam-managed)" are stripped to bare directory names because Steam looks tools up by directory name, and writing "proton-cachyos-slr (system)" silently falls back to "no compat tool" → execve of the .exe → instant exit. (This was the start/stop-loop bug fixed in 7f0ddd4.)
Extension points
Adding a new game source (e.g. Heroic-managed Battle.net)
- Add discovery logic to core/src/services/game_scanner_service.cpp following the GOG / Legendary / Lutris patterns. Path validation for executable field MUST go through resolveContainedExecutable() (defense-in-depth against malformed installed.json).
- Add a GameSource enum value in core/include/models/game.h.
- The UI will surface it automatically via SidebarManager's sources section.
Adding a new keyboard shortcut
- Use ShortcutBuilder("category.id").shortcut("...").action(...).registerWith(ShortcutManager::instance()) in MainWindow::setupKeyboardShortcuts.
- Do not also register a QShortcut and do not also set setShortcut() on a context-menu QAction — Qt's activatedAmbiguously semantics silently drop both calls when the same key sequence has multiple bindings. ShortcutManager owns it.
Adding a new test
Drop a tests/test_<name>.cpp and an entry in tests/CMakeLists.txt calling the project-local _gl_add_unit_test(test_<name> test_<name>.cpp) helper. gtest_discover_tests registers each TEST() as its own CTest entry automatically. See CONTRIBUTING.md for the full workflow.
Where to look for documented invariants
Most non-obvious invariants are inline comments in the code, not in this file. The biggest concentrations:
Open questions / known limitations
- The full launcher binary still depends on Qt at link time even for the core layer's tests (because some controllers reach into UI primitives). See tests/CMakeLists.txt for the per-test workarounds.
- MainWindow::~MainWindow clears several singleton callbacks defensively because singletons hold raw this pointers. Migrating those singletons (ShortcutManager, ThemeManager) to dependency injection has been started for some but not all (see project memory notes on the QPalette + ThemeManager DI work).
- Schema migrations are intentionally not supported (delete-DB-to-upgrade). This is fine while the launcher is single-user; not fine for any shared deployment.