desktop: rewrite reserved area handling + improve tests (#12383)

This commit is contained in:
Vaxry 2025-12-05 14:16:22 +00:00 committed by GitHub
parent d5c52ef58e
commit 9264436f35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 818 additions and 413 deletions

View file

@ -1095,7 +1095,6 @@ std::optional<std::string> CConfigManager::resetHLConfig() {
g_pAnimationManager->addBezierWithName("linear", Vector2D(0.0, 0.0), Vector2D(1.0, 1.0));
g_pTrackpadGestures->clearGestures();
m_mAdditionalReservedAreas.clear();
m_workspaceRules.clear();
setDefaultAnimationVars(); // reset anims
m_declaredPlugins.clear();
@ -1139,7 +1138,8 @@ std::optional<std::string> CConfigManager::handleMonitorv2(const std::string& ou
if (VAL && VAL->m_bSetByUser) {
const auto ARGS = CVarList(std::any_cast<Hyprlang::STRING>(VAL->getValue()));
try {
parser.setReserved({.top = std::stoi(ARGS[0]), .bottom = std::stoi(ARGS[1]), .left = std::stoi(ARGS[2]), .right = std::stoi(ARGS[3])});
// top, right, bottom, left
parser.setReserved({std::stoi(ARGS[0]), std::stoi(ARGS[3]), std::stoi(ARGS[1]), std::stoi(ARGS[2])});
} catch (...) { return "parse error: invalid reserved area"; }
}
VAL = m_config->getSpecialConfigValuePtr("monitorv2", "mirror", output.c_str());
@ -2193,8 +2193,8 @@ void CMonitorRuleParser::setMirror(const std::string& value) {
m_rule.mirrorOf = value;
}
bool CMonitorRuleParser::setReserved(const SMonitorAdditionalReservedArea& value) {
g_pConfigManager->m_mAdditionalReservedAreas[name()] = value;
bool CMonitorRuleParser::setReserved(const Desktop::CReservedArea& value) {
m_rule.reservedArea = value;
return true;
}
@ -2223,13 +2223,22 @@ std::optional<std::string> CConfigManager::handleMonitor(const std::string& comm
return {};
} else if (ARGS[1] == "addreserved") {
std::optional<Desktop::CReservedArea> area;
try {
parser.setReserved({.top = std::stoi(std::string(ARGS[2])),
.bottom = std::stoi(std::string(ARGS[3])),
.left = std::stoi(std::string(ARGS[4])),
.right = std::stoi(std::string(ARGS[5]))});
// top, right, bottom, left
area = {std::stoi(std::string{ARGS[2]}), std::stoi(std::string{ARGS[5]}), std::stoi(std::string{ARGS[3]}), std::stoi(std::string{ARGS[4]})};
} catch (...) { return "parse error: invalid reserved area"; }
return {};
if (!area.has_value())
return "parse error: bad addreserved";
auto rule = std::ranges::find_if(m_monitorRules, [n = ARGS[0]](const auto& other) { return other.name == n; });
if (rule != m_monitorRules.end()) {
rule->reservedArea = area.value();
return {};
}
// fall
} else {
Debug::log(ERR, "ConfigManager parseMonitor, curitem bogus???");
return "parse error: curitem bogus";

View file

@ -18,6 +18,7 @@
#include "../SharedDefs.hpp"
#include "../helpers/Color.hpp"
#include "../desktop/DesktopTypes.hpp"
#include "../desktop/reserved/ReservedArea.hpp"
#include "../helpers/memory/Memory.hpp"
#include "../managers/XWaylandManager.hpp"
#include "../managers/KeybindManager.hpp"
@ -48,13 +49,6 @@ struct SWorkspaceRule {
std::map<std::string, std::string> layoutopts;
};
struct SMonitorAdditionalReservedArea {
int top = 0;
int bottom = 0;
int left = 0;
int right = 0;
};
struct SPluginKeyword {
HANDLE handle = nullptr;
std::string name = "";
@ -185,7 +179,7 @@ class CMonitorRuleParser {
void setDisabled();
void setMirror(const std::string& value);
bool setReserved(const SMonitorAdditionalReservedArea& value);
bool setReserved(const Desktop::CReservedArea& value);
private:
SMonitorRule m_rule;
@ -196,36 +190,34 @@ class CConfigManager {
public:
CConfigManager();
void init();
void reload();
std::string verify();
void init();
void reload();
std::string verify();
int getDeviceInt(const std::string&, const std::string&, const std::string& fallback = "");
float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = "");
Vector2D getDeviceVec(const std::string&, const std::string&, const std::string& fallback = "");
std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = "");
bool deviceConfigExplicitlySet(const std::string&, const std::string&);
bool deviceConfigExists(const std::string&);
Hyprlang::CConfigValue* getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback);
int getDeviceInt(const std::string&, const std::string&, const std::string& fallback = "");
float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = "");
Vector2D getDeviceVec(const std::string&, const std::string&, const std::string& fallback = "");
std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = "");
bool deviceConfigExplicitlySet(const std::string&, const std::string&);
bool deviceConfigExists(const std::string&);
Hyprlang::CConfigValue* getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback);
void* const* getConfigValuePtr(const std::string&);
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = "");
std::string getMainConfigPath();
std::string getConfigString();
void* const* getConfigValuePtr(const std::string&);
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = "");
std::string getMainConfigPath();
std::string getConfigString();
SMonitorRule getMonitorRuleFor(const PHLMONITOR);
SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace);
std::string getDefaultWorkspaceFor(const std::string&);
SMonitorRule getMonitorRuleFor(const PHLMONITOR);
SWorkspaceRule getWorkspaceRuleFor(PHLWORKSPACE workspace);
std::string getDefaultWorkspaceFor(const std::string&);
PHLMONITOR getBoundMonitorForWS(const std::string&);
std::string getBoundMonitorStringForWS(const std::string&);
const std::vector<SWorkspaceRule>& getAllWorkspaceRules();
PHLMONITOR getBoundMonitorForWS(const std::string&);
std::string getBoundMonitorStringForWS(const std::string&);
const std::vector<SWorkspaceRule>& getAllWorkspaceRules();
void ensurePersistentWorkspacesPresent();
void ensurePersistentWorkspacesPresent();
const std::vector<SConfigOptionDescription>& getAllDescriptions();
std::unordered_map<std::string, SMonitorAdditionalReservedArea> m_mAdditionalReservedAreas;
const std::vector<SConfigOptionDescription>& getAllDescriptions();
const std::unordered_map<std::string, SP<Hyprutils::Animation::SAnimationPropertyConfig>>& getAnimationConfig();