Floating rules are now isolated between workspaces

This commit is contained in:
2025-06-11 11:48:31 +02:00
parent d9d2a74f02
commit b400cb539f
8 changed files with 176 additions and 16 deletions

View File

@@ -17,8 +17,8 @@ std::list<Client> HyprlandService::getClients() {
};
std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
std::list<Client> clients = HyprlandService::getClients();
int activeWorkspaceID = HyprlandService::getCurrentWorkspace().id;
std::list<Client> clients = getClients();
int activeWorkspaceID = getCurrentWorkspace().id;
for (auto it = clients.begin(); it != clients.end(); ) {
if (it->workspace.id != activeWorkspaceID) {
@@ -31,6 +31,16 @@ std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
return clients;
};
std::list<WindowRule> HyprlandService::getWindowRules() {
std::list<WindowRule> rules;
for (auto& line : FileService::readLines(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE)) {
rules.push_back(WindowRule::parse(line));
}
return rules;
};
void HyprlandService::setClientFloating(Client& c) {
ShellService::exec(HYPRCTL_BINARY " dispatch setfloating address:" + c.address);
};
@@ -43,15 +53,69 @@ void HyprlandService::toggleClientFloating(Client& c) {
ShellService::exec(HYPRCTL_BINARY " dispatch togglefloating address:" + c.address);
};
void HyprlandService::setFloatingRule(bool b) {
if (b) {
FileServices::createOrOverwriteFile(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE, FLOATING_RULE);
}
else {
FileServices::emptyFile(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE);
//on = true -> creates a window rule to ENABLE floating mode for currently active workspace
//on = false -> creates a window rule to DISABLE floating mode for currently active workspace
void HyprlandService::setFloatingRule(bool on) {
WindowRule rule {.tile = !on, .workspaceID = getCurrentWorkspace().id};
auto conflictingRule = findConflictingRule(rule);
if (conflictingRule.has_value()) {
removeRule(conflictingRule.value());
}
FileService::appendToFile(
ShellService::getHomePath() + FLOATING_RULE_CONF_FILE,
rule.toString()
);
};
std::optional<WindowRule> HyprlandService::findConflictingRule(WindowRule subject) {
std::list<WindowRule> rules = getWindowRules();
int id = getCurrentWorkspace().id;
for (auto& rule : rules) {
if (rule.tile == !subject.tile && rule.workspaceID == subject.workspaceID)
{
return rule;
}
}
return std::nullopt;
};
void HyprlandService::removeRule(WindowRule rule) {
std::list<WindowRule> rules = getWindowRules();
int index = 0;
int foundIndex = -1;
for (auto& it : rules) {
if (it.toString() == rule.toString())
{
foundIndex = index;
break;
}
++index;
}
if (foundIndex != -1) {
FileService::deleteNthLine(
ShellService::getHomePath() + FLOATING_RULE_CONF_FILE,
foundIndex
);
}
//else: rule not found, do nothing
}
bool HyprlandService::isFloatingRulePresent() {
return FileServices::doesNonEmptyFileExist(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE);
//Checks if there's a valid window rule in place that enables floating mode for the currently active workspace
std::list<WindowRule> rules = getWindowRules();
int id = getCurrentWorkspace().id;
for (auto& rule : rules) {
if (rule.workspaceID == id && rule.tile == false) {
return true;
}
}
return false;
};