mirror of
https://github.com/hyprwm/Hyprland
synced 2025-01-11 23:49:49 +01:00
feat: window rounding %
This commit is contained in:
parent
e66eab7b6a
commit
f47e4cdb78
3 changed files with 81 additions and 8 deletions
|
@ -1,12 +1,18 @@
|
|||
#pragma once
|
||||
#include "../defines.hpp"
|
||||
#include "../helpers/varlist/VarList.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum eConfigValueDataTypes : int8_t {
|
||||
CVD_TYPE_INVALID = -1,
|
||||
CVD_TYPE_GRADIENT = 0,
|
||||
CVD_TYPE_CSS_VALUE = 1
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -130,6 +130,35 @@ static void configHandleGapDestroy(void** data) {
|
|||
delete reinterpret_cast<CCssGapData*>(*data);
|
||||
}
|
||||
|
||||
static Hyprlang::CParseResult configHandleRounding(const char* VALUE, void** data) {
|
||||
std::string V = VALUE;
|
||||
|
||||
if (!*data)
|
||||
*data = new CRoundingData();
|
||||
|
||||
const auto DATA = reinterpret_cast<CRoundingData*>(*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<CRoundingData*>(*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});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <format>
|
||||
#include <hyprutils/animation/AnimatedVariable.hpp>
|
||||
#include <re2/re2.h>
|
||||
|
||||
|
@ -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 <hyprutils/string/String.hpp>
|
||||
|
||||
|
@ -1145,13 +1148,18 @@ bool CWindow::opaque() {
|
|||
}
|
||||
|
||||
float CWindow::rounding() {
|
||||
static auto PROUNDING = CConfigValue<Hyprlang::INT>("decoration:rounding");
|
||||
static auto PROUNDING = CConfigValue<Hyprlang::CConfigCustomValueType>("decoration:rounding");
|
||||
static auto PROUNDINGPOWER = CConfigValue<Hyprlang::FLOAT>("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;
|
||||
}
|
||||
|
||||
const auto px = m_vSize.size() * PROUNDINGDATA->fraction;
|
||||
return m_sWindowData.noRounding.valueOrDefault() ? 0 : px;
|
||||
}
|
||||
|
||||
float CWindow::roundingPower() {
|
||||
|
|
Loading…
Reference in a new issue