quick commit
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
#include <unordered_set>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "helpers/systemHelper.hpp"
|
||||
#include "helpers/command.hpp"
|
||||
#include "helpers/hypr.hpp"
|
||||
|
||||
HyprlandService::HyprlandService() = default;
|
||||
|
||||
@@ -23,10 +24,10 @@ HyprlandService::~HyprlandService() {
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
// free allocated workspace pointers
|
||||
for (auto &p : this->workspaces) {
|
||||
delete p.second;
|
||||
}
|
||||
|
||||
this->workspaces.clear();
|
||||
this->monitors.clear();
|
||||
}
|
||||
@@ -67,8 +68,7 @@ void HyprlandService::start() {
|
||||
addr.sun_family = AF_UNIX;
|
||||
std::strncpy(addr.sun_path, socket_path.c_str(), sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (connect(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) ==
|
||||
-1) {
|
||||
if (connect(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) == -1) {
|
||||
std::cerr << "[Hyprland] Failed to connect to " << socket_path
|
||||
<< std::endl;
|
||||
close(fd);
|
||||
@@ -145,15 +145,13 @@ std::string HyprlandService::get_socket_path() {
|
||||
}
|
||||
|
||||
void HyprlandService::refresh_monitors() {
|
||||
// free any previously allocated WorkspaceState objects before rebuilding
|
||||
for (auto &p : this->workspaces) {
|
||||
delete p.second;
|
||||
}
|
||||
this->workspaces.clear();
|
||||
this->monitors.clear();
|
||||
|
||||
std::string output = SystemHelper::get_command_output(kMonitorCommand);
|
||||
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto monitorsJson = HyprctlHelper::getMonitorData();
|
||||
|
||||
for (const auto &monitorJson : monitorsJson) {
|
||||
Monitor monitor;
|
||||
@@ -188,35 +186,27 @@ void HyprlandService::refresh_monitors() {
|
||||
monitorStateChanged.emit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every time when workspace changes have been detected.
|
||||
* Used to Update the internal state for the Workspaces,
|
||||
*/
|
||||
void HyprlandService::refresh_workspaces() {
|
||||
std::string output = SystemHelper::get_command_output(kWorkspaceCommand);
|
||||
auto workspacesJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto workspacesJson = HyprctlHelper::getWorkspaceData();
|
||||
|
||||
for (auto &[id, ws] : this->workspaces) {
|
||||
ws->focused = false;
|
||||
ws->active = false;
|
||||
}
|
||||
|
||||
output = SystemHelper::get_command_output(kMonitorCommand);
|
||||
auto monitorsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto monitorsJson = HyprctlHelper::getMonitorData();
|
||||
|
||||
for (const auto &monitorJson : monitorsJson) {
|
||||
const int monitorId = monitorJson.value("id", -1);
|
||||
const int focusedWorkspaceId = monitorJson["activeWorkspace"].value("id", -1);
|
||||
|
||||
// write into the stored monitor (use reference)
|
||||
auto it = this->monitors.find(monitorId);
|
||||
if (it != this->monitors.end()) {
|
||||
it->second.focusedWorkspaceId = focusedWorkspaceId;
|
||||
}
|
||||
}
|
||||
|
||||
std::string clientsOutput = SystemHelper::get_command_output(kClientsCommand);
|
||||
auto clientsJson = nlohmann::json::parse(clientsOutput, nullptr, false);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
std::unordered_set<std::string> liveClientAddresses;
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
@@ -234,21 +224,23 @@ void HyprlandService::refresh_workspaces() {
|
||||
for (const auto &workspaceJson : workspacesJson) {
|
||||
const int workspaceId = workspaceJson.value("id", -1);
|
||||
auto workspaceStateIt = this->workspaces.find(workspaceId);
|
||||
|
||||
if (workspaceStateIt == this->workspaces.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
WorkspaceState *workspaceState = workspaceStateIt->second;
|
||||
auto mit = this->monitors.find(workspaceState->monitorId);
|
||||
|
||||
if (mit != this->monitors.end()) {
|
||||
workspaceState->focused = mit->second.focusedWorkspaceId == workspaceId;
|
||||
} else {
|
||||
workspaceState->focused = false;
|
||||
}
|
||||
|
||||
workspaceState->active = true;
|
||||
}
|
||||
|
||||
// drop urgent flags for windows no longer reported by hyprctl clients
|
||||
for (auto &[id, ws] : this->workspaces) {
|
||||
auto &urgent = ws->urgentWindows;
|
||||
auto newEnd = std::remove_if(urgent.begin(), urgent.end(), [&](const std::string &addr) {
|
||||
@@ -267,7 +259,7 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||
"hyprctl dispatch workspace " + std::to_string(workspaceId);
|
||||
|
||||
try {
|
||||
(void)SystemHelper::get_command_output(cmd.c_str());
|
||||
(void)CommandHelper::execNoOutput(cmd.c_str());
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "[Hyprland] Failed to dispatch workspace command: "
|
||||
<< ex.what() << " cmd=" << cmd << std::endl;
|
||||
@@ -275,8 +267,7 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
|
||||
}
|
||||
|
||||
void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
@@ -301,8 +292,7 @@ void HyprlandService::onUrgentEvent(std::string windowAddress) {
|
||||
}
|
||||
|
||||
void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
|
||||
std::string output = SystemHelper::get_command_output(kClientsCommand);
|
||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
auto clientsJson = HyprctlHelper::getClientData();
|
||||
|
||||
for (const auto &clientJson : clientsJson) {
|
||||
const std::string addr = clientJson.value("address", "");
|
||||
|
||||
Reference in New Issue
Block a user