highlight urgent workspace
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
namespace {
|
||||
const char *kMonitorCommand = "hyprctl monitors -j";
|
||||
const char *kWorkspaceCommand = "hyprctl workspaces -j";
|
||||
const char *kClientsCommand = "hyprctl clients -j";
|
||||
|
||||
bool is_workspace_event(const std::string &event) {
|
||||
return event.find("workspace") != std::string::npos;
|
||||
@@ -32,8 +33,11 @@ HyprlandService::~HyprlandService() {
|
||||
}
|
||||
}
|
||||
|
||||
void HyprlandService::on_hyprland_event(std::string event,
|
||||
std::string /*data*/) {
|
||||
void HyprlandService::on_hyprland_event(std::string event, std::string data) {
|
||||
if (event == "urgent") {
|
||||
handle_urgent_window(data);
|
||||
}
|
||||
|
||||
if (is_workspace_event(event) || event == "focusedmon" ||
|
||||
event == "monitoradded" || event == "monitorremoved") {
|
||||
refresh_monitors();
|
||||
@@ -326,4 +330,58 @@ HyprlandService::getMonitorByIndex(std::size_t index) const {
|
||||
auto it = monitors.begin();
|
||||
std::advance(it, static_cast<long>(index));
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
void HyprlandService::handle_urgent_window(std::string windowAddress) {
|
||||
std::string output;
|
||||
try {
|
||||
output = SystemHelper::get_command_output(kClientsCommand);
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "[Hyprland] Failed to query clients: " << ex.what()
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto clientsJson = nlohmann::json::parse(output, nullptr, false);
|
||||
if (!clientsJson.is_array()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int workspaceId = -1;
|
||||
|
||||
for (const auto &client : clientsJson) {
|
||||
if (!client.is_object())
|
||||
continue;
|
||||
|
||||
std::string addr = client.value("address", "");
|
||||
if (addr == "0x" + windowAddress) {
|
||||
if (client.contains("workspace") &&
|
||||
client["workspace"].is_object()) {
|
||||
workspaceId = client["workspace"].value("id", -1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceId == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &pair : monitors) {
|
||||
auto &monitor = pair.second;
|
||||
bool changed = false;
|
||||
|
||||
for (auto &wsPair : monitor.workspaceStates) {
|
||||
if (wsPair.second.hyprId == workspaceId) {
|
||||
if (!wsPair.second.urgent) {
|
||||
wsPair.second.urgent = true;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
workspaceStateChanged.emit(monitor.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user