2025-06-11 11:48:31 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include "../include/WindowRule.h"
|
|
|
|
|
|
|
|
|
|
std::string WindowRule::toString() {
|
2026-01-05 12:45:08 +01:00
|
|
|
std::string mode = this->tile ? "tile on" : "float on";
|
|
|
|
|
return "windowrule = " + mode + ", match:workspace " + std::to_string(this->workspaceID);
|
|
|
|
|
}
|
2025-06-11 11:48:31 +02:00
|
|
|
|
|
|
|
|
WindowRule WindowRule::parse(std::string ruleStr) {
|
|
|
|
|
WindowRule rule;
|
2026-01-05 12:45:08 +01:00
|
|
|
|
2025-06-11 11:48:31 +02:00
|
|
|
// Remove spaces for easier parsing
|
|
|
|
|
ruleStr.erase(std::remove(ruleStr.begin(), ruleStr.end(), ' '), ruleStr.end());
|
|
|
|
|
|
|
|
|
|
// Find mode
|
|
|
|
|
auto modePos = ruleStr.find("windowrule=");
|
|
|
|
|
if (modePos != std::string::npos) {
|
|
|
|
|
auto commaPos = ruleStr.find(',', modePos);
|
|
|
|
|
std::string mode = ruleStr.substr(modePos + 11, commaPos - (modePos + 11));
|
2026-01-05 12:45:08 +01:00
|
|
|
rule.tile = (mode == "tileon");
|
2025-06-11 11:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find workspace
|
2026-01-05 12:45:08 +01:00
|
|
|
auto wsPos = ruleStr.find("match:workspace");
|
2025-06-11 11:48:31 +02:00
|
|
|
if (wsPos != std::string::npos) {
|
2026-01-05 12:45:08 +01:00
|
|
|
std::string wsStr = ruleStr.substr(wsPos + 15);
|
2025-06-11 11:48:31 +02:00
|
|
|
rule.workspaceID = std::stoi(wsStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rule;
|
2026-01-05 12:45:08 +01:00
|
|
|
}
|