Skip to content

Commit 80669f7

Browse files
authored
Merge pull request Alexays#4024 from khaneliman/hyprland-crash
2 parents 569445f + 91ef6e5 commit 80669f7

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/modules/hyprland/workspaces.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data,
7979
const auto keys = workspace_data.getMemberNames();
8080

8181
const auto *k = "persistent-rule";
82-
if (std::find(keys.begin(), keys.end(), k) != keys.end()) {
82+
if (std::ranges::find(keys, k) != keys.end()) {
8383
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName,
8484
workspace_data[k].asBool() ? "true" : "false");
8585
(*workspace)->setPersistentRule(workspace_data[k].asBool());
8686
}
8787

8888
k = "persistent-config";
89-
if (std::find(keys.begin(), keys.end(), k) != keys.end()) {
89+
if (std::ranges::find(keys, k) != keys.end()) {
9090
spdlog::debug("Set config persistency of workspace {} to: {}", workspaceName,
9191
workspace_data[k].asBool() ? "true" : "false");
9292
(*workspace)->setPersistentConfig(workspace_data[k].asBool());
@@ -231,7 +231,7 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs
231231
std::vector<std::string> persistentWorkspacesToCreate;
232232

233233
const std::string currentMonitor = m_bar.output->name;
234-
const bool monitorInConfig = std::find(keys.begin(), keys.end(), currentMonitor) != keys.end();
234+
const bool monitorInConfig = std::ranges::find(keys, currentMonitor) != keys.end();
235235
for (const std::string &key : keys) {
236236
// only add if either:
237237
// 1. key is the current monitor name
@@ -573,12 +573,11 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
573573
Json::Value clientsData = m_ipc.getSocket1JsonReply("clients");
574574
std::string jsonWindowAddress = fmt::format("0x{}", payload);
575575

576-
auto client =
577-
std::find_if(clientsData.begin(), clientsData.end(), [jsonWindowAddress](auto &client) {
578-
return client["address"].asString() == jsonWindowAddress;
579-
});
576+
auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto &client) {
577+
return client["address"].asString() == jsonWindowAddress;
578+
});
580579

581-
if (!client->empty()) {
580+
if (client != clientsData.end() && !client->empty()) {
582581
(*inserter)({*client});
583582
}
584583
}
@@ -760,9 +759,9 @@ void Workspaces::setCurrentMonitorId() {
760759
// get monitor ID from name (used by persistent workspaces)
761760
m_monitorId = 0;
762761
auto monitors = m_ipc.getSocket1JsonReply("monitors");
763-
auto currentMonitor = std::find_if(
764-
monitors.begin(), monitors.end(),
765-
[this](const Json::Value &m) { return m["name"].asString() == m_bar.output->name; });
762+
auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value &m) {
763+
return m["name"].asString() == m_bar.output->name;
764+
});
766765
if (currentMonitor == monitors.end()) {
767766
spdlog::error("Monitor '{}' does not have an ID? Using 0", m_bar.output->name);
768767
} else {
@@ -846,9 +845,9 @@ void Workspaces::setUrgentWorkspace(std::string const &windowaddress) {
846845
}
847846
}
848847

849-
auto workspace =
850-
std::find_if(m_workspaces.begin(), m_workspaces.end(),
851-
[workspaceId](std::unique_ptr<Workspace> &x) { return x->id() == workspaceId; });
848+
auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace> &x) {
849+
return x->id() == workspaceId;
850+
});
852851
if (workspace != m_workspaces.end()) {
853852
workspace->get()->setUrgent();
854853
}
@@ -862,11 +861,10 @@ auto Workspaces::update() -> void {
862861
void Workspaces::updateWindowCount() {
863862
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
864863
for (auto &workspace : m_workspaces) {
865-
auto workspaceJson =
866-
std::find_if(workspacesJson.begin(), workspacesJson.end(), [&](Json::Value const &x) {
867-
return x["name"].asString() == workspace->name() ||
868-
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
869-
});
864+
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
865+
return x["name"].asString() == workspace->name() ||
866+
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
867+
});
870868
uint32_t count = 0;
871869
if (workspaceJson != workspacesJson.end()) {
872870
try {
@@ -921,12 +919,11 @@ void Workspaces::updateWorkspaceStates() {
921919
if (m_withIcon) {
922920
workspaceIcon = workspace->selectIcon(m_iconsMap);
923921
}
924-
auto updatedWorkspace = std::find_if(
925-
updatedWorkspaces.begin(), updatedWorkspaces.end(), [&workspace](const auto &w) {
926-
auto wNameRaw = w["name"].asString();
927-
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
928-
return wName == workspace->name();
929-
});
922+
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) {
923+
auto wNameRaw = w["name"].asString();
924+
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
925+
return wName == workspace->name();
926+
});
930927
if (updatedWorkspace != updatedWorkspaces.end()) {
931928
workspace->setOutput((*updatedWorkspace)["monitor"].asString());
932929
}

0 commit comments

Comments
 (0)