Skip to content

Commit 38c1e72

Browse files
authored
rules: fix some monitor rules (#11873)
1 parent 0959672 commit 38c1e72

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

hyprtester/src/tests/main/window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ static bool test() {
237237
EXPECT_CONTAINS(str, "floating: 1");
238238
EXPECT_CONTAINS(str, std::format("size: {},{}", SIZE, SIZE));
239239
EXPECT_NOT_CONTAINS(str, "pinned: 1");
240-
241240
OK(getFromSocket("/keyword windowrule plugin:someplugin:variable, class:wr_kitty"));
242241
OK(getFromSocket("/keyword windowrule plugin:someplugin:variable 10, class:wr_kitty"));
243242
OK(getFromSocket("/keyword windowrule workspace 1, class:wr_kitty"));
@@ -246,6 +245,7 @@ static bool test() {
246245
if (!spawnKitty("magic_kitty"))
247246
return false;
248247
EXPECT_CONTAINS(getFromSocket("/activewindow"), "special:magic");
248+
EXPECT_NOT_CONTAINS(str, "workspace: 9");
249249
}
250250
NLog::log("{}Testing faulty rules", Colors::YELLOW);
251251
{

src/config/ConfigManager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,16 +2669,17 @@ std::optional<std::string> CConfigManager::handleWindowRule(const std::string& c
26692669
bool parsingParams = false;
26702670

26712671
for (const auto& varStr : VARLIST) {
2672-
std::string_view var = varStr;
2673-
auto sep = var.find(':');
2674-
std::string_view key = (sep != std::string_view::npos) ? var.substr(0, sep) : var;
2672+
std::string_view var = varStr;
2673+
auto sep = var.find(':');
2674+
std::string_view key = (sep != std::string_view::npos) ? var.substr(0, sep) : var;
2675+
bool isParam = (sep != std::string_view::npos && !(key.starts_with("workspace ") || (key.starts_with("monitor ")) || key.ends_with("plugin")));
26752676

26762677
if (!parsingParams) {
2677-
// Don't be alarmed, ends_with is a single memcmp, i went and checked.
2678-
if (sep == std::string_view::npos || key.ends_with("plugin") || key.ends_with("special")) {
2678+
if (!isParam) {
26792679
tokens.emplace_back(var);
26802680
continue;
26812681
}
2682+
26822683
parsingParams = true;
26832684
}
26842685

@@ -2964,7 +2965,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
29642965
CHECK_OR_THROW(configStringToInt(rule.substr(delim + 11)))
29652966
wsRule.isPersistent = *X;
29662967
} else if ((delim = rule.find("defaultName:")) != std::string::npos)
2967-
wsRule.defaultName = rule.substr(delim + 12);
2968+
wsRule.defaultName = trim(rule.substr(delim + 12));
29682969
else if ((delim = rule.find(ruleOnCreatedEmpty)) != std::string::npos) {
29692970
CHECK_OR_THROW(cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmptyLen)))
29702971
wsRule.onCreatedEmptyRunCmd = *X;

src/events/Windows.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../protocols/ToplevelExport.hpp"
1616
#include "../protocols/types/ContentType.hpp"
1717
#include "../xwayland/XSurface.hpp"
18+
#include "desktop/DesktopTypes.hpp"
1819
#include "managers/animation/AnimationManager.hpp"
1920
#include "managers/animation/DesktopAnimationManager.hpp"
2021
#include "managers/PointerManager.hpp"
@@ -147,23 +148,16 @@ void Events::listener_mapWindow(void* owner, void* data) {
147148
try {
148149
const auto MONITORSTR = trim(r->m_rule.substr(r->m_rule.find(' ')));
149150

150-
if (MONITORSTR == "unset") {
151+
if (MONITORSTR == "unset")
151152
PWINDOW->m_monitor = PMONITOR;
152-
} else {
153-
if (isNumber(MONITORSTR)) {
154-
const MONITORID MONITOR = std::stoi(MONITORSTR);
155-
if (const auto PM = g_pCompositor->getMonitorFromID(MONITOR); PM)
156-
PWINDOW->m_monitor = PM;
157-
else
158-
PWINDOW->m_monitor = g_pCompositor->m_monitors.at(0);
159-
} else {
160-
const auto PMONITOR = g_pCompositor->getMonitorFromName(MONITORSTR);
161-
if (PMONITOR)
162-
PWINDOW->m_monitor = PMONITOR;
163-
else {
164-
Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR);
165-
continue;
166-
}
153+
else {
154+
const auto MONITOR = g_pCompositor->getMonitorFromString(MONITORSTR);
155+
156+
if (MONITOR)
157+
PWINDOW->m_monitor = MONITOR;
158+
else {
159+
Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR);
160+
continue;
167161
}
168162
}
169163

0 commit comments

Comments
 (0)