Skip to content

Commit

Permalink
config: improve layoutopt handling for workspacerules
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Dec 11, 2023
1 parent e53134c commit ea7569d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
16 changes: 14 additions & 2 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,20 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std:
wsRule.isPersistent = configStringToInt(rule.substr(delim + 11));
else if ((delim = rule.find(ruleOnCreatedEmtpy)) != std::string::npos)
wsRule.onCreatedEmptyRunCmd = cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmtpyLen));
else if ((delim = rule.find("layoutopt:orientation:")) != std::string::npos)
wsRule.layoutopts["orientation"] = rule.substr(delim + 22);
else if ((delim = rule.find("layoutopt:")) != std::string::npos) {
std::string opt = rule.substr(delim + 10);
if (!opt.contains(":")) {
// invalid
Debug::log(ERR, "Invalid workspace rule found: {}", rule);
parseError = "Invalid workspace rule found: " + rule;
return;
}

std::string val = opt.substr(opt.find(":") + 1);
opt = opt.substr(0, opt.find(":"));

wsRule.layoutopts[opt] = val;
}
};

size_t pos = 0;
Expand Down
30 changes: 15 additions & 15 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ struct SConfigValue {
};

struct SWorkspaceRule {
std::string monitor = "";
std::string workspaceString = "";
std::string workspaceName = "";
int workspaceId = -1;
bool isDefault = false;
bool isPersistent = false;
std::optional<int64_t> gapsIn;
std::optional<int64_t> gapsOut;
std::optional<int64_t> borderSize;
std::optional<int> border;
std::optional<int> rounding;
std::optional<int> decorate;
std::optional<int> shadow;
std::optional<std::string> onCreatedEmptyRunCmd;
std::map<std::string, std::any> layoutopts;
std::string monitor = "";
std::string workspaceString = "";
std::string workspaceName = "";
int workspaceId = -1;
bool isDefault = false;
bool isPersistent = false;
std::optional<int64_t> gapsIn;
std::optional<int64_t> gapsOut;
std::optional<int64_t> borderSize;
std::optional<int> border;
std::optional<int> rounding;
std::optional<int> decorate;
std::optional<int> shadow;
std::optional<std::string> onCreatedEmptyRunCmd;
std::map<std::string, std::string> layoutopts;
};

struct SMonitorAdditionalReservedArea {
Expand Down
13 changes: 6 additions & 7 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,21 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) {
const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts;
auto orientationForWs = *orientation;

try {
if (layoutoptsForWs.contains("orientation"))
orientationForWs = std::any_cast<std::string>(layoutoptsForWs.at("orientation"));
} catch (std::exception& e) { Debug::log(ERR, "Error from layoutopt rules: {}", e.what()); }
if (layoutoptsForWs.contains("orientation"))
orientationForWs = layoutoptsForWs.at("orientation");

if (orientationForWs == "top") {
PWORKSPACEDATA->orientation = ORIENTATION_TOP;
} else if (orientationForWs == "right") {
PWORKSPACEDATA->orientation = ORIENTATION_RIGHT;
} else if (orientationForWs == "bottom") {
PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM;
} else if (orientationForWs == "left") {
PWORKSPACEDATA->orientation = ORIENTATION_LEFT;
} else {
} else if (orientationForWs == "center") {
PWORKSPACEDATA->orientation = ORIENTATION_CENTER;
} else {
PWORKSPACEDATA->orientation = ORIENTATION_LEFT;
}

return PWORKSPACEDATA;
}

Expand Down

0 comments on commit ea7569d

Please sign in to comment.