2025-06-10 14:16:44 +02:00
|
|
|
#include "../include/HyprlandService.h"
|
2025-06-10 14:09:56 +02:00
|
|
|
|
|
|
|
|
using json = nlohmann::json;
|
|
|
|
|
|
|
|
|
|
std::string HyprlandService::exec(const std::string& command) {
|
|
|
|
|
char buffer[128];
|
|
|
|
|
std::string result = "";
|
|
|
|
|
|
|
|
|
|
FILE* pipe = popen(command.c_str(), "r");
|
|
|
|
|
if (!pipe) {
|
|
|
|
|
return "popen failed";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
|
|
|
|
result += buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int status = pclose(pipe);
|
|
|
|
|
if (status == -1) {
|
|
|
|
|
return "Error closing pipe";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Workspace HyprlandService::getCurrentWorkspace() {
|
2025-06-10 15:45:03 +02:00
|
|
|
json j = json::parse(exec(HYPRCTL_BINARY " activeworkspace -j"));
|
2025-06-10 14:09:56 +02:00
|
|
|
return j.get<Workspace>();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::list<Client> HyprlandService::getClients() {
|
2025-06-10 15:45:03 +02:00
|
|
|
json j = json::parse(exec(HYPRCTL_BINARY " clients -j"));
|
2025-06-10 14:09:56 +02:00
|
|
|
return j.get<std::list<Client>>();
|
|
|
|
|
};
|
2025-06-10 14:55:42 +02:00
|
|
|
|
|
|
|
|
std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
|
|
|
|
|
std::list<Client> clients = HyprlandService::getClients();
|
|
|
|
|
int activeWorkspaceID = HyprlandService::getCurrentWorkspace().id;
|
|
|
|
|
|
|
|
|
|
for (auto it = clients.begin(); it != clients.end(); ) {
|
|
|
|
|
if (it->workspace.id != activeWorkspaceID) {
|
|
|
|
|
it = clients.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return clients;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void HyprlandService::setClientFloating(Client& c) {
|
2025-06-10 15:45:03 +02:00
|
|
|
exec(HYPRCTL_BINARY " dispatch setfloating address:" + c.address);
|
2025-06-10 14:55:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void HyprlandService::setClientTiled(Client& c) {
|
2025-06-10 15:45:03 +02:00
|
|
|
exec(HYPRCTL_BINARY " dispatch settiled address:" + c.address);
|
2025-06-10 14:55:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HyprlandService::toggleClientFloating(Client& c) {
|
2025-06-10 15:45:25 +02:00
|
|
|
exec(HYPRCTL_BINARY " dispatch togglefloating address:" + c.address);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void HyprlandService::setFloatingRule(bool b) {
|
|
|
|
|
if (b) {
|
2025-06-10 16:45:58 +02:00
|
|
|
FileServices::createOrOverwriteFile(FLOATING_RULE_CONF_FILE, FLOATING_RULE);
|
2025-06-10 15:45:25 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2025-06-10 16:45:58 +02:00
|
|
|
FileServices::emptyFile(FLOATING_RULE_CONF_FILE);
|
2025-06-10 15:45:25 +02:00
|
|
|
}
|
2025-06-10 16:45:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool HyprlandService::isFloatingRulePresent() {
|
|
|
|
|
return FileServices::doesNonEmptyFileExist(FLOATING_RULE_CONF_FILE);
|
2025-06-10 14:55:42 +02:00
|
|
|
};
|