Skip to content

Commit

Permalink
dispatchers: Allow relative numbers for scaleactive
Browse files Browse the repository at this point in the history
  • Loading branch information
dawsers committed Feb 21, 2025
1 parent c85b6f9 commit 6ba4e54
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,20 +2156,28 @@ SDispatchResult CKeybindManager::scaleActive(std::string args) {
return {.success = false, .error = "Window not found"};

std::optional<float> scaleResult;
bool exact = false;

try {
scaleResult = stof(args);
} catch (...) {
if (args.starts_with("exact")) {
exact = true;
scaleResult = getPlusMinusKeywordResult(args.substr(5), 0);
} else
scaleResult = getPlusMinusKeywordResult(args, 0);

if (!scaleResult.has_value()) {
Debug::log(ERR, "Invalid arg \"{}\" in scaleactive!", args);
return {.success = false, .error = "Invalid scale in scaleactive!"};
return {.success = false, .error = "Invalid scale argument in scaleactive!"};
}

float scale = scaleResult.value();
if (scale > 0.0f) {
if (!exact)
scale += 1.0 / PLASTWINDOW->m_sWindowData.contentScale.valueOr(1.0f);

if (scale > 0.0f)
PLASTWINDOW->m_sWindowData.contentScale = CWindowOverridableVar(1.0f / scale, PRIORITY_SET_PROP);
} else {
else
PLASTWINDOW->m_sWindowData.contentScale.unset(PRIORITY_SET_PROP);
}

PLASTWINDOW->sendWindowSize();

return {};
Expand Down

0 comments on commit 6ba4e54

Please sign in to comment.