Skip to content

Commit

Permalink
modernizing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Jul 16, 2023
1 parent 8ac1395 commit e5c8061
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/canvas/wayland/config/hyprland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include "hyprland.hpp"
#include "os.hpp"
#include "util.hpp"
#include "application.hpp"
#include "tmux.hpp"

#include <algorithm>
Expand All @@ -27,8 +25,6 @@
#include <nlohmann/json.hpp>

using njson = nlohmann::json;
using std::begin;
using std::end;

HyprlandSocket::HyprlandSocket()
{
Expand Down Expand Up @@ -62,10 +58,10 @@ auto HyprlandSocket::get_active_window() -> nlohmann::json
address = active.at("address");
}
const auto clients = request_result("j/clients");
const auto client = std::find_if(begin(clients), end(clients), [this] (const njson& json) {
const auto client = std::ranges::find_if(clients, [this] (const njson& json) {
return json.at("address") == address;
});
if (client == end(clients)) {
if (client == clients.end()) {
throw std::runtime_error("Active window not found");
}
return *client;
Expand All @@ -75,7 +71,7 @@ auto HyprlandSocket::get_active_monitor() -> nlohmann::json
{
const auto monitors = request_result("j/monitors");
multimonitor = monitors.size() > 1;
const auto focused_monitor = std::find_if(begin(monitors), end(monitors), [] (const njson& json) {
const auto focused_monitor = std::ranges::find_if(monitors, [] (const njson& json) {
return json.at("focused") == true;
});
return focused_monitor.value();
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/wayland/config/sway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ auto SwaySocket::get_active_window(const std::vector<nlohmann::json>& nodes) ->

for (const auto pid: pids) {
const auto tree = util::get_process_tree(pid);
const auto found = std::find_if(nodes.begin(), nodes.end(), [&tree] (const njson& json) -> bool {
const auto found = std::ranges::find_if(nodes, [&tree] (const njson& json) -> bool {
try {
return std::find(tree.begin(), tree.end(), json.at("pid")) != tree.end();
return std::ranges::find(tree, json.at("pid").get<int>()) != tree.end();
} catch (const njson::out_of_range& err) {
return false;
}
Expand Down

0 comments on commit e5c8061

Please sign in to comment.