rules: fix some monitor rules (#11873)

This commit is contained in:
ItsOhen 2025-09-29 20:10:34 +02:00 committed by GitHub
parent 0959672591
commit 38c1e72c9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 23 deletions

View file

@ -237,7 +237,6 @@ static bool test() {
EXPECT_CONTAINS(str, "floating: 1");
EXPECT_CONTAINS(str, std::format("size: {},{}", SIZE, SIZE));
EXPECT_NOT_CONTAINS(str, "pinned: 1");
OK(getFromSocket("/keyword windowrule plugin:someplugin:variable, class:wr_kitty"));
OK(getFromSocket("/keyword windowrule plugin:someplugin:variable 10, class:wr_kitty"));
OK(getFromSocket("/keyword windowrule workspace 1, class:wr_kitty"));
@ -246,6 +245,7 @@ static bool test() {
if (!spawnKitty("magic_kitty"))
return false;
EXPECT_CONTAINS(getFromSocket("/activewindow"), "special:magic");
EXPECT_NOT_CONTAINS(str, "workspace: 9");
}
NLog::log("{}Testing faulty rules", Colors::YELLOW);
{

View file

@ -2669,16 +2669,17 @@ std::optional<std::string> CConfigManager::handleWindowRule(const std::string& c
bool parsingParams = false;
for (const auto& varStr : VARLIST) {
std::string_view var = varStr;
auto sep = var.find(':');
std::string_view key = (sep != std::string_view::npos) ? var.substr(0, sep) : var;
std::string_view var = varStr;
auto sep = var.find(':');
std::string_view key = (sep != std::string_view::npos) ? var.substr(0, sep) : var;
bool isParam = (sep != std::string_view::npos && !(key.starts_with("workspace ") || (key.starts_with("monitor ")) || key.ends_with("plugin")));
if (!parsingParams) {
// Don't be alarmed, ends_with is a single memcmp, i went and checked.
if (sep == std::string_view::npos || key.ends_with("plugin") || key.ends_with("special")) {
if (!isParam) {
tokens.emplace_back(var);
continue;
}
parsingParams = true;
}
@ -2964,7 +2965,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
CHECK_OR_THROW(configStringToInt(rule.substr(delim + 11)))
wsRule.isPersistent = *X;
} else if ((delim = rule.find("defaultName:")) != std::string::npos)
wsRule.defaultName = rule.substr(delim + 12);
wsRule.defaultName = trim(rule.substr(delim + 12));
else if ((delim = rule.find(ruleOnCreatedEmpty)) != std::string::npos) {
CHECK_OR_THROW(cleanCmdForWorkspace(name, rule.substr(delim + ruleOnCreatedEmptyLen)))
wsRule.onCreatedEmptyRunCmd = *X;

View file

@ -15,6 +15,7 @@
#include "../protocols/ToplevelExport.hpp"
#include "../protocols/types/ContentType.hpp"
#include "../xwayland/XSurface.hpp"
#include "desktop/DesktopTypes.hpp"
#include "managers/animation/AnimationManager.hpp"
#include "managers/animation/DesktopAnimationManager.hpp"
#include "managers/PointerManager.hpp"
@ -147,23 +148,16 @@ void Events::listener_mapWindow(void* owner, void* data) {
try {
const auto MONITORSTR = trim(r->m_rule.substr(r->m_rule.find(' ')));
if (MONITORSTR == "unset") {
if (MONITORSTR == "unset")
PWINDOW->m_monitor = PMONITOR;
} else {
if (isNumber(MONITORSTR)) {
const MONITORID MONITOR = std::stoi(MONITORSTR);
if (const auto PM = g_pCompositor->getMonitorFromID(MONITOR); PM)
PWINDOW->m_monitor = PM;
else
PWINDOW->m_monitor = g_pCompositor->m_monitors.at(0);
} else {
const auto PMONITOR = g_pCompositor->getMonitorFromName(MONITORSTR);
if (PMONITOR)
PWINDOW->m_monitor = PMONITOR;
else {
Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR);
continue;
}
else {
const auto MONITOR = g_pCompositor->getMonitorFromString(MONITORSTR);
if (MONITOR)
PWINDOW->m_monitor = MONITOR;
else {
Debug::log(ERR, "No monitor in monitor {} rule", MONITORSTR);
continue;
}
}