renderer: Allow headless mode in hyprland (#4794)

* allow headless

* clang-format

* fix redundant logic lol
This commit is contained in:
thejch 2024-03-15 07:28:14 -07:00 committed by GitHub
parent 6c24cee88f
commit bc15a8f600
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 13 deletions

View file

@ -127,6 +127,18 @@ void CCompositor::initServer() {
throwError("wlr_backend_autocreate() failed!");
}
bool isHeadlessOnly = true;
wlr_multi_for_each_backend(
m_sWLRBackend,
[](wlr_backend* backend, void* isHeadlessOnly) {
if (!wlr_backend_is_headless(backend))
*(bool*)isHeadlessOnly = false;
},
&isHeadlessOnly);
if (isHeadlessOnly) {
m_sWLRRenderer = wlr_renderer_autocreate(m_sWLRBackend);
} else {
m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend);
if (m_iDRMFD < 0) {
Debug::log(CRIT, "Couldn't query the DRM FD!");
@ -134,6 +146,7 @@ void CCompositor::initServer() {
}
m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD);
}
if (!m_sWLRRenderer) {
Debug::log(CRIT, "m_sWLRRenderer was NULL! This usually means wlroots could not find a GPU or enountered some issues.");

View file

@ -33,6 +33,7 @@ CHyprRenderer::CHyprRenderer() {
const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD);
if (DRMV) {
std::string name = std::string{DRMV->name, DRMV->name_len};
std::transform(name.begin(), name.end(), name.begin(), tolower);
@ -41,6 +42,9 @@ CHyprRenderer::CHyprRenderer() {
Debug::log(LOG, "Primary DRM driver information: {} v{}.{}.{} from {} description {}", name, DRMV->version_major, DRMV->version_minor, DRMV->version_patchlevel,
std::string{DRMV->date, DRMV->date_len}, std::string{DRMV->desc, DRMV->desc_len});
} else {
Debug::log(LOG, "No primary DRM driver information found");
}
drmFreeVersion(DRMV);
}