What Programming Language Is Hyprland Written In? Inside the C++20 Wayland Codebase
Hyprland is implemented entirely in modern C++20, utilizing the CMake build system and extensive C++ Standard Library features across its Wayland compositor architecture.
The hyprwm/Hyprland repository is a high-performance Wayland compositor whose core is written in native C++. By examining the source tree, you will find .cpp implementation files and .hpp headers that leverage C++20 capabilities, smart pointers, and standard library containers to manage complex window state and rendering pipelines.
C++20 as the Core Language
Hyprland is explicitly configured to compile as C++20. In the root CMakeLists.txt, the project sets the -std=c++20 compiler flag (lines 20-26), which enables modern language features required throughout the codebase. This standard unlocks std::format for string formatting, constexpr compile-time evaluation, and improved lambda captures.
The compositor makes heavy use of C++ Standard Library idioms. Throughout src/Compositor.cpp and src/Compositor.hpp, you will find std::unique_ptr and std::shared_ptr managing Wayland object lifecycles, std::vector and std::string handling dynamic data, and range-based for loops iterating over window collections. These patterns confirm a modern C++ philosophy rather than traditional C-style memory management.
Key Source Files Demonstrating C++ Usage
Several critical files illustrate Hyprland’s commitment to C++:
src/Compositor.cpp– The main compositor implementation featuring class definitions, namespace scoping, and STL containers likestd::unordered_mapfor client tracking.src/Compositor.hpp– Header file declaring theCCompositorclass with inline methods, template usage, and C++ access specifiers.src/includes.hpp– Central header aggregating C++ utility headers and forward declarations using#pragma onceguards.src/defines.hpp– Macro definitions andenum classdeclarations scoped within C++ namespaces.src/init/initHelpers.cpp– Initialization routines using<filesystem>and<chrono>from the C++20 standard library.hyprpm/CMakeLists.txt– Proves that even the Hyprland package manager sub-module is built as C++.
Modern C++ Features in Practice
Hyprland employs specific C++20 and modern C++ patterns that distinguish it from C-based compositors:
Memory Management via RAII – The codebase eschews raw pointers for std::unique_ptr and std::shared_ptr, ensuring automatic resource cleanup when compositor objects go out of scope.
Template Metaprogramming – Utilities in src/helpers/ use function templates and class templates for type-safe callbacks and event handlers.
Standard Library Algorithms – Rather than manual loops, Hyprland uses std::ranges algorithms and std::find_if for window lookup operations.
Code Examples from the Hyprland Source
Below are representative patterns found in the repository, demonstrating how Hyprland utilizes C++:
Logger Implementation Using Hyprutils
This pattern mirrors the logging found in src/Compositor.cpp, using the Hyprutils::String::format helper:
#include <hyprutils/string/String.hpp>
#include <iostream>
int main() {
const std::string msg = "Hyprland logger test";
std::cout << Hyprutils::String::format("[DEBUG] {}\n", msg);
return 0;
}
Wayland Server Initialization
The core event loop structure matches CCompositor::initServer(), showing raw Wayland C API wrapped in C++ control flow:
#include <wayland-server-core.h>
int main() {
wl_display *display = wl_display_create();
wl_display_add_socket_auto(display);
wl_display_run(display); // event loop – same pattern used in CCompositor::initServer()
wl_display_destroy(display);
return 0;
}
C++20 std::format for Instance Signatures
Hyprland generates unique instance signatures in the CCompositor constructor using formatting similar to this:
#include <format>
#include <iostream>
int main() {
std::string instance = std::format("{}_{:%Y%m%d_%H%M%S}", "Hyprland", std::chrono::system_clock::now());
std::cout << "Instance signature: " << instance << '\n';
return 0;
}
Plugin System with Smart Pointers
The plugin architecture in plugins/PluginSystem.hpp uses std::unique_ptr for automatic memory management:
#include "plugins/PluginSystem.hpp"
int main() {
auto pluginSystem = std::make_unique<CPluginSystem>();
pluginSystem->load("myplugin.so"); // loads a shared object compiled as C++
return 0;
}
Build System Configuration
Hyprland relies on CMake as its native build system for C++ projects. The top-level CMakeLists.txt not only enforces the C++20 standard but also links against C++ libraries like hyprutils and hyprlang. The build process compiles dozens of .cpp files in src/ into a single native binary, linking with Wayland and DRM libraries via C++ linkage.
Summary
- Hyprland is written in C++20, confirmed by the
-std=c++20flag inCMakeLists.txt. - Core implementation resides in
.cppfiles likesrc/Compositor.cpp, using classes and smart pointers. - The codebase leverages RAII, templates, and STL containers for memory-safe window management.
- CMake handles compilation of the pure C++ source tree, including sub-modules like
hyprpm.
Frequently Asked Questions
Is Hyprland written in C or C++?
Hyprland is written in C++, not C. While it interfaces with C-based system libraries like Wayland and libdrm, the compositor core uses C++ classes, namespaces, and the standard library. All source files use .cpp and .hpp extensions, and the project requires a C++20 compiler.
What C++ standard version does Hyprland require?
Hyprland requires C++20. The build configuration explicitly sets this standard in CMakeLists.txt, enabling features like std::format, constexpr functions, and designated initializers. Compiling with C++17 or earlier would result in build failures due to missing language features used in src/init/initHelpers.cpp and other files.
Why does Hyprland use C++ instead of C?
The developers chose C++ to gain zero-cost abstractions and type safety through RAII (Resource Acquisition Is Initialization). Using std::unique_ptr and std::shared_ptr eliminates manual memory management errors, while C++ templates provide compile-time polymorphism for event handling and rendering logic that would be verbose and error-prone in C.
Are there other programming languages used in Hyprland?
The core compositor and its tools are exclusively C++. While Hyprland parses configuration files written in its own custom syntax, the parser implementation in src/config/ is itself C++. Even auxiliary tools like hyprpm (the package manager) are built from C++ source, as evidenced by hyprpm/CMakeLists.txt. There is no Rust, Python, or other language in the critical rendering path.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →