Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add % to resizeparams #3246

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2281,33 +2281,48 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con
if (!args.contains(' '))
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 y = args.substr(args.find_first_of(' ') + 1);

if (x == "exact") {
std::string newX = y.substr(0, y.find_first_of(' '));
std::string newY = y.substr(y.find_first_of(' ') + 1);

if (!isNumber(newX) || !isNumber(newY)) {
Debug::log(ERR, "parseWindowVectorArgsRelative: exact args not numbers");
return relativeTo;
}
x = y.substr(0, y.find_first_of(' '));
y = y.substr(y.find_first_of(' ') + 1);
isExact = true;
}

const int X = std::stoi(newX);
const int Y = std::stoi(newY);
if (x.contains('%')) {
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)) {
Debug::log(ERR, "parseWindowVectorArgsRelative: args not numbers");
return relativeTo;
}

const int X = std::stoi(x);
const int Y = std::stoi(y);
int X = 0;
int Y = 0;

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 + relativeTo.x, Y + relativeTo.y);
return Vector2D(X, Y);
}

void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) {
Expand Down