hyprland/workspaces: break up parseConfig
parent
e4353e548a
commit
9fe51af6b0
|
@ -145,7 +145,17 @@ class Workspaces : public AModule, public EventHandler {
|
||||||
Json::Value const& clientsData = Json::Value::nullRef);
|
Json::Value const& clientsData = Json::Value::nullRef);
|
||||||
void removeWorkspace(std::string const& name);
|
void removeWorkspace(std::string const& name);
|
||||||
void setUrgentWorkspace(std::string const& windowaddress);
|
void setUrgentWorkspace(std::string const& windowaddress);
|
||||||
|
|
||||||
|
// Config
|
||||||
void parseConfig(const Json::Value& config);
|
void parseConfig(const Json::Value& config);
|
||||||
|
auto populateIconsMap(const Json::Value& formatIcons) -> void;
|
||||||
|
auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member) -> void;
|
||||||
|
auto populateSortByConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
|
auto populatePersistentWorkspacesConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
|
||||||
|
auto populateWindowRewriteConfig(const Json::Value& config) -> void;
|
||||||
|
|
||||||
void registerIpc();
|
void registerIpc();
|
||||||
|
|
||||||
// workspace events
|
// workspace events
|
||||||
|
|
|
@ -55,54 +55,63 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||||
const Json::Value &configFormat = config["format"];
|
const auto &configFormat = config["format"];
|
||||||
|
|
||||||
m_format = configFormat.isString() ? configFormat.asString() : "{name}";
|
m_format = configFormat.isString() ? configFormat.asString() : "{name}";
|
||||||
m_withIcon = m_format.find("{icon}") != std::string::npos;
|
m_withIcon = m_format.find("{icon}") != std::string::npos;
|
||||||
|
|
||||||
if (m_withIcon && m_iconsMap.empty()) {
|
if (m_withIcon && m_iconsMap.empty()) {
|
||||||
Json::Value formatIcons = config["format-icons"];
|
populateIconsMap(config["format-icons"]);
|
||||||
for (std::string &name : formatIcons.getMemberNames()) {
|
|
||||||
m_iconsMap.emplace(name, formatIcons[name].asString());
|
|
||||||
}
|
|
||||||
m_iconsMap.emplace("", "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto configAllOutputs = config_["all-outputs"];
|
populateBoolConfig(config, "all-outputs", m_allOutputs);
|
||||||
if (configAllOutputs.isBool()) {
|
populateBoolConfig(config, "show-special", m_showSpecial);
|
||||||
m_allOutputs = configAllOutputs.asBool();
|
populateBoolConfig(config, "active-only", m_activeOnly);
|
||||||
}
|
populateBoolConfig(config, "move-to-monitor", m_moveToMonitor);
|
||||||
|
|
||||||
auto configShowSpecial = config_["show-special"];
|
populateSortByConfig(config);
|
||||||
if (configShowSpecial.isBool()) {
|
|
||||||
m_showSpecial = configShowSpecial.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configActiveOnly = config_["active-only"];
|
populateIgnoreWorkspacesConfig(config);
|
||||||
if (configActiveOnly.isBool()) {
|
|
||||||
m_activeOnly = configActiveOnly.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configMoveToMonitor = config_["move-to-monitor"];
|
populatePersistentWorkspacesConfig(config);
|
||||||
if (configMoveToMonitor.isBool()) {
|
|
||||||
m_moveToMonitor = configMoveToMonitor.asBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto configSortBy = config_["sort-by"];
|
populateFormatWindowSeparatorConfig(config);
|
||||||
|
|
||||||
|
populateWindowRewriteConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Workspaces::populateIconsMap(const Json::Value &formatIcons) -> void {
|
||||||
|
for (const auto &name : formatIcons.getMemberNames()) {
|
||||||
|
m_iconsMap.emplace(name, formatIcons[name].asString());
|
||||||
|
}
|
||||||
|
m_iconsMap.emplace("", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member)
|
||||||
|
-> void {
|
||||||
|
auto configValue = config[key];
|
||||||
|
if (configValue.isBool()) {
|
||||||
|
member = configValue.asBool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
||||||
|
auto configSortBy = config["sort-by"];
|
||||||
if (configSortBy.isString()) {
|
if (configSortBy.isString()) {
|
||||||
auto sortByStr = configSortBy.asString();
|
auto sortByStr = configSortBy.asString();
|
||||||
try {
|
try {
|
||||||
m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap);
|
m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap);
|
||||||
} catch (const std::invalid_argument &e) {
|
} catch (const std::invalid_argument &e) {
|
||||||
// Handle the case where the string is not a valid enum representation.
|
|
||||||
m_sortBy = SortMethod::DEFAULT;
|
m_sortBy = SortMethod::DEFAULT;
|
||||||
g_warning("Invalid string representation for sort-by. Falling back to default sort method.");
|
spdlog::warn(
|
||||||
|
"Invalid string representation for sort-by. Falling back to default sort method.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value ignoreWorkspaces = config["ignore-workspaces"];
|
auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> void {
|
||||||
|
auto ignoreWorkspaces = config["ignore-workspaces"];
|
||||||
if (ignoreWorkspaces.isArray()) {
|
if (ignoreWorkspaces.isArray()) {
|
||||||
for (Json::Value &workspaceRegex : ignoreWorkspaces) {
|
for (const auto &workspaceRegex : ignoreWorkspaces) {
|
||||||
if (workspaceRegex.isString()) {
|
if (workspaceRegex.isString()) {
|
||||||
std::string ruleString = workspaceRegex.asString();
|
std::string ruleString = workspaceRegex.asString();
|
||||||
try {
|
try {
|
||||||
|
@ -116,29 +125,31 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_["persistent_workspaces"].isObject()) {
|
auto Workspaces::populatePersistentWorkspacesConfig(const Json::Value &config) -> void {
|
||||||
|
if (config.isMember("persistent-workspaces") || config.isMember("persistent_workspaces")) {
|
||||||
spdlog::warn(
|
spdlog::warn(
|
||||||
"persistent_workspaces is deprecated. Please change config to use persistent-workspaces.");
|
"persistent_workspaces is deprecated. Please change config to use persistent-workspaces.");
|
||||||
|
m_persistentWorkspaceConfig =
|
||||||
|
config.get("persistent-workspaces", config.get("persistent_workspaces", Json::Value()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config_["persistent-workspaces"].isObject() || config_["persistent_workspaces"].isObject()) {
|
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void {
|
||||||
m_persistentWorkspaceConfig = config_["persistent-workspaces"].isObject()
|
auto formatWindowSeparator = config["format-window-separator"];
|
||||||
? config_["persistent-workspaces"]
|
|
||||||
: config_["persistent_workspaces"];
|
|
||||||
}
|
|
||||||
|
|
||||||
const Json::Value &formatWindowSeparator = config["format-window-separator"];
|
|
||||||
m_formatWindowSeparator =
|
m_formatWindowSeparator =
|
||||||
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
||||||
|
}
|
||||||
|
|
||||||
const Json::Value &windowRewrite = config["window-rewrite"];
|
auto Workspaces::populateWindowRewriteConfig(const Json::Value &config) -> void {
|
||||||
|
const auto &windowRewrite = config["window-rewrite"];
|
||||||
if (!windowRewrite.isObject()) {
|
if (!windowRewrite.isObject()) {
|
||||||
spdlog::debug("window-rewrite is not defined or is not an object, using default rules.");
|
spdlog::debug("window-rewrite is not defined or is not an object, using default rules.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Json::Value &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
const auto &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||||
std::string windowRewriteDefault =
|
std::string windowRewriteDefault =
|
||||||
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue