From 51afc2c2910d6f7c1f2dee9c90f54729d3c3d940 Mon Sep 17 00:00:00 2001 From: fazzi <18248986+fxzzi@users.noreply.github.com> Date: Fri, 18 Apr 2025 20:44:54 +0100 Subject: ctm: enable fade animation on nvidia driver versions 575 and above (#10095) * ctm: enable fade animation on nvidia driver versions 575 and above * format if statement without braces; handle potential throw when checking for nvidia version file --- src/helpers/MiscFunctions.cpp | 35 +++++++++++++++++++++++++++++++++++ src/helpers/MiscFunctions.hpp | 1 + 2 files changed, 36 insertions(+) (limited to 'src/helpers') diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 9e398fd9..88af38c7 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -817,3 +817,38 @@ float stringToPercentage(const std::string& VALUE, const float REL) { else return std::stof(VALUE); } + +// Checks if Nvidia driver major version is at least given version. +// Useful for explicit_sync_kms and ctm_animation as they only work +// past certain driver versions. +bool isNvidiaDriverVersionAtLeast(int threshold) { + static int driverMajor = 0; + static bool once = true; + + if (once) { + once = false; + + std::error_code ec; + if (std::filesystem::exists("/sys/module/nvidia_drm/version", ec) && !ec) { + std::ifstream ifs("/sys/module/nvidia_drm/version"); + if (ifs.good()) { + try { + std::string driverInfo((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + + size_t firstDot = driverInfo.find('.'); + if (firstDot != std::string::npos) + driverMajor = std::stoi(driverInfo.substr(0, firstDot)); + + Debug::log(LOG, "Parsed NVIDIA major version: {}", driverMajor); + + } catch (std::exception& e) { + driverMajor = 0; // Default to 0 if parsing fails + } + + ifs.close(); + } + } + } + + return driverMajor >= threshold; +} diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index bd288638..f361313b 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -39,6 +39,7 @@ bool envEnabled(const std::string& env); Hyprutils::OS::CFileDescriptor allocateSHMFile(size_t len); bool allocateSHMFilePair(size_t size, Hyprutils::OS::CFileDescriptor& rw_fd_ptr, Hyprutils::OS::CFileDescriptor& ro_fd_ptr); float stringToPercentage(const std::string& VALUE, const float REL); +bool isNvidiaDriverVersionAtLeast(int threshold); template [[deprecated("use std::format instead")]] std::string getFormat(std::format_string fmt, Args&&... args) { -- cgit v1.2.3