windowrules: add % to resizeparams (#3246)

Co-authored-by: Leeman <lstrout@enlj.com>
This commit is contained in:
alaricljs 2023-09-10 18:26:14 -04:00 committed by GitHub
parent 79862c957c
commit 81661b49aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2281,22 +2281,29 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con
if (!args.contains(' ')) if (!args.contains(' '))
return relativeTo; return relativeTo;
const auto PMONITOR = m_pLastMonitor;
bool xIsPercent = false;
bool yIsPercent = false;
bool isExact = false;
std::string x = args.substr(0, args.find_first_of(' ')); std::string x = args.substr(0, args.find_first_of(' '));
std::string y = args.substr(args.find_first_of(' ') + 1); std::string y = args.substr(args.find_first_of(' ') + 1);
if (x == "exact") { if (x == "exact") {
std::string newX = y.substr(0, y.find_first_of(' ')); x = y.substr(0, y.find_first_of(' '));
std::string newY = y.substr(y.find_first_of(' ') + 1); y = y.substr(y.find_first_of(' ') + 1);
isExact = true;
if (!isNumber(newX) || !isNumber(newY)) {
Debug::log(ERR, "parseWindowVectorArgsRelative: exact args not numbers");
return relativeTo;
} }
const int X = std::stoi(newX); if (x.contains('%')) {
const int Y = std::stoi(newY); xIsPercent = true;
x = x.substr(0, x.length() - 1);
}
return Vector2D(X, Y); if (y.contains('%')) {
yIsPercent = true;
y = y.substr(0, y.length() - 1);
} }
if (!isNumber(x) || !isNumber(y)) { if (!isNumber(x) || !isNumber(y)) {
@ -2304,10 +2311,18 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con
return relativeTo; return relativeTo;
} }
const int X = std::stoi(x); int X = 0;
const int Y = std::stoi(y); int Y = 0;
return Vector2D(X + relativeTo.x, Y + relativeTo.y); if (isExact) {
X = xIsPercent ? std::stof(x) * 0.01 * PMONITOR->vecSize.x : std::stoi(x);
Y = yIsPercent ? std::stof(y) * 0.01 * PMONITOR->vecSize.y : std::stoi(y);
} else {
X = xIsPercent ? std::stof(x) * 0.01 * relativeTo.x + relativeTo.x : std::stoi(x) + relativeTo.x;
Y = yIsPercent ? std::stof(y) * 0.01 * relativeTo.y + relativeTo.y : std::stoi(y) + relativeTo.y;
}
return Vector2D(X, Y);
} }
void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) { void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) {