diff options
author | thejch <[email protected]> | 2024-03-15 07:28:14 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2024-03-15 14:28:14 +0000 |
commit | bc15a8f60028539690cccdb78eed7fc9175fe792 (patch) | |
tree | 73c9528313226c9fa40f76be53ddbf99f51b99f7 | |
parent | 6c24cee88f50721cfd6a62e4140924ac13549d1d (diff) | |
download | Hyprland-bc15a8f60028539690cccdb78eed7fc9175fe792.tar.gz Hyprland-bc15a8f60028539690cccdb78eed7fc9175fe792.zip |
renderer: Allow headless mode in hyprland (#4794)
* allow headless
* clang-format
* fix redundant logic lol
-rw-r--r-- | src/Compositor.cpp | 25 | ||||
-rw-r--r-- | src/render/Renderer.cpp | 18 |
2 files changed, 30 insertions, 13 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index eda5b5ed..42ba9b5f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -127,13 +127,26 @@ void CCompositor::initServer() { throwError("wlr_backend_autocreate() failed!"); } - m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend); - if (m_iDRMFD < 0) { - Debug::log(CRIT, "Couldn't query the DRM FD!"); - throwError("wlr_backend_get_drm_fd() 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); - m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD); + 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!"); + throwError("wlr_backend_get_drm_fd() failed!"); + } + + 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."); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index a9c7c11a..10f15a9d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -31,16 +31,20 @@ CHyprRenderer::CHyprRenderer() { } else { Debug::log(LOG, "m_sWLRSession is null, omitting full DRM node checks"); - const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD); + const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD); - std::string name = std::string{DRMV->name, DRMV->name_len}; - std::transform(name.begin(), name.end(), name.begin(), tolower); + if (DRMV) { + std::string name = std::string{DRMV->name, DRMV->name_len}; + std::transform(name.begin(), name.end(), name.begin(), tolower); - if (name.contains("nvidia")) - m_bNvidia = true; + if (name.contains("nvidia")) + m_bNvidia = true; - 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}); + 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); } |