mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-07-25 17:21:54 -07:00
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
This commit is contained in:
@@ -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<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
|
||||
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;
|
||||
}
|
||||
|
@@ -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 <typename... Args>
|
||||
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "managers/AnimationManager.hpp"
|
||||
#include "../helpers/Monitor.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
|
||||
CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_) : resource(resource_) {
|
||||
if UNLIKELY (!good())
|
||||
@@ -109,8 +110,12 @@ void CHyprlandCTMControlProtocol::destroyResource(CHyprlandCTMControlResource* r
|
||||
bool CHyprlandCTMControlProtocol::isCTMAnimationEnabled() {
|
||||
static auto PENABLEANIM = CConfigValue<Hyprlang::INT>("render:ctm_animation");
|
||||
|
||||
if (*PENABLEANIM == 2)
|
||||
return !g_pHyprRenderer->isNvidia();
|
||||
if (*PENABLEANIM == 2 /* auto */) {
|
||||
if (!g_pHyprRenderer->isNvidia())
|
||||
return true;
|
||||
// CTM animations are bugged on versions below.
|
||||
return isNvidiaDriverVersionAtLeast(575);
|
||||
}
|
||||
return *PENABLEANIM;
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "debug/Log.hpp"
|
||||
#include "../protocols/ColorManagement.hpp"
|
||||
#include "../protocols/types/ContentType.hpp"
|
||||
#include "../helpers/MiscFunctions.hpp"
|
||||
|
||||
#include <hyprutils/utils/ScopeGuard.hpp>
|
||||
using namespace Hyprutils::Utils;
|
||||
@@ -2349,43 +2350,9 @@ SExplicitSyncSettings CHyprRenderer::getExplicitSyncSettings(SP<Aquamarine::IOut
|
||||
if (!m_bNvidia)
|
||||
settings.explicitKMSEnabled = true;
|
||||
else {
|
||||
|
||||
// check nvidia version. Explicit KMS is supported in >=560
|
||||
// in the case of an error, driverMajor will stay 0 and explicit KMS will be disabled
|
||||
static int driverMajor = 0;
|
||||
|
||||
static bool once = true;
|
||||
if (once) {
|
||||
once = false;
|
||||
|
||||
Debug::log(LOG, "Renderer: checking for explicit KMS support for nvidia");
|
||||
|
||||
if (std::filesystem::exists("/sys/module/nvidia_drm/version")) {
|
||||
Debug::log(LOG, "Renderer: Nvidia version file exists");
|
||||
|
||||
std::ifstream ifs("/sys/module/nvidia_drm/version");
|
||||
if (ifs.good()) {
|
||||
try {
|
||||
std::string driverInfo((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
|
||||
Debug::log(LOG, "Renderer: Read nvidia version {}", driverInfo);
|
||||
|
||||
CVarList ver(driverInfo, 0, '.', true);
|
||||
driverMajor = std::stoi(ver[0]);
|
||||
|
||||
Debug::log(LOG, "Renderer: Parsed nvidia major version: {}", driverMajor);
|
||||
|
||||
} catch (std::exception& e) { settings.explicitKMSEnabled = false; }
|
||||
|
||||
ifs.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settings.explicitKMSEnabled = driverMajor >= 560;
|
||||
settings.explicitKMSEnabled = isNvidiaDriverVersionAtLeast(560);
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user