better working tray

This commit is contained in:
2026-01-02 16:50:02 +01:00
parent 2d5b492da8
commit ab7b3b3092
5 changed files with 559 additions and 228 deletions

View File

@@ -1,5 +1,6 @@
#include "services/hyprland.hpp"
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
@@ -9,6 +10,7 @@
#include <string>
#include <sys/socket.h>
#include <sys/un.h>
#include <unordered_set>
#include <unistd.h>
#include "helpers/systemHelper.hpp"
@@ -213,6 +215,22 @@ void HyprlandService::refresh_workspaces() {
}
}
std::string clientsOutput = SystemHelper::get_command_output(kClientsCommand);
auto clientsJson = nlohmann::json::parse(clientsOutput, nullptr, false);
std::unordered_set<std::string> liveClientAddresses;
for (const auto &clientJson : clientsJson) {
const std::string addr = clientJson.value("address", "");
if (addr.empty()) {
continue;
}
if (addr.rfind("0x", 0) == 0) {
liveClientAddresses.insert(addr.substr(2));
} else {
liveClientAddresses.insert(addr);
}
}
for (const auto &workspaceJson : workspacesJson) {
const int workspaceId = workspaceJson.value("id", -1);
auto workspaceStateIt = this->workspaces.find(workspaceId);
@@ -230,6 +248,17 @@ void HyprlandService::refresh_workspaces() {
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) {
return liveClientAddresses.find(addr) == liveClientAddresses.end();
});
if (newEnd != urgent.end()) {
urgent.erase(newEnd, urgent.end());
}
}
workspaceStateChanged.emit();
}