From f47e4cdb78cd07d8f8f159f265defb98b368c38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=80=D1=8B=D0=BB=D0=BE=D0=B2=20=D0=90=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Fri, 10 Jan 2025 01:30:24 +0300 Subject: [PATCH] feat: window rounding % --- src/config/ConfigDataValues.hpp | 42 ++++++++++++++++++++++++++++++--- src/config/ConfigManager.cpp | 31 +++++++++++++++++++++++- src/desktop/Window.cpp | 16 +++++++++---- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 80e45a05..7ca30cd3 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -1,12 +1,18 @@ #pragma once #include "../defines.hpp" #include "../helpers/varlist/VarList.hpp" +#include "debug/Log.hpp" +#include +#include +#include +#include #include enum eConfigValueDataTypes : int8_t { - CVD_TYPE_INVALID = -1, - CVD_TYPE_GRADIENT = 0, - CVD_TYPE_CSS_VALUE = 1 + CVD_TYPE_INVALID = -1, + CVD_TYPE_GRADIENT = 0, + CVD_TYPE_CSS_VALUE = 1, + CVD_TYPE_ROUNDING_VALUE = 2 }; class ICustomConfigValueData { @@ -136,3 +142,33 @@ class CCssGapData : public ICustomConfigValueData { return std::format("{} {} {} {}", top, right, bottom, left); } }; + +class CRoundingData : public ICustomConfigValueData { + public: + double fraction = 0; + int64_t px = 0; + + void parseRoundingData(CVarList varlist) { + if (varlist[0].find('%') == std::string::npos) { + px = std::atoi(varlist[0].c_str()); + return; + } + + varlist[0].resize(varlist[0].size() - 1); + fraction = atof(varlist[0].c_str()) / 100; + } + + virtual eConfigValueDataTypes getDataType() { + return CVD_TYPE_ROUNDING_VALUE; + } + + virtual std::string toString() { + if (fraction != 0) + return std::format("{}%", fraction * 100); + return std::format("{}", px); + } + + bool isPercent() const { + return fraction != 0; + } +}; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index def15f26..ada54c37 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -130,6 +130,35 @@ static void configHandleGapDestroy(void** data) { delete reinterpret_cast(*data); } +static Hyprlang::CParseResult configHandleRounding(const char* VALUE, void** data) { + std::string V = VALUE; + + if (!*data) + *data = new CRoundingData(); + + const auto DATA = reinterpret_cast(*data); + CVarList varlist(V); + Hyprlang::CParseResult result; + + try { + DATA->parseRoundingData(varlist); + } catch (...) { + std::string parseError = "Error parsing rounding " + V; + result.setError(parseError.c_str()); + } + + return result; +} + +static void configHandleRoundingDestroy(void** data) { + if (*data) + delete reinterpret_cast(*data); +} + +static Hyprlang::CConfigCustomValueType configRoundingValueParser() { + return Hyprlang::CConfigCustomValueType{configHandleRounding, configHandleRoundingDestroy, "0"}; +} + static Hyprlang::CParseResult handleRawExec(const char* c, const char* v) { const std::string VALUE = v; const std::string COMMAND = c; @@ -428,7 +457,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:colored_stdout_logs", Hyprlang::INT{1}); - m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:rounding", configRoundingValueParser()); m_pConfig->addConfigValue("decoration:rounding_power", {2.F}); m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:blur:size", Hyprlang::INT{8}); diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 2bd82ad3..f3a68839 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -17,6 +18,8 @@ #include "../protocols/core/Compositor.hpp" #include "../xwayland/XWayland.hpp" #include "../helpers/Color.hpp" +#include "config/ConfigDataValues.hpp" +#include "debug/Log.hpp" #include @@ -1145,13 +1148,18 @@ bool CWindow::opaque() { } float CWindow::rounding() { - static auto PROUNDING = CConfigValue("decoration:rounding"); + static auto PROUNDING = CConfigValue("decoration:rounding"); static auto PROUNDINGPOWER = CConfigValue("decoration:rounding_power"); + static auto PROUNDINGDATA = (CRoundingData*)(PROUNDING.ptr()->getData()); - float roundingPower = m_sWindowData.roundingPower.valueOr(*PROUNDINGPOWER); - float rounding = m_sWindowData.rounding.valueOr(*PROUNDING) * (roundingPower / 2.0); /* Make perceived roundness consistent. */ + if (!PROUNDINGDATA->isPercent()) { + const float roundingPower = m_sWindowData.roundingPower.valueOr(*PROUNDINGPOWER); + const float rounding = m_sWindowData.rounding.valueOr(PROUNDINGDATA->px) * (roundingPower / 2.0); /* Make perceived roundness consistent. */ + return m_sWindowData.noRounding.valueOrDefault() ? 0 : rounding; + } - return m_sWindowData.noRounding.valueOrDefault() ? 0 : rounding; + const auto px = m_vSize.size() * PROUNDINGDATA->fraction; + return m_sWindowData.noRounding.valueOrDefault() ? 0 : px; } float CWindow::roundingPower() {