core: move to hyprlang config value wrapper (#667)

This commit is contained in:
Maximilian Seidler 2025-01-29 22:10:27 +00:00 committed by GitHub
parent e77bc92b99
commit 1bfa79eb83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 47 additions and 50 deletions

View file

@ -65,7 +65,7 @@ pkg_check_modules(
wayland-client
wayland-protocols
wayland-egl
hyprlang>=0.4.0
hyprlang>=0.6.0
egl
xkbcommon
libjpeg

View file

@ -62,11 +62,11 @@
]
},
"locked": {
"lastModified": 1737632363,
"narHash": "sha256-X9I8POSlHxBVjD0fiX1O2j7U9Zi1+4rIkrsyHP0uHXY=",
"lastModified": 1737978343,
"narHash": "sha256-TfFS0HCEJh63Kahrkp1h9hVDMdLU8a37Zz+IFucxyfA=",
"owner": "hyprwm",
"repo": "hyprutils",
"rev": "006620eb29d54ea9086538891404c78563d1bae1",
"rev": "6a8bc9d2a4451df12f5179dc0b1d2d46518a90ab",
"type": "github"
},
"original": {

View file

@ -9,11 +9,11 @@
#include <memory>
CAuth::CAuth() {
static auto* const PENABLEPAM = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("auth:pam:enabled");
if (**PENABLEPAM)
static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled");
if (*ENABLEPAM)
m_vImpls.push_back(std::make_shared<CPam>());
static auto* const PENABLEFINGERPRINT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("auth:fingerprint:enabled");
if (**PENABLEFINGERPRINT)
static const auto ENABLEFINGERPRINT = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:enabled");
if (*ENABLEFINGERPRINT)
m_vImpls.push_back(std::make_shared<CFingerprint>());
RASSERT(!m_vImpls.empty(), "At least one authentication method must be enabled!");

View file

@ -36,10 +36,10 @@ static std::map<std::string, MatchResult> s_mapStringToTestType = {{"verify-no-m
{"verify-unknown-error", MATCH_UNKNOWN_ERROR}};
CFingerprint::CFingerprint() {
static auto* const PFINGERPRINTREADY = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:fingerprint:ready_message"));
m_sFingerprintReady = *PFINGERPRINTREADY;
static auto* const PFINGERPRINTPRESENT = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:fingerprint:present_message"));
m_sFingerprintPresent = *PFINGERPRINTPRESENT;
static const auto FINGERPRINTREADY = g_pConfigManager->getValue<Hyprlang::STRING>("auth:fingerprint:ready_message");
m_sFingerprintReady = *FINGERPRINTREADY;
static const auto FINGERPRINTPRESENT = g_pConfigManager->getValue<Hyprlang::STRING>("auth:fingerprint:present_message");
m_sFingerprintPresent = *FINGERPRINTPRESENT;
}
CFingerprint::~CFingerprint() {
@ -166,8 +166,8 @@ void CFingerprint::handleVerifyStatus(const std::string& result, bool done) {
m_sFailureReason = "Fingerprint auth disabled (too many failed attempts)";
} else {
done = false;
static const auto RETRYDELAY = **(Hyprlang::INT* const*)(g_pConfigManager->getValuePtr("auth:fingerprint:retry_delay"));
g_pHyprlock->addTimer(std::chrono::milliseconds(RETRYDELAY), [](std::shared_ptr<CTimer> self, void* data) { ((CFingerprint*)data)->startVerify(true); }, this);
static const auto RETRYDELAY = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:retry_delay");
g_pHyprlock->addTimer(std::chrono::milliseconds(*RETRYDELAY), [](std::shared_ptr<CTimer> self, void* data) { ((CFingerprint*)data)->startVerify(true); }, this);
m_sFailureReason = "Fingerprint did not match";
}
break;

View file

@ -61,8 +61,8 @@ int conv(int num_msg, const struct pam_message** msg, struct pam_response** resp
}
CPam::CPam() {
static auto* const PPAMMODULE = (Hyprlang::STRING*)(g_pConfigManager->getValuePtr("auth:pam:module"));
m_sPamModule = *PPAMMODULE;
static const auto PAMMODULE = g_pConfigManager->getValue<Hyprlang::STRING>("auth:pam:module");
m_sPamModule = *PAMMODULE;
if (!std::filesystem::exists(std::filesystem::path("/etc/pam.d/") / m_sPamModule)) {
Debug::log(ERR, "Pam module \"/etc/pam.d/{}\" does not exist! Falling back to \"/etc/pam.d/su\"", m_sPamModule);

View file

@ -358,13 +358,6 @@ void CConfigManager::init() {
#undef SHADOWABLE
}
std::mutex configMtx;
void* const* CConfigManager::getValuePtr(const std::string& name) {
std::lock_guard<std::mutex> lg(configMtx);
return m_config.getConfigValuePtr(name.c_str())->getDataStaticPtr();
}
std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
std::vector<CConfigManager::SWidgetConfig> result;

View file

@ -13,8 +13,12 @@
class CConfigManager {
public:
CConfigManager(std::string configPath);
void init();
void* const* getValuePtr(const std::string& name);
void init();
template <typename T>
Hyprlang::CSimpleConfigValue<T> getValue(const std::string& name) {
return Hyprlang::CSimpleConfigValue<T>(&m_config, name.c_str());
}
struct SWidgetConfig {
std::string type;

View file

@ -77,7 +77,7 @@ void updateGradientVariable(CAnimatedVariable<CGradientValueData>& av, const flo
}
void CHyprlockAnimationManager::tick() {
static auto* const PANIMATIONSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("animations:enabled");
static const auto ANIMATIONSENABLED = g_pConfigManager->getValue<Hyprlang::INT>("animations:enabled");
for (size_t i = 0; i < m_vActiveAnimatedVariables.size(); i++) {
const auto PAV = m_vActiveAnimatedVariables[i].lock();
if (!PAV || !PAV->ok())
@ -86,7 +86,7 @@ void CHyprlockAnimationManager::tick() {
const auto SPENT = PAV->getPercent();
const auto PBEZIER = getBezier(PAV->getBezierName());
const auto POINTY = PBEZIER->getYForPoint(SPENT);
const bool WARP = !**PANIMATIONSENABLED || SPENT >= 1.f;
const bool WARP = !*ANIMATIONSENABLED || SPENT >= 1.f;
switch (PAV->m_Type) {
case AVARTYPE_FLOAT: {

View file

@ -19,10 +19,10 @@ CSessionLockSurface::CSessionLockSurface(COutput* output) : output(output) {
exit(1);
}
const auto PFRACTIONALSCALING = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:fractional_scaling");
const auto ENABLE_FSV1 = **PFRACTIONALSCALING == 1 || /* auto enable */ (**PFRACTIONALSCALING == 2);
const auto PFRACTIONALMGR = g_pHyprlock->getFractionalMgr();
const auto PVIEWPORTER = g_pHyprlock->getViewporter();
static const auto FRACTIONALSCALING = g_pConfigManager->getValue<Hyprlang::INT>("general:fractional_scaling");
const auto ENABLE_FSV1 = *FRACTIONALSCALING == 1 || /* auto enable */ (*FRACTIONALSCALING == 2);
const auto PFRACTIONALMGR = g_pHyprlock->getFractionalMgr();
const auto PVIEWPORTER = g_pHyprlock->getViewporter();
if (ENABLE_FSV1 && PFRACTIONALMGR && PVIEWPORTER) {
fractional = makeShared<CCWpFractionalScaleV1>(PFRACTIONALMGR->sendGetFractionalScale(surface->resource()));

View file

@ -40,11 +40,11 @@ void CSeatManager::registerSeat(SP<CCWlSeat> seat) {
if (!m_pCursorShape)
return;
static auto* const PHIDE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:hide_cursor");
static const auto HIDE = g_pConfigManager->getValue<Hyprlang::INT>("general:hide_cursor");
m_pCursorShape->lastCursorSerial = serial;
if (**PHIDE)
if (*HIDE)
m_pCursorShape->hideCursor();
else
m_pCursorShape->setShape(wpCursorShapeDeviceV1Shape::WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);

View file

@ -33,13 +33,13 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b
g_pEGL = std::make_unique<CEGL>(m_sWaylandState.display);
if (!immediate) {
const auto PGRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
m_tGraceEnds = **PGRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**PGRACE) : std::chrono::system_clock::from_time_t(0);
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace");
m_tGraceEnds = *GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(*GRACE) : std::chrono::system_clock::from_time_t(0);
} else
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
const auto PIMMEDIATERENDER = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:immediate_render");
m_bImmediateRender = immediateRender || **PIMMEDIATERENDER;
static const auto IMMEDIATERENDER = g_pConfigManager->getValue<Hyprlang::INT>("general:immediate_render");
m_bImmediateRender = immediateRender || *IMMEDIATERENDER;
const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP");
const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""};
@ -661,9 +661,9 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
} else if (SYM == XKB_KEY_Return || SYM == XKB_KEY_KP_Enter) {
Debug::log(LOG, "Authenticating");
static auto* const PIGNOREEMPTY = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:ignore_empty_input");
static const auto IGNOREEMPTY = g_pConfigManager->getValue<Hyprlang::INT>("general:ignore_empty_input");
if (m_sPasswordState.passBuffer.empty() && **PIGNOREEMPTY) {
if (m_sPasswordState.passBuffer.empty() && *IGNOREEMPTY) {
Debug::log(LOG, "Ignoring empty input");
return;
}

View file

@ -215,15 +215,15 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
target.type = TARGET_IMAGE; /* text is just an image lol */
target.id = rq.id;
const int FONTSIZE = rq.props.contains("font_size") ? std::any_cast<int>(rq.props.at("font_size")) : 16;
const CHyprColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CHyprColor>(rq.props.at("color")) : CHyprColor(1.0, 1.0, 1.0, 1.0);
const std::string FONTFAMILY = rq.props.contains("font_family") ? std::any_cast<std::string>(rq.props.at("font_family")) : "Sans";
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
const int FONTSIZE = rq.props.contains("font_size") ? std::any_cast<int>(rq.props.at("font_size")) : 16;
const CHyprColor FONTCOLOR = rq.props.contains("color") ? std::any_cast<CHyprColor>(rq.props.at("color")) : CHyprColor(1.0, 1.0, 1.0, 1.0);
const std::string FONTFAMILY = rq.props.contains("font_family") ? std::any_cast<std::string>(rq.props.at("font_family")) : "Sans";
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
static auto* const TRIM = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:text_trim");
std::string text = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
static const auto TRIM = g_pConfigManager->getValue<Hyprlang::INT>("general:text_trim");
std::string text = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset;
if (**TRIM) {
if (*TRIM) {
text.erase(0, text.find_first_not_of(" \n\r\t"));
text.erase(text.find_last_not_of(" \n\r\t") + 1);
}

View file

@ -201,7 +201,7 @@ CRenderer::CRenderer() {
//
CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf) {
static auto* const PDISABLEBAR = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:disable_loading_bar");
static const auto DISABLEBAR = g_pConfigManager->getValue<Hyprlang::INT>("general:disable_loading_bar");
projection = Mat3x3::outputProjection(surf.size, HYPRUTILS_TRANSFORM_NORMAL);
@ -224,7 +224,7 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf
if (WAITFORASSETS) {
// render status
if (!**PDISABLEBAR) {
if (!*DISABLEBAR) {
CBox progress = {0, 0, asyncResourceGatherer->progress * surf.size.x, 2};
renderRect(progress, CHyprColor{0.2f, 0.1f, 0.1f, 1.f}, 0);
}

View file

@ -31,8 +31,8 @@ CScreencopyFrame::CScreencopyFrame(COutput* output) : m_output(output) {
captureOutput();
static auto* const PSCMODE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:screencopy_mode");
if (**PSCMODE == 1)
static const auto SCMODE = g_pConfigManager->getValue<Hyprlang::INT>("general:screencopy_mode");
if (*SCMODE == 1)
m_frame = std::make_unique<CSCSHMFrame>(m_sc);
else
m_frame = std::make_unique<CSCDMAFrame>(m_sc);