Skip to content

Commit

Permalink
core: move to hyprlang config value wrapper (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma authored Jan 29, 2025
1 parent e77bc92 commit 1bfa79e
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pkg_check_modules(
wayland-client
wayland-protocols
wayland-egl
hyprlang>=0.4.0
hyprlang>=0.6.0
egl
xkbcommon
libjpeg
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/auth/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
12 changes: 6 additions & 6 deletions src/auth/Fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/auth/Pam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 0 additions & 7 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/core/AnimationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions src/core/LockSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions src/core/Seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""};
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/AsyncResourceGatherer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/Screencopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1bfa79e

Please sign in to comment.