Merge pull request #4024 from khaneliman/hyprland-crash

This commit is contained in:
Alexis Rouillard
2025-04-04 08:34:13 +02:00
committed by GitHub

View File

@ -79,14 +79,14 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data,
const auto keys = workspace_data.getMemberNames(); const auto keys = workspace_data.getMemberNames();
const auto *k = "persistent-rule"; const auto *k = "persistent-rule";
if (std::find(keys.begin(), keys.end(), k) != keys.end()) { if (std::ranges::find(keys, k) != keys.end()) {
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName, spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName,
workspace_data[k].asBool() ? "true" : "false"); workspace_data[k].asBool() ? "true" : "false");
(*workspace)->setPersistentRule(workspace_data[k].asBool()); (*workspace)->setPersistentRule(workspace_data[k].asBool());
} }
k = "persistent-config"; k = "persistent-config";
if (std::find(keys.begin(), keys.end(), k) != keys.end()) { if (std::ranges::find(keys, k) != keys.end()) {
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName, spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName,
workspace_data[k].asBool() ? "true" : "false"); workspace_data[k].asBool() ? "true" : "false");
(*workspace)->setPersistentConfig(workspace_data[k].asBool()); (*workspace)->setPersistentConfig(workspace_data[k].asBool());
@ -231,7 +231,7 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs
std::vector<std::string> persistentWorkspacesToCreate; std::vector<std::string> persistentWorkspacesToCreate;
const std::string currentMonitor = m_bar.output->name; const std::string currentMonitor = m_bar.output->name;
const bool monitorInConfig = std::find(keys.begin(), keys.end(), currentMonitor) != keys.end(); const bool monitorInConfig = std::ranges::find(keys, currentMonitor) != keys.end();
for (const std::string &key : keys) { for (const std::string &key : keys) {
// only add if either: // only add if either:
// 1. key is the current monitor name // 1. key is the current monitor name
@ -573,12 +573,11 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
Json::Value clientsData = m_ipc.getSocket1JsonReply("clients"); Json::Value clientsData = m_ipc.getSocket1JsonReply("clients");
std::string jsonWindowAddress = fmt::format("0x{}", payload); std::string jsonWindowAddress = fmt::format("0x{}", payload);
auto client = auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto &client) {
std::find_if(clientsData.begin(), clientsData.end(), [jsonWindowAddress](auto &client) {
return client["address"].asString() == jsonWindowAddress; return client["address"].asString() == jsonWindowAddress;
}); });
if (!client->empty()) { if (client != clientsData.end() && !client->empty()) {
(*inserter)({*client}); (*inserter)({*client});
} }
} }
@ -760,9 +759,9 @@ void Workspaces::setCurrentMonitorId() {
// get monitor ID from name (used by persistent workspaces) // get monitor ID from name (used by persistent workspaces)
m_monitorId = 0; m_monitorId = 0;
auto monitors = m_ipc.getSocket1JsonReply("monitors"); auto monitors = m_ipc.getSocket1JsonReply("monitors");
auto currentMonitor = std::find_if( auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value &m) {
monitors.begin(), monitors.end(), return m["name"].asString() == m_bar.output->name;
[this](const Json::Value &m) { return m["name"].asString() == m_bar.output->name; }); });
if (currentMonitor == monitors.end()) { if (currentMonitor == monitors.end()) {
spdlog::error("Monitor '{}' does not have an ID? Using 0", m_bar.output->name); spdlog::error("Monitor '{}' does not have an ID? Using 0", m_bar.output->name);
} else { } else {
@ -846,9 +845,9 @@ void Workspaces::setUrgentWorkspace(std::string const &windowaddress) {
} }
} }
auto workspace = auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace> &x) {
std::find_if(m_workspaces.begin(), m_workspaces.end(), return x->id() == workspaceId;
[workspaceId](std::unique_ptr<Workspace> &x) { return x->id() == workspaceId; }); });
if (workspace != m_workspaces.end()) { if (workspace != m_workspaces.end()) {
workspace->get()->setUrgent(); workspace->get()->setUrgent();
} }
@ -862,8 +861,7 @@ auto Workspaces::update() -> void {
void Workspaces::updateWindowCount() { void Workspaces::updateWindowCount() {
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces"); const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
for (auto &workspace : m_workspaces) { for (auto &workspace : m_workspaces) {
auto workspaceJson = auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
std::find_if(workspacesJson.begin(), workspacesJson.end(), [&](Json::Value const &x) {
return x["name"].asString() == workspace->name() || return x["name"].asString() == workspace->name() ||
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name()); (workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
}); });
@ -921,8 +919,7 @@ void Workspaces::updateWorkspaceStates() {
if (m_withIcon) { if (m_withIcon) {
workspaceIcon = workspace->selectIcon(m_iconsMap); workspaceIcon = workspace->selectIcon(m_iconsMap);
} }
auto updatedWorkspace = std::find_if( auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) {
updatedWorkspaces.begin(), updatedWorkspaces.end(), [&workspace](const auto &w) {
auto wNameRaw = w["name"].asString(); auto wNameRaw = w["name"].asString();
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
return wName == workspace->name(); return wName == workspace->name();