From ef81d500ca63c10c6159450ad515b3a4723a505c Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 26 Sep 2026 00:05:42 +0900 Subject: [PATCH] linux client: detect panel res via /sys/class/drm --- client/hmd_traits.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/client/hmd_traits.cpp b/client/hmd_traits.cpp index cb211987..449970cd 100644 --- a/client/hmd_traits.cpp +++ b/client/hmd_traits.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -309,6 +310,40 @@ void hmd_traits::init() permissions[feature::face_tracking] = "android.permission.FACE_TRACKING"; } } +#else // not android + for (const auto & entry: std::filesystem::directory_iterator("/sys/class/drm")) + { + std::ifstream modes(entry.path() / "modes"); + if (not modes) + continue; + + std::string mode; + while (std::getline(modes, mode)) + { + // panel modes are reported as `2*2160x2160_120` etc. + if (not mode.starts_with("2*")) + // not a HMD + continue; + + const auto x = mode.find('x', 2); + if (x == std::string::npos) + continue; + + try + { + panel_width_override = std::stoul(mode.substr(2, x - 2)); + spdlog::info("Detected native panel mode {}, panel width {}", mode, panel_width_override); + break; + } + catch (...) + { + spdlog::warn("Failed to parse native panel mode {}", mode); + } + } + + if (panel_width_override > 0) + break; + } #endif spdlog::info("HMD traits initialized");