mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 23:05:59 +01:00
IPC: Add config descriptions (#7377)
Thanks @gulafaran for the work --- Co-authored-by: @gulafaran
This commit is contained in:
parent
c5feee1e35
commit
92744b5b9a
7 changed files with 1491 additions and 13 deletions
1344
src/config/ConfigDescriptions.hpp
Normal file
1344
src/config/ConfigDescriptions.hpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -28,7 +28,9 @@
|
|||
#include <filesystem>
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
extern "C" char** environ;
|
||||
extern "C" char** environ;
|
||||
|
||||
#include "ConfigDescriptions.hpp"
|
||||
|
||||
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
||||
std::string V = VALUE;
|
||||
|
@ -312,8 +314,6 @@ CConfigManager::CConfigManager() {
|
|||
configPaths.emplace_back(getMainConfigPath());
|
||||
m_pConfig = std::make_unique<Hyprlang::CConfig>(configPaths.begin()->c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = true});
|
||||
|
||||
m_pConfig->addConfigValue("general:sensitivity", {1.0f});
|
||||
m_pConfig->addConfigValue("general:apply_sens_to_raw", Hyprlang::INT{0});
|
||||
m_pConfig->addConfigValue("general:border_size", Hyprlang::INT{1});
|
||||
m_pConfig->addConfigValue("general:no_border_on_floating", Hyprlang::INT{0});
|
||||
m_pConfig->addConfigValue("general:border_part_of_window", Hyprlang::INT{1});
|
||||
|
@ -2607,3 +2607,60 @@ std::optional<std::string> CConfigManager::handlePlugin(const std::string& comma
|
|||
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::vector<SConfigOptionDescription>& CConfigManager::getAllDescriptions() {
|
||||
return CONFIG_OPTIONS;
|
||||
}
|
||||
|
||||
std::string SConfigOptionDescription::jsonify() const {
|
||||
auto parseData = [this]() -> std::string {
|
||||
return std::visit(
|
||||
[](auto&& val) {
|
||||
using T = std::decay_t<decltype(val)>;
|
||||
if constexpr (std::is_same_v<T, SStringData>) {
|
||||
return std::format(R"#( "value": "{}")#", val.value);
|
||||
} else if constexpr (std::is_same_v<T, SRangeData>) {
|
||||
return std::format(R"#( "value": {},
|
||||
"min": {},
|
||||
"max": {})#",
|
||||
val.value, val.min, val.max);
|
||||
} else if constexpr (std::is_same_v<T, SFloatData>) {
|
||||
return std::format(R"#( "value": {},
|
||||
"min": {},
|
||||
"max": {})#",
|
||||
val.value, val.min, val.max);
|
||||
} else if constexpr (std::is_same_v<T, SColorData>) {
|
||||
return std::format(R"#( "value": {})#", val.color.getAsHex());
|
||||
} else if constexpr (std::is_same_v<T, SBoolData>) {
|
||||
return std::format(R"#( "value": {})#", val.value);
|
||||
} else if constexpr (std::is_same_v<T, SChoiceData>) {
|
||||
return std::format(R"#( "value": {})#", val.choices);
|
||||
} else if constexpr (std::is_same_v<T, SVectorData>) {
|
||||
return std::format(R"#( "x": {},
|
||||
"y": {},
|
||||
"min_x": {},
|
||||
"min_y": {},
|
||||
"max_x": {},
|
||||
"max_y": {})#",
|
||||
val.vec.x, val.vec.y, val.min.x, val.min.y, val.max.x, val.max.y);
|
||||
} else if constexpr (std::is_same_v<T, SGradientData>) {
|
||||
return std::format(R"#( "value": "{}")#", val.gradient);
|
||||
}
|
||||
return std::string{""};
|
||||
},
|
||||
data);
|
||||
};
|
||||
|
||||
std::string json = std::format(R"#({{
|
||||
"value": "{}",
|
||||
"description": "{}",
|
||||
"type": {},
|
||||
"flags": {},
|
||||
"data": {{
|
||||
{}
|
||||
}}
|
||||
}})#",
|
||||
value, description, (uint16_t)type, (uint32_t)flags, parseData());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,70 @@ struct SExecRequestedRule {
|
|||
uint64_t iPid = 0;
|
||||
};
|
||||
|
||||
enum eConfigOptionType : uint16_t {
|
||||
CONFIG_OPTION_BOOL = 0,
|
||||
CONFIG_OPTION_INT = 1, /* e.g. 0/1/2*/
|
||||
CONFIG_OPTION_FLOAT = 2,
|
||||
CONFIG_OPTION_STRING_SHORT = 3, /* e.g. "auto" */
|
||||
CONFIG_OPTION_STRING_LONG = 4, /* e.g. a command */
|
||||
CONFIG_OPTION_COLOR = 5,
|
||||
CONFIG_OPTION_CHOICE = 6, /* e.g. "one", "two", "three" */
|
||||
CONFIG_OPTION_GRADIENT = 7,
|
||||
CONFIG_OPTION_VECTOR = 8,
|
||||
};
|
||||
|
||||
enum eConfigOptionFlags : uint32_t {
|
||||
CONFIG_OPTION_FLAG_PERCENTAGE = (1 << 0),
|
||||
};
|
||||
|
||||
struct SConfigOptionDescription {
|
||||
|
||||
struct SBoolData {
|
||||
bool value = false;
|
||||
};
|
||||
|
||||
struct SRangeData {
|
||||
int value = 0, min = 0, max = 2;
|
||||
};
|
||||
|
||||
struct SFloatData {
|
||||
float value = 0, min = 0, max = 100;
|
||||
};
|
||||
|
||||
struct SStringData {
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct SColorData {
|
||||
CColor color;
|
||||
};
|
||||
|
||||
struct SChoiceData {
|
||||
int firstIndex = 0;
|
||||
std::string choices; // comma-separated
|
||||
};
|
||||
|
||||
struct SGradientData {
|
||||
std::string gradient;
|
||||
};
|
||||
|
||||
struct SVectorData {
|
||||
Vector2D vec, min, max;
|
||||
};
|
||||
|
||||
std::string value; // e.g. general:gaps_in
|
||||
std::string description;
|
||||
std::string specialCategory; // if value is special (e.g. device:abc) value will be abc and special device
|
||||
bool specialKey = false;
|
||||
eConfigOptionType type = CONFIG_OPTION_BOOL;
|
||||
uint32_t flags = 0; // eConfigOptionFlags
|
||||
|
||||
std::string jsonify() const;
|
||||
|
||||
//
|
||||
std::variant<SBoolData, SRangeData, SFloatData, SStringData, SColorData, SChoiceData, SGradientData, SVectorData> data;
|
||||
};
|
||||
|
||||
class CConfigManager {
|
||||
public:
|
||||
CConfigManager();
|
||||
|
@ -115,6 +179,8 @@ class CConfigManager {
|
|||
std::vector<SWindowRule> getMatchingRules(PHLWINDOW, bool dynamic = true, bool shadowExec = false);
|
||||
std::vector<SLayerRule> getMatchingRules(PHLLS);
|
||||
|
||||
const std::vector<SConfigOptionDescription>& getAllDescriptions();
|
||||
|
||||
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
|
||||
|
||||
std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
|
||||
|
|
|
@ -1561,6 +1561,21 @@ std::string getIsLocked(eHyprCtlOutputFormat format, std::string request) {
|
|||
return lockedStr;
|
||||
}
|
||||
|
||||
std::string getDescriptions(eHyprCtlOutputFormat format, std::string request) {
|
||||
std::string json = "{";
|
||||
const auto& DESCS = g_pConfigManager->getAllDescriptions();
|
||||
|
||||
for (const auto& d : DESCS) {
|
||||
json += d.jsonify() + ",\n";
|
||||
}
|
||||
|
||||
json.pop_back();
|
||||
json.pop_back();
|
||||
|
||||
json += "}\n";
|
||||
return json;
|
||||
}
|
||||
|
||||
CHyprCtl::CHyprCtl() {
|
||||
registerCommand(SHyprCtlCommand{"workspaces", true, workspacesRequest});
|
||||
registerCommand(SHyprCtlCommand{"workspacerules", true, workspaceRulesRequest});
|
||||
|
@ -1581,6 +1596,7 @@ CHyprCtl::CHyprCtl() {
|
|||
registerCommand(SHyprCtlCommand{"layouts", true, layoutsRequest});
|
||||
registerCommand(SHyprCtlCommand{"configerrors", true, configErrorsRequest});
|
||||
registerCommand(SHyprCtlCommand{"locked", true, getIsLocked});
|
||||
registerCommand(SHyprCtlCommand{"descriptions", true, getDescriptions});
|
||||
|
||||
registerCommand(SHyprCtlCommand{"monitors", false, monitorsRequest});
|
||||
registerCommand(SHyprCtlCommand{"reload", false, reloadRequest});
|
||||
|
|
|
@ -21,6 +21,6 @@ CColor::CColor(uint64_t hex) {
|
|||
this->a = ALPHA(hex);
|
||||
}
|
||||
|
||||
uint32_t CColor::getAsHex() {
|
||||
uint32_t CColor::getAsHex() const {
|
||||
return (uint32_t)(a * 255.f) * 0x1000000 + (uint32_t)(r * 255.f) * 0x10000 + (uint32_t)(g * 255.f) * 0x100 + (uint32_t)(b * 255.f) * 0x1;
|
||||
}
|
|
@ -10,7 +10,7 @@ class CColor {
|
|||
|
||||
float r = 0, g = 0, b = 0, a = 1.f;
|
||||
|
||||
uint32_t getAsHex();
|
||||
uint32_t getAsHex() const;
|
||||
|
||||
CColor operator-(const CColor& c2) const {
|
||||
return CColor(r - c2.r, g - c2.g, b - c2.b, a - c2.a);
|
||||
|
|
|
@ -82,18 +82,13 @@ CInputManager::~CInputManager() {
|
|||
}
|
||||
|
||||
void CInputManager::onMouseMoved(IPointer::SMotionEvent e) {
|
||||
static auto PSENS = CConfigValue<Hyprlang::FLOAT>("general:sensitivity");
|
||||
static auto PNOACCEL = CConfigValue<Hyprlang::INT>("input:force_no_accel");
|
||||
static auto PSENSTORAW = CConfigValue<Hyprlang::INT>("general:apply_sens_to_raw");
|
||||
static auto PNOACCEL = CConfigValue<Hyprlang::INT>("input:force_no_accel");
|
||||
|
||||
const auto DELTA = *PNOACCEL == 1 ? e.unaccel : e.delta;
|
||||
|
||||
if (*PSENSTORAW == 1)
|
||||
PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA * *PSENS, e.unaccel * *PSENS);
|
||||
else
|
||||
PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, e.unaccel);
|
||||
PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, e.unaccel);
|
||||
|
||||
g_pPointerManager->move(DELTA * *PSENS);
|
||||
g_pPointerManager->move(DELTA);
|
||||
|
||||
mouseMoveUnified(e.timeMs);
|
||||
|
||||
|
|
Loading…
Reference in a new issue